From dc3af8c23ae0c950c5a66a743c41be093ad42f95 Mon Sep 17 00:00:00 2001 From: Luna Brovchuk Date: Sun, 1 Oct 2023 22:21:49 +0200 Subject: [PATCH] Finish Sonic Waves (XD) --- src/models/enemies/bat/Bat.tscn | 6 ------ src/models/enemies/bat/bat.gd | 31 +++++++++++++++++++++-------- src/models/player/Player.tscn | 6 +++--- src/models/sonic_wave/Sonic_Wave.gd | 8 ++++++-- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/src/models/enemies/bat/Bat.tscn b/src/models/enemies/bat/Bat.tscn index 31ae654..940b0be 100644 --- a/src/models/enemies/bat/Bat.tscn +++ b/src/models/enemies/bat/Bat.tscn @@ -19,7 +19,6 @@ script = ExtResource( 2 ) use_parent_material = true frames = ExtResource( 1 ) animation = "idle" -frame = 2 playing = true centered = false @@ -32,8 +31,3 @@ shape = SubResource( 1 ) [node name="SameSpeciesCollider" type="CollisionShape2D" parent="."] position = Vector2( 8.5, 10 ) shape = SubResource( 2 ) - -[node name="Timer" type="Timer" parent="."] -autostart = true - -[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"] diff --git a/src/models/enemies/bat/bat.gd b/src/models/enemies/bat/bat.gd index 7d250f1..0d1a8b9 100644 --- a/src/models/enemies/bat/bat.gd +++ b/src/models/enemies/bat/bat.gd @@ -4,12 +4,31 @@ var velocity = Vector2.ZERO var speed = 64 onready var sonic_wave_preload = preload("res://src/models/sonic_wave/Sonic_Wave.tscn") +var shooting_timer = .0 +var attack_timer = .0 +var shooting = false +var shot = false var sonic_wave func _ready(): hp = 15 -func _physics_process(_delta): +func _physics_process(delta): + if not shooting: + shooting_timer += delta + if shooting_timer >= 2.0: + shooting = true + shooting_timer = .0 + if shooting: + attack_timer += delta + if attack_timer >= .5 and not shot: + _shoot() + shot = true + if attack_timer >= 1.0: + attack_timer = 0 + shooting = false + shot = false + var player_position = player.global_position + Vector2(12, 12) var angle = get_angle_to(player_position) if position.distance_to(player_position) > 64: @@ -29,15 +48,11 @@ func _physics_process(_delta): self.global_position.y += sin(Time.get_ticks_msec() * 0.01) / 3 velocity *= speed * speed_multiplier - velocity = move_and_slide(velocity) - - + if not shooting: + velocity = move_and_slide(velocity) + func _shoot(): sonic_wave = sonic_wave_preload.instance() get_parent().add_child(sonic_wave) sonic_wave.global_position.x = self.global_position.x + 8 sonic_wave.global_position.y = self.global_position.y + 8 - - -func _on_Timer_timeout(): - _shoot() diff --git a/src/models/player/Player.tscn b/src/models/player/Player.tscn index 77b9f7f..e6e7505 100644 --- a/src/models/player/Player.tscn +++ b/src/models/player/Player.tscn @@ -5,10 +5,10 @@ [ext_resource path="res://res/shaders/colorize.tres" type="Material" id=3] [sub_resource type="RectangleShape2D" id=1] -extents = Vector2( 3.5, 3.5 ) +extents = Vector2( 4, 4 ) [sub_resource type="RectangleShape2D" id=2] -extents = Vector2( 3.5, 9 ) +extents = Vector2( 7, 11 ) [sub_resource type="Animation" id=4] resource_name = "RESET" @@ -48,7 +48,7 @@ tracks/0/loop_wrap = true tracks/0/imported = false tracks/0/enabled = true tracks/0/keys = { -"times": PoolRealArray( 0, 2 ), +"times": PoolRealArray( 0, 0.9 ), "transitions": PoolRealArray( 1, 1 ), "update": 1, "values": [ true, false ] diff --git a/src/models/sonic_wave/Sonic_Wave.gd b/src/models/sonic_wave/Sonic_Wave.gd index 2f77e7a..a2f3653 100644 --- a/src/models/sonic_wave/Sonic_Wave.gd +++ b/src/models/sonic_wave/Sonic_Wave.gd @@ -3,7 +3,11 @@ extends KinematicBody2D var velocity = Vector2.ZERO var speed = 120 onready var player = $"../../Player" +var angle + +func _ready(): + angle = global_position.angle_to_point(player.global_position) func _physics_process(delta): - self.global_position = self.global_position.move_toward(player.global_position, delta * speed) - $Sprite.look_at(player.global_position) + $Sprite.rotation_degrees = rad2deg(angle + PI) + move_and_slide(Vector2(speed, 0).rotated(angle + PI))