From d2dc132952bf778f0af1dfcdaa67cc0198d95411 Mon Sep 17 00:00:00 2001 From: zerothelootrat Date: Fri, 7 Jun 2024 03:35:23 -0400 Subject: [PATCH] fixed y-wing turret laser trajectory. - Zerothelootrat --- README.md | 17 ++++++++++++----- Scenes/enemy_spawner.tscn | 2 +- Scenes/turret_laser.tscn | 5 +++++ Scripts/enemy_ywing.gd | 37 +++++++++++++++++++++++++------------ Scripts/turret_laser.gd | 22 +++++++++++++++++++++- 5 files changed, 64 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index e829a02..5bccf96 100644 --- a/README.md +++ b/README.md @@ -15,18 +15,25 @@ currently only have one enemy and one level up type ##todo: -- [x] Finish Y-Wing Art -- [x] Import Y-Wing & get turret working - -[x] Implement Y-Wing Main Cannon -- [ ] Power up 2 (shield) +- [ ] Power up 2 (shield) : After dinner 6/7/2024 - [ ] locate sounds - [ ] World Map -- [ ] Work on Boss fight +- [ ] Work on Boss Enemy +- [ ] Spawner Refactor to allow level editing +- [ ] Boss Fight state machine - [ ] Level 1 and boss fight +##finished: +- [x] Finish Y-Wing Art +- [x] Import Y-Wing & get turret working +- [x] Implement Y-Wing Main Cannon + update log: 6/4/2024 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? + +6/7/2024 +Y-wing 99% finished, tweaks required. added a few things to objectives list. moved finished objects to finished objects list. diff --git a/Scenes/enemy_spawner.tscn b/Scenes/enemy_spawner.tscn index f74016a..41c159c 100644 --- a/Scenes/enemy_spawner.tscn +++ b/Scenes/enemy_spawner.tscn @@ -23,7 +23,7 @@ position = Vector2(370, 0) position = Vector2(470, 0) [node name="SpawnTimer" type="Timer" parent="."] -wait_time = 2.0 +wait_time = 10.0 autostart = true [connection signal="timeout" from="SpawnTimer" to="." method="_on_spawn_timer_timeout"] diff --git a/Scenes/turret_laser.tscn b/Scenes/turret_laser.tscn index 93106b4..30a2085 100644 --- a/Scenes/turret_laser.tscn +++ b/Scenes/turret_laser.tscn @@ -20,4 +20,9 @@ texture = ExtResource("1_8xaek") position = Vector2(0, 2) shape = SubResource("CapsuleShape2D_kjs2o") +[node name="Timer" type="Timer" parent="."] +wait_time = 10.0 +autostart = true + [connection signal="area_entered" from="." to="." method="_on_area_entered"] +[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"] diff --git a/Scripts/enemy_ywing.gd b/Scripts/enemy_ywing.gd index 6702890..6dfcb72 100644 --- a/Scripts/enemy_ywing.gd +++ b/Scripts/enemy_ywing.gd @@ -49,6 +49,7 @@ func _physics_process(delta): fire_main_cannon() main_cannon = false mainCannonFire.start() + aim_turret(delta) if target_ray.is_colliding and target_ray.get_collider() is player: @@ -69,19 +70,31 @@ func _physics_process(delta): #turret.rotate(current_rotation) #turret.rotation(atan2(target.x - turret_pos.x,target.y - turret_pos.y)) +var default_target : Vector2 #figured out with loki, holy shit this was annoying func aim_turret(delta): - var target : Vector2 = get_tree().current_scene.player.global_position - var turret_pos = turret.global_position - var target_rot = atan2(target.x - turret_pos.x, target.y - turret_pos.y) - var target_pos = get_tree().current_scene.player.global_position - var current_rotation = turret.rotation + var player = get_tree().current_scene.player + if is_instance_valid(player): + + var target = get_tree().current_scene.player.global_position + var turret_pos = turret.global_position + var target_rot = atan2(target.x - turret_pos.x, target.y - turret_pos.y) + var target_pos = get_tree().current_scene.player.global_position + var current_rotation = turret.rotation + if target == null: + firing_solution = 0 + + if target == null: + default_target.x = 0 + default_target.y = 0 + target = default_target + - var speed = 5 #in degrees, can adjust - var direction = 1 - if target_rot < current_rotation: #may need to be "<" - direction = -1 + var speed = 5 #in degrees, can adjust + var direction = 1 + if target_rot < current_rotation: #may need to be "<" + direction = -1 #current_rotation += direction * speed * (PI/180) * delta #turret.look_at(target_pos) @@ -90,9 +103,9 @@ func aim_turret(delta): #current_rotation += current_rotation * 0.90 + target_rot * 0.10 #turret.set_rotation(atan2(target.x - turret_pos.x,target.y - turret_pos.y)) #turret.set_rotation(atan2(turret_pos.x - target.x, turret_pos.y - target_pos.y)) - turret.set_rotation(atan2(target.y - turret_pos.y, target.x - turret_pos.x)-90*(PI/180)) - firing_solution = atan2(target.y - turret_pos.y, target.x - turret_pos.x)-90*(PI/180) - target_area = target_pos + turret.set_rotation(atan2(target.y - turret_pos.y, target.x - turret_pos.x)-90*(PI/180)) + firing_solution = atan2(target.y - turret_pos.y, target.x - turret_pos.x)-90*(PI/180) + target_area = target_pos func fire_turret(location,firing_solution,target_area): get_tree().current_scene.firey_wingturret(location,firing_solution,target_area) diff --git a/Scripts/turret_laser.gd b/Scripts/turret_laser.gd index 412defd..19de85d 100644 --- a/Scripts/turret_laser.gd +++ b/Scripts/turret_laser.gd @@ -7,6 +7,7 @@ extends Area2D var speed = 100 var target2 : Vector2 var new_rot +var direction func initialize(firing_solution,target): print('firing_solution='+str(firing_solution)) new_rot = firing_solution @@ -18,6 +19,8 @@ func initialize(firing_solution,target): func _ready(): set_rotation(new_rot) + direction = (target2 - global_position).normalized() + func _physics_process(delta): @@ -26,10 +29,27 @@ func _physics_process(delta): #print(target2) #print(typeof(global_position)) #print(typeof(target)) - global_position -= (global_position - target2).normalized() * speed * delta + #var direction = (global_position - target2).normalized() + + #print("target2 " + str(target2)) + #print("direction normalized " + str(direction)) + #print("target_far " + str(target_far)) + #print("direction " + str(direction)) + #print("target2 " + str(target2)) + #global_position += (direction - global_position).normalized() * speed * delta + global_position += direction * speed * delta + if global_position.x >= 980: + #print("cleanup") + queue_free() + func _on_area_entered(area): if area is player: area.take_damage(1) queue_free() + + +func _on_timer_timeout(): + print("cleanup") + queue_free()