dev-health-attack2 #66

Merged
Snoweuph merged 3 commits from dev-health-attack2 into dev-base 2023-04-23 13:25:39 +00:00
3 changed files with 22 additions and 10 deletions
Showing only changes of commit 66ae4054c6 - Show all commits

View file

@ -2,13 +2,17 @@ extends CharacterBody2D
class_name Bunny
@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 agent : NavigationAgent2D
@export var speed := 3.0
var health : int
var damage : int
var attack_speed : float
var time_since_last_attack : float
var team : int
var player : Node2D
@ -35,9 +39,8 @@ var random_angle_change := deg_to_rad(4.0)
func _ready():
pass
func _physics_process(delta):
func _physics_process(delta : float):
randomize()
if abs(player.velocity.length() - last_player_velocity) > 100.0:
time_since_got_player = max_pos_check_time
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)
else:
animation_player.stop()
update_attack(delta)
time_since_got_player += delta
time_since_got_move_location += delta
time_since_last_attack += delta
last_player_velocity = player.velocity.length()
last_target_position = agent.target_position
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():
agent.target_position = Vector2(player.global_position) + Vector2(randf() - 0.5 , randf() - 0.5) * 2 * random_goal_spread_factor

View file

@ -6,17 +6,18 @@ 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, damage : int) -> Bunny:
func spawn_bunny(pos : Vector2, team : int, health : int, damage : int, attack_speed : float) -> Bunny:
var bunny = BunnyPrefab.instantiate()
self.add_child(bunny)
bunny.global_position = pos
bunny.health = health
bunny.damage = damage
bunny.attack_speed = attack_speed
bunny.team = team
bunny.player = player
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 = []
# 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:
var pos = free_tiles.pick_random()
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)
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 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, damage)
bunnys += spawn_wave(free_tiles.duplicate(), team, actual_batch_size, health, damage, attack_speed)
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
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, 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:
bunny.sub_on_death(func(bunny): bunnys.erase(bunny))
bunny.sub_on_death(func(bunny): bunny.queue_free())