From 71e3b6ae4aa221773a4e87ce700b9f6485bc4bcb Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Sun, 23 Apr 2023 14:50:34 +0200 Subject: [PATCH] Adding Damage stat to bunnys --- Scripts/EntitySystem/Bunny.gd | 5 +++-- Scripts/EntitySystem/BunnyGenerator.gd | 13 +++++++------ Scripts/GameManager.gd | 2 +- Scripts/WeaponSystem/Projectile.gd | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Scripts/EntitySystem/Bunny.gd b/Scripts/EntitySystem/Bunny.gd index 76c73ae..cf16778 100644 --- a/Scripts/EntitySystem/Bunny.gd +++ b/Scripts/EntitySystem/Bunny.gd @@ -8,6 +8,7 @@ class_name Bunny @export var speed := 3.0 var health : int +var damage : int var team : int var player : Node2D @@ -72,12 +73,12 @@ func update_target_pos(): agent.target_position = Vector2(player.global_position) + Vector2(randf() - 0.5 , randf() - 0.5) * 2 * random_goal_spread_factor pass -func damage(damage_amount : int): +func take_damage(damage_amount : int): health -= damage_amount if(health <= 0): on_death() pass -func heal(health_amount : int): +func get_heal(health_amount : int): self.health += health_amount pass diff --git a/Scripts/EntitySystem/BunnyGenerator.gd b/Scripts/EntitySystem/BunnyGenerator.gd index 5087540..d38e0e1 100644 --- a/Scripts/EntitySystem/BunnyGenerator.gd +++ b/Scripts/EntitySystem/BunnyGenerator.gd @@ -6,16 +6,17 @@ class_name BunnyGenerator @export var player_save_distance : float = 400 @onready var BunnyPrefab : PackedScene = load(bunny_prefab.resource_path) -func spawn_bunny(pos : Vector2, team : int, health : int) -> Bunny: +func spawn_bunny(pos : Vector2, team : int, health : int, damage : int) -> Bunny: var bunny = BunnyPrefab.instantiate() self.add_child(bunny) bunny.global_position = pos bunny.health = health + bunny.damage = damage bunny.team = team bunny.player = player return bunny -func spawn_wave(free_tiles : Array, team: int, amount : int, health : int) -> Array: +func spawn_wave(free_tiles : Array, team: int, amount : int, health : int, damage : int) -> Array: var bunnys = [] # Make Sure that no possitions to near to the player are insdie of the list @@ -27,19 +28,19 @@ func spawn_wave(free_tiles : Array, team: int, amount : int, health : int) -> Ar for i in amount: var pos = free_tiles.pick_random() free_tiles.erase(pos) - var bunny = spawn_bunny(pos, team, health) + var bunny = spawn_bunny(pos, team, health, damage) bunnys.push_back(bunny) return bunnys -func spawn_batched_wave(batch_size : float, batch_delay: float, free_tiles : Array, team: int, amount : int, health : int) -> Array: +func spawn_batched_wave(batch_size : float, batch_delay: float, free_tiles : Array, team: int, amount : int, health : int, damage : int) -> Array: var bunnys = [] var batch_count = ceil(amount / batch_size) var actual_batch_size = floor(amount / batch_count) var last_batch_size = amount - batch_size * batch_count for s in batch_count: - bunnys += spawn_wave(free_tiles.duplicate(), team, actual_batch_size, health) + bunnys += spawn_wave(free_tiles.duplicate(), team, actual_batch_size, health, damage) await get_tree().create_timer(batch_delay).timeout - bunnys += spawn_wave(free_tiles.duplicate(), team, last_batch_size, health) + bunnys += spawn_wave(free_tiles.duplicate(), team, last_batch_size, health, damage) await get_tree().create_timer(batch_delay).timeout return bunnys diff --git a/Scripts/GameManager.gd b/Scripts/GameManager.gd index a391bef..10cc48a 100644 --- a/Scripts/GameManager.gd +++ b/Scripts/GameManager.gd @@ -17,7 +17,7 @@ func _process(_delta): if bunnys.size() == 0 and !in_wave_gen: in_wave_gen = true wave += 1 - bunnys = await bunny_generator.spawn_batched_wave(25, 0.25, gen_data.free_tiles.duplicate(), TEAM.EVIL, wave * 250, 3) + bunnys = await bunny_generator.spawn_batched_wave(25, 0.25, gen_data.free_tiles.duplicate(), TEAM.EVIL, wave * 250, 3, 1) for bunny in bunnys: bunny.sub_on_death(func(bunny): bunnys.erase(bunny)) bunny.sub_on_death(func(bunny): bunny.queue_free()) diff --git a/Scripts/WeaponSystem/Projectile.gd b/Scripts/WeaponSystem/Projectile.gd index 345c8a6..ee4df99 100644 --- a/Scripts/WeaponSystem/Projectile.gd +++ b/Scripts/WeaponSystem/Projectile.gd @@ -30,7 +30,7 @@ func _on_collision(body): queue_free() if collided_layer & bunny_collision_layer: var bunny = body as Bunny - bunny.damage(damage) + bunny.take_damage(damage) queue_free() pass