Adding Damage stat to bunnys

This commit is contained in:
Snoweuph 2023-04-23 14:50:34 +02:00
parent fe89b4a00d
commit 71e3b6ae4a
4 changed files with 12 additions and 10 deletions

View file

@ -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

View file

@ -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

View file

@ -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())

View file

@ -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