dev-health-attack2 #66
3 changed files with 22 additions and 10 deletions
|
@ -2,13 +2,17 @@ extends CharacterBody2D
|
||||||
class_name Bunny
|
class_name Bunny
|
||||||
|
|
||||||
@export var animation_player : AnimationPlayer
|
@export var animation_player : AnimationPlayer
|
||||||
@export var min_distance_to_player := 20.0
|
@export var min_distance_to_player := 10.0
|
||||||
@export var max_distance_to_player := 500.0
|
@export var max_distance_to_player := 500.0
|
||||||
@export var agent : NavigationAgent2D
|
@export var agent : NavigationAgent2D
|
||||||
@export var speed := 3.0
|
@export var speed := 3.0
|
||||||
|
|
||||||
var health : int
|
var health : int
|
||||||
var damage : int
|
var damage : int
|
||||||
|
|
||||||
|
var attack_speed : float
|
||||||
|
var time_since_last_attack : float
|
||||||
|
|
||||||
var team : int
|
var team : int
|
||||||
var player : Node2D
|
var player : Node2D
|
||||||
|
|
||||||
|
@ -35,9 +39,8 @@ var random_angle_change := deg_to_rad(4.0)
|
||||||
func _ready():
|
func _ready():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta : float):
|
||||||
randomize()
|
randomize()
|
||||||
|
|
||||||
if abs(player.velocity.length() - last_player_velocity) > 100.0:
|
if abs(player.velocity.length() - last_player_velocity) > 100.0:
|
||||||
time_since_got_player = max_pos_check_time
|
time_since_got_player = max_pos_check_time
|
||||||
if time_since_got_player >= max_pos_check_time and player.velocity.length() > 0.1:
|
if time_since_got_player >= max_pos_check_time and player.velocity.length() > 0.1:
|
||||||
|
@ -63,11 +66,19 @@ func _physics_process(delta):
|
||||||
move_and_collide(move_velocity)
|
move_and_collide(move_velocity)
|
||||||
else:
|
else:
|
||||||
animation_player.stop()
|
animation_player.stop()
|
||||||
|
update_attack(delta)
|
||||||
time_since_got_player += delta
|
time_since_got_player += delta
|
||||||
time_since_got_move_location += delta
|
time_since_got_move_location += delta
|
||||||
|
time_since_last_attack += delta
|
||||||
last_player_velocity = player.velocity.length()
|
last_player_velocity = player.velocity.length()
|
||||||
last_target_position = agent.target_position
|
last_target_position = agent.target_position
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
func update_attack(delta : float):
|
||||||
|
if time_since_last_attack >= attack_speed:
|
||||||
|
time_since_last_attack = 0
|
||||||
|
print("bunny attacking with: " + str(damage) + " damage")
|
||||||
|
pass
|
||||||
|
|
||||||
func update_target_pos():
|
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
|
||||||
|
|
|
@ -6,17 +6,18 @@ 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, damage : int) -> Bunny:
|
func spawn_bunny(pos : Vector2, team : int, health : int, damage : int, attack_speed : float) -> 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.damage = damage
|
||||||
|
bunny.attack_speed = attack_speed
|
||||||
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, damage : int) -> Array:
|
func spawn_wave(free_tiles : Array, team: int, amount : int, health : int, damage : int, attack_speed : float) -> 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
|
||||||
|
@ -28,19 +29,19 @@ func spawn_wave(free_tiles : Array, team: int, amount : int, health : int, damag
|
||||||
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, damage)
|
var bunny = spawn_bunny(pos, team, health, damage, attack_speed)
|
||||||
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, damage : int) -> Array:
|
func spawn_batched_wave(batch_size : float, batch_delay: float, free_tiles : Array, team: int, amount : int, health : int, damage : int, attack_speed : float) -> 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, damage)
|
bunnys += spawn_wave(free_tiles.duplicate(), team, actual_batch_size, health, damage, attack_speed)
|
||||||
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, damage)
|
bunnys += spawn_wave(free_tiles.duplicate(), team, last_batch_size, health, damage, attack_speed)
|
||||||
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, 1)
|
bunnys = await bunny_generator.spawn_batched_wave(25, 0.25, gen_data.free_tiles.duplicate(), TEAM.EVIL, wave * 250, 3, 1, 5.0)
|
||||||
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())
|
||||||
|
|
Reference in a new issue