dev-health-attack2 #66
4 changed files with 12 additions and 10 deletions
|
@ -8,6 +8,7 @@ class_name Bunny
|
||||||
@export var speed := 3.0
|
@export var speed := 3.0
|
||||||
|
|
||||||
var health : int
|
var health : int
|
||||||
|
var damage : int
|
||||||
var team : int
|
var team : int
|
||||||
var player : Node2D
|
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
|
agent.target_position = Vector2(player.global_position) + Vector2(randf() - 0.5 , randf() - 0.5) * 2 * random_goal_spread_factor
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func damage(damage_amount : int):
|
func take_damage(damage_amount : int):
|
||||||
health -= damage_amount
|
health -= damage_amount
|
||||||
if(health <= 0): on_death()
|
if(health <= 0): on_death()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func heal(health_amount : int):
|
func get_heal(health_amount : int):
|
||||||
self.health += health_amount
|
self.health += health_amount
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
|
@ -6,16 +6,17 @@ class_name BunnyGenerator
|
||||||
@export var player_save_distance : float = 400
|
@export var player_save_distance : float = 400
|
||||||
@onready var BunnyPrefab : PackedScene = load(bunny_prefab.resource_path)
|
@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()
|
var bunny = BunnyPrefab.instantiate()
|
||||||
self.add_child(bunny)
|
self.add_child(bunny)
|
||||||
bunny.global_position = pos
|
bunny.global_position = pos
|
||||||
bunny.health = health
|
bunny.health = health
|
||||||
|
bunny.damage = damage
|
||||||
bunny.team = team
|
bunny.team = team
|
||||||
bunny.player = player
|
bunny.player = player
|
||||||
return bunny
|
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 = []
|
var bunnys = []
|
||||||
|
|
||||||
# Make Sure that no possitions to near to the player are insdie of the list
|
# 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:
|
for i in amount:
|
||||||
var pos = free_tiles.pick_random()
|
var pos = free_tiles.pick_random()
|
||||||
free_tiles.erase(pos)
|
free_tiles.erase(pos)
|
||||||
var bunny = spawn_bunny(pos, team, health)
|
var bunny = spawn_bunny(pos, team, health, damage)
|
||||||
bunnys.push_back(bunny)
|
bunnys.push_back(bunny)
|
||||||
return bunnys
|
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 bunnys = []
|
||||||
var batch_count = ceil(amount / batch_size)
|
var batch_count = ceil(amount / batch_size)
|
||||||
var actual_batch_size = floor(amount / batch_count)
|
var actual_batch_size = floor(amount / batch_count)
|
||||||
var last_batch_size = amount - batch_size * batch_count
|
var last_batch_size = amount - batch_size * batch_count
|
||||||
|
|
||||||
for s in 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
|
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
|
await get_tree().create_timer(batch_delay).timeout
|
||||||
return bunnys
|
return bunnys
|
||||||
|
|
|
@ -17,7 +17,7 @@ func _process(_delta):
|
||||||
if bunnys.size() == 0 and !in_wave_gen:
|
if bunnys.size() == 0 and !in_wave_gen:
|
||||||
in_wave_gen = true
|
in_wave_gen = true
|
||||||
wave += 1
|
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:
|
for bunny in bunnys:
|
||||||
bunny.sub_on_death(func(bunny): bunnys.erase(bunny))
|
bunny.sub_on_death(func(bunny): bunnys.erase(bunny))
|
||||||
bunny.sub_on_death(func(bunny): bunny.queue_free())
|
bunny.sub_on_death(func(bunny): bunny.queue_free())
|
||||||
|
|
|
@ -30,7 +30,7 @@ func _on_collision(body):
|
||||||
queue_free()
|
queue_free()
|
||||||
if collided_layer & bunny_collision_layer:
|
if collided_layer & bunny_collision_layer:
|
||||||
var bunny = body as Bunny
|
var bunny = body as Bunny
|
||||||
bunny.damage(damage)
|
bunny.take_damage(damage)
|
||||||
queue_free()
|
queue_free()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Reference in a new issue