From 869ad92e5a2e52eebd4eeee1d588da92732539bc Mon Sep 17 00:00:00 2001 From: zerothelootrat Date: Wed, 5 Jun 2024 17:37:46 -0400 Subject: [PATCH] Y wing turret and laser update --- README.md | 8 ++++++-- Scenes/turret_laser.tscn | 2 ++ Scenes/world.gd | 12 +++++++----- Scripts/enemy_ywing.gd | 16 +++++++++++----- Scripts/turret_laser.gd | 16 +++++++++++----- 5 files changed, 37 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index e230672..e829a02 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ currently only have one enemy and one level up type ##todo: - [x] Finish Y-Wing Art -- [ ] Import Y-Wing & get turret working +- [x] Import Y-Wing & get turret working + -[x] Implement Y-Wing Main Cannon - [ ] Power up 2 (shield) - [ ] locate sounds - [ ] World Map @@ -25,4 +26,7 @@ currently only have one enemy and one level up type update log: 6/4/2024 -First implementation of y-wing sprite, and turret. Scripting to be done later. \ No newline at end of file +First implementation of y-wing sprite, and turret. Scripting to be done later. + +6/5/2024 +Y-Wing implemented, and turret working (X/Y coords for the blaster bolt needs tweaking) Multiple target_pos.x * 2? diff --git a/Scenes/turret_laser.tscn b/Scenes/turret_laser.tscn index 04c1674..93106b4 100644 --- a/Scenes/turret_laser.tscn +++ b/Scenes/turret_laser.tscn @@ -19,3 +19,5 @@ texture = ExtResource("1_8xaek") [node name="CollisionShape2D" type="CollisionShape2D" parent="."] position = Vector2(0, 2) shape = SubResource("CapsuleShape2D_kjs2o") + +[connection signal="area_entered" from="." to="." method="_on_area_entered"] diff --git a/Scenes/world.gd b/Scenes/world.gd index fcb35c1..66e6658 100644 --- a/Scenes/world.gd +++ b/Scenes/world.gd @@ -7,7 +7,7 @@ var missile = preload("res://Scenes/missile.tscn") var missile_refil = preload("res://Scenes/missile_pickup.tscn") var enemy_laser = preload("res://Scenes/enemy_laser.tscn") -var enemy_y_wing_turret_laser = null +var enemy_y_wing_turret_laser = preload("res://Scenes/turret_laser.tscn") var enemy_y_wing_main_laser = null @onready var player = $player @@ -60,11 +60,13 @@ func fire_enemy_laser(location): e.global_position = location add_child(e) -func firey_wingturret(location,rotation,target): - print(str(rotation)) - print(str(target)) - var l = enemy_y_wing_turret_laser.initialize(rotation,target) +func firey_wingturret(location,firing_solution,target): + var l = enemy_y_wing_turret_laser.instantiate() l.global_position = location + l.initialize(firing_solution,target) + #print(str(firing_solution)) + add_child(l) + #l.initialize(rotation,target) diff --git a/Scripts/enemy_ywing.gd b/Scripts/enemy_ywing.gd index 411e913..a915cc8 100644 --- a/Scripts/enemy_ywing.gd +++ b/Scripts/enemy_ywing.gd @@ -25,8 +25,8 @@ var main_cannon = true #can turret fire? (rate of fire control) var turret_cannon = true -var firing_solution = null -var target_area = null +var firing_solution : float +var target_area : Vector2 #reset raycast, setup settings @@ -52,7 +52,10 @@ func _physics_process(delta): if target_ray.is_colliding and target_ray.get_collider() is player: if turret_cannon == true: - fire_turret(turret_muzzle,firing_solution,target_area) + fire_turret(turret_muzzle.global_position,firing_solution,target_area) + #print(str(turret_muzzle.global_position)) + #print(str(firing_solution)) + #print(str(target_area)) turret_timer.start() turret_cannon = false @@ -90,8 +93,11 @@ func aim_turret(delta): firing_solution = atan2(target.y - turret_pos.y, target.x - turret_pos.x)-90*(PI/180) target_area = target_pos -func fire_turret(location,rotation,target_area): - get_tree().current_scene.firey_wingturret(location,rotation,target_area) +func fire_turret(location,firing_solution,target_area): + get_tree().current_scene.firey_wingturret(location,firing_solution,target_area) + #print(str(location)) + #print(str(firing_solution)) + #print(str(target_area)) diff --git a/Scripts/turret_laser.gd b/Scripts/turret_laser.gd index e7d3bc1..412defd 100644 --- a/Scripts/turret_laser.gd +++ b/Scripts/turret_laser.gd @@ -3,6 +3,7 @@ extends Area2D @onready var turret_laser = $Sprite2D + var speed = 100 var target2 : Vector2 var new_rot @@ -10,14 +11,14 @@ func initialize(firing_solution,target): print('firing_solution='+str(firing_solution)) new_rot = firing_solution #turret_laser.set_rotation(firing_solution) - print(str(turret_laser)) - print(str(firing_solution)) + #print(str(turret_laser)) + #print(str(firing_solution)) target2 = target #print(str(firing_solution)) func _ready(): - turret_laser.set_rotation(new_rot) - $CollisionShape2D.set_rotation(new_rot) + set_rotation(new_rot) + func _physics_process(delta): #print(str(global_position.x - target.x)) @@ -26,4 +27,9 @@ func _physics_process(delta): #print(typeof(global_position)) #print(typeof(target)) global_position -= (global_position - target2).normalized() * speed * delta - pass + + +func _on_area_entered(area): + if area is player: + area.take_damage(1) + queue_free()