From 076976db2c95c9b0d7b113032a8cc02d8f30556c Mon Sep 17 00:00:00 2001 From: Luna Brovchuk Date: Mon, 2 Oct 2023 21:35:23 +0200 Subject: [PATCH] Stun --- src/models/bullet/bullet.gd | 3 ++- src/models/enemies/rat/Rat.tscn | 2 +- src/models/player/Player.tscn | 1 - src/models/player/player.gd | 28 +++++++++++++++++++++------ src/models/sonic_wave/Sonic_Wave.tscn | 2 +- 5 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/models/bullet/bullet.gd b/src/models/bullet/bullet.gd index 364b5e2..4b906ee 100644 --- a/src/models/bullet/bullet.gd +++ b/src/models/bullet/bullet.gd @@ -7,6 +7,7 @@ var damage = 5 var freeze_modifier = 1 var bounced = 0 var ricochet_count = 0 +var damage_multiplier = 1 var prev_target var target var explosive_damage = 0 @@ -39,7 +40,7 @@ func area_entered(area): var parent = area.get_parent() if parent.is_in_group("enemy") and parent != prev_target: prev_target = parent - parent.deal_damage(damage) + parent.deal_damage(damage * damage_multiplier) parent.freeze_modifier = freeze_modifier parent.frozen_timer = 0 parent.poison_damage = poison_damage diff --git a/src/models/enemies/rat/Rat.tscn b/src/models/enemies/rat/Rat.tscn index 72461de..4bbe4eb 100644 --- a/src/models/enemies/rat/Rat.tscn +++ b/src/models/enemies/rat/Rat.tscn @@ -16,7 +16,7 @@ use_parent_material = true position = Vector2( -3, 0 ) frames = ExtResource( 1 ) animation = "idle" -frame = 2 +frame = 1 playing = true centered = false diff --git a/src/models/player/Player.tscn b/src/models/player/Player.tscn index 65a2f32..b21224f 100644 --- a/src/models/player/Player.tscn +++ b/src/models/player/Player.tscn @@ -124,7 +124,6 @@ visible = false position = Vector2( 11, 2 ) frames = ExtResource( 5 ) animation = "idle" -frame = 1 playing = true [node name="AudioGetDamage" type="AudioStreamPlayer" parent="."] diff --git a/src/models/player/player.gd b/src/models/player/player.gd index 3b533a8..50087d1 100644 --- a/src/models/player/player.gd +++ b/src/models/player/player.gd @@ -10,6 +10,7 @@ var speed_multiplier: float = 1.0 var invincibility_timer = .0 var velocity = Vector2.ZERO var recharge_timer = .0 +var stunned_timer = .0 var invincible = false var stunned = false var target @@ -60,6 +61,7 @@ func choose_target(): func area_entered(area): var parent = area.get_parent() + if not is_instance_valid(parent): return if parent.is_in_group("enemy") and not parent.is_in_group("bat") and not invincible: $AnimationPlayer.play("damage") $AudioGetDamage.play() @@ -67,6 +69,12 @@ func area_entered(area): invincible = true invincibility_timer = .0 get_tree().get_root().get_node("Game/View/Camera2D").current = true + if is_instance_valid(parent) and parent.is_in_group("sonic_wave") and not stunned and not invincible: + stunned = true + $Stars.visible = true + stunned_timer = .0 + recharge_timer = .0 + $Sprite.play("stun") func get_recharge(): var recharge = 2.0 @@ -87,7 +95,7 @@ func _shoot(): for modifier in spell_holder.modifiers: match modifier: "ricochet": ricochet_count += 1 - "big_magic": dmg_multiplier *= 1.25 + "big_magic": dmg_multiplier *= 1.5 "explode": explosive_damage += 10 "fireball": fireball_amount += 1 "freeze": freeze_modifier /= 2.0 @@ -97,7 +105,7 @@ func _shoot(): bullet = bullet_preload.instance() bullet.target = target - bullet.damage *= dmg_multiplier + bullet.damage_multiplier = dmg_multiplier bullet.scale = Vector2(dmg_multiplier, dmg_multiplier) bullet.explosive_damage = explosive_damage bullet.freeze_modifier = freeze_modifier @@ -130,7 +138,7 @@ func _draw(): draw_dashed_line(Vector2(12, 12), target.global_position - self.global_position + mob_offset, Color("ffde00"), 1) func _process(_delta): - if Global.playing: + if Global.playing and not stunned: $Sprite.play("idle") if velocity == Vector2.ZERO else $Sprite.play("run") if abs(velocity.x) > 10: $Sprite.flip_h = true if velocity.x < 0 else false @@ -148,6 +156,12 @@ func _process(_delta): func _physics_process(delta): get_input() + if stunned: + stunned_timer += delta + if stunned_timer >= 1.5: + stunned = false + $Stars.visible = false + var areas = $DirtCollision.get_overlapping_areas() slowed = false for area in areas: @@ -172,9 +186,11 @@ func _physics_process(delta): if Global.playing: $Sprite.playing = true invincibility_timer += delta - if recharge_timer <= get_recharge(): - recharge_timer += delta - velocity = move_and_slide(velocity * speed_multiplier) + + if not stunned: + if recharge_timer <= get_recharge(): + recharge_timer += delta + velocity = move_and_slide(velocity * speed_multiplier) else: $Sprite.playing = false diff --git a/src/models/sonic_wave/Sonic_Wave.tscn b/src/models/sonic_wave/Sonic_Wave.tscn index ee3e8e0..ba84afd 100644 --- a/src/models/sonic_wave/Sonic_Wave.tscn +++ b/src/models/sonic_wave/Sonic_Wave.tscn @@ -6,7 +6,7 @@ [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 3, 4.25 ) -[node name="Sonic_Wave" type="KinematicBody2D"] +[node name="Sonic_Wave" type="KinematicBody2D" groups=["sonic_wave"]] script = ExtResource( 2 ) [node name="Sprite" type="Sprite" parent="."]