Merge pull request 'dev-health-attack2' (#66) from dev-health-attack2 into dev-base

Reviewed-on: #66
This commit is contained in:
Snoweuph 2023-04-23 13:25:39 +00:00
commit 6c5c5138c2
10 changed files with 68 additions and 36 deletions

View file

@ -41,7 +41,7 @@
[ext_resource type="StyleBox" uid="uid://0jfr1uwuog0s" path="res://Assets/UI/Slider/v/background.tres" id="39_dl1e4"] [ext_resource type="StyleBox" uid="uid://0jfr1uwuog0s" path="res://Assets/UI/Slider/v/background.tres" id="39_dl1e4"]
[ext_resource type="FontFile" uid="uid://dqdeftjkwxe64" path="res://Assets/Fonts/Dogica/dogicapixel.ttf" id="40_bmcvq"] [ext_resource type="FontFile" uid="uid://dqdeftjkwxe64" path="res://Assets/Fonts/Dogica/dogicapixel.ttf" id="40_bmcvq"]
[sub_resource type="Image" id="Image_iuu86"] [sub_resource type="Image" id="Image_dx2gc"]
data = { data = {
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0), "data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 64, 255, 255, 255, 64, 255, 255, 255, 0),
"format": "RGBA8", "format": "RGBA8",
@ -51,7 +51,7 @@ data = {
} }
[sub_resource type="ImageTexture" id="ImageTexture_g5bup"] [sub_resource type="ImageTexture" id="ImageTexture_g5bup"]
image = SubResource("Image_iuu86") image = SubResource("Image_dx2gc")
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_sj7h5"] [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_sj7h5"]

View file

@ -1,12 +1,12 @@
[gd_scene load_steps=17 format=3 uid="uid://c4btepmue6d7p"] [gd_scene load_steps=17 format=3 uid="uid://cg4xag5jx65kg"]
[ext_resource type="TileSet" uid="uid://bj7uu2180mie3" path="res://Assets/Tileset.tres" id="1_38041"] [ext_resource type="TileSet" uid="uid://bj7uu2180mie3" path="res://Assets/Tileset.tres" id="1_38041"]
[ext_resource type="Script" path="res://Scripts/GameManager.gd" id="1_t708k"] [ext_resource type="Script" path="res://Scripts/GameManager.gd" id="1_t708k"]
[ext_resource type="Script" path="res://Scripts/MapGenerator.gd" id="2_ope8r"] [ext_resource type="Script" path="res://Scripts/MapGenerator.gd" id="2_ope8r"]
[ext_resource type="Script" path="res://Scripts/EntitySystem/BunnyGenerator.gd" id="3_o045y"] [ext_resource type="Script" path="res://Scripts/EntitySystem/BunnyGenerator.gd" id="3_o045y"]
[ext_resource type="PackedScene" uid="uid://cpl4tllohhyel" path="res://Prefabs/bunny.tscn" id="4_hpafd"] [ext_resource type="PackedScene" uid="uid://cpl4tllohhyel" path="res://Prefabs/bunny.tscn" id="4_hpafd"]
[ext_resource type="Script" path="res://Scripts/PlayerController.gd" id="5_d2cbj"]
[ext_resource type="Texture2D" uid="uid://ojlfqxj5bilo" path="res://Assets/Sprites/Jesus/jesus_spritesheet.png" id="6_p526i"] [ext_resource type="Texture2D" uid="uid://ojlfqxj5bilo" path="res://Assets/Sprites/Jesus/jesus_spritesheet.png" id="6_p526i"]
[ext_resource type="Script" path="res://Scripts/Player.gd" id="6_q3xml"]
[ext_resource type="Script" path="res://Scripts/WeaponSystem/WeaponController.gd" id="7_mtrts"] [ext_resource type="Script" path="res://Scripts/WeaponSystem/WeaponController.gd" id="7_mtrts"]
[ext_resource type="PackedScene" uid="uid://csxh42o8twxwn" path="res://Prefabs/projectile.tscn" id="8_fp1vx"] [ext_resource type="PackedScene" uid="uid://csxh42o8twxwn" path="res://Prefabs/projectile.tscn" id="8_fp1vx"]
@ -119,10 +119,11 @@ _data = {
"RESET": SubResource("Animation_o3hln") "RESET": SubResource("Animation_o3hln")
} }
[node name="GameManager" type="Node2D" node_paths=PackedStringArray("map_generator", "bunny_generator")] [node name="GameManager" type="Node2D" node_paths=PackedStringArray("map_generator", "bunny_generator", "player")]
script = ExtResource("1_t708k") script = ExtResource("1_t708k")
map_generator = NodePath("Map Generator") map_generator = NodePath("Map Generator")
bunny_generator = NodePath("Bunny Generator") bunny_generator = NodePath("Bunny Generator")
player = NodePath("Player")
[node name="Map Generator" type="TileMap" parent="."] [node name="Map Generator" type="TileMap" parent="."]
scale = Vector2(1.5, 1.5) scale = Vector2(1.5, 1.5)
@ -141,7 +142,7 @@ player = NodePath("../Player")
[node name="Player" type="CharacterBody2D" parent="." node_paths=PackedStringArray("animation_player")] [node name="Player" type="CharacterBody2D" parent="." node_paths=PackedStringArray("animation_player")]
position = Vector2(1440, 810) position = Vector2(1440, 810)
collision_layer = 0 collision_layer = 0
script = ExtResource("5_d2cbj") script = ExtResource("6_q3xml")
animation_player = NodePath("Player Animator") animation_player = NodePath("Player Animator")
[node name="Player Sprite" type="Sprite2D" parent="Player"] [node name="Player Sprite" type="Sprite2D" parent="Player"]

View file

@ -1,11 +1,11 @@
[gd_scene load_steps=17 format=3 uid="uid://dkcl1ycmxpilw"] [gd_scene load_steps=17 format=3]
[ext_resource type="Script" path="res://Scripts/GameManager.gd" id="1_1tmfd"] [ext_resource type="Script" path="res://Scripts/GameManager.gd" id="1_1tmfd"]
[ext_resource type="TileSet" uid="uid://bj7uu2180mie3" path="res://Assets/Tileset.tres" id="2_bqk0y"] [ext_resource type="TileSet" uid="uid://bj7uu2180mie3" path="res://Assets/Tileset.tres" id="2_bqk0y"]
[ext_resource type="Script" path="res://Scripts/MapGenerator.gd" id="3_n0wjg"] [ext_resource type="Script" path="res://Scripts/MapGenerator.gd" id="3_n0wjg"]
[ext_resource type="Script" path="res://Scripts/EntitySystem/BunnyGenerator.gd" id="4_0by8r"] [ext_resource type="Script" path="res://Scripts/EntitySystem/BunnyGenerator.gd" id="4_0by8r"]
[ext_resource type="PackedScene" uid="uid://cpl4tllohhyel" path="res://Prefabs/bunny.tscn" id="5_ghq1m"] [ext_resource type="PackedScene" uid="uid://cpl4tllohhyel" path="res://Prefabs/bunny.tscn" id="5_ghq1m"]
[ext_resource type="Script" path="res://Scripts/PlayerController.gd" id="6_o5qq4"] [ext_resource type="Script" path="res://Scripts/Player.gd" id="6_o5qq4"]
[ext_resource type="Texture2D" uid="uid://ojlfqxj5bilo" path="res://Assets/Sprites/Jesus/jesus_spritesheet.png" id="7_we2bi"] [ext_resource type="Texture2D" uid="uid://ojlfqxj5bilo" path="res://Assets/Sprites/Jesus/jesus_spritesheet.png" id="7_we2bi"]
[ext_resource type="Script" path="res://Scripts/WeaponSystem/WeaponController.gd" id="8_p0li1"] [ext_resource type="Script" path="res://Scripts/WeaponSystem/WeaponController.gd" id="8_p0li1"]
[ext_resource type="PackedScene" uid="uid://csxh42o8twxwn" path="res://Prefabs/projectile.tscn" id="9_k5fai"] [ext_resource type="PackedScene" uid="uid://csxh42o8twxwn" path="res://Prefabs/projectile.tscn" id="9_k5fai"]

View file

@ -1,11 +1,11 @@
[gd_scene load_steps=19 format=3 uid="uid://beio3828jo4ht"] [gd_scene load_steps=19 format=3]
[ext_resource type="Script" path="res://Scripts/GameManager.gd" id="1_nh5gk"] [ext_resource type="Script" path="res://Scripts/GameManager.gd" id="1_nh5gk"]
[ext_resource type="TileSet" uid="uid://bj7uu2180mie3" path="res://Assets/Tileset.tres" id="2_ws3yx"] [ext_resource type="TileSet" uid="uid://bj7uu2180mie3" path="res://Assets/Tileset.tres" id="2_ws3yx"]
[ext_resource type="Script" path="res://Scripts/MapGenerator.gd" id="3_335m3"] [ext_resource type="Script" path="res://Scripts/MapGenerator.gd" id="3_335m3"]
[ext_resource type="Script" path="res://Scripts/EntitySystem/BunnyGenerator.gd" id="4_38mjq"] [ext_resource type="Script" path="res://Scripts/EntitySystem/BunnyGenerator.gd" id="4_38mjq"]
[ext_resource type="PackedScene" uid="uid://cpl4tllohhyel" path="res://Prefabs/bunny.tscn" id="5_24kvo"] [ext_resource type="PackedScene" uid="uid://cpl4tllohhyel" path="res://Prefabs/bunny.tscn" id="5_24kvo"]
[ext_resource type="Script" path="res://Scripts/PlayerController.gd" id="6_1tkxe"] [ext_resource type="Script" path="res://Scripts/Player.gd" id="6_1tkxe"]
[ext_resource type="Texture2D" uid="uid://ojlfqxj5bilo" path="res://Assets/Sprites/Jesus/jesus_spritesheet.png" id="7_6m0we"] [ext_resource type="Texture2D" uid="uid://ojlfqxj5bilo" path="res://Assets/Sprites/Jesus/jesus_spritesheet.png" id="7_6m0we"]
[ext_resource type="Script" path="res://Scripts/WeaponSystem/WeaponController.gd" id="8_ohifd"] [ext_resource type="Script" path="res://Scripts/WeaponSystem/WeaponController.gd" id="8_ohifd"]
[ext_resource type="PackedScene" uid="uid://csxh42o8twxwn" path="res://Prefabs/projectile.tscn" id="9_unx3c"] [ext_resource type="PackedScene" uid="uid://csxh42o8twxwn" path="res://Prefabs/projectile.tscn" id="9_unx3c"]

View file

@ -1,10 +1,10 @@
[gd_scene load_steps=16 format=3 uid="uid://cugui0mjc6cfe"] [gd_scene load_steps=16 format=3]
[ext_resource type="TileSet" uid="uid://bj7uu2180mie3" path="res://Assets/Tileset.tres" id="1_s4utw"] [ext_resource type="TileSet" uid="uid://bj7uu2180mie3" path="res://Assets/Tileset.tres" id="1_s4utw"]
[ext_resource type="Script" path="res://Scripts/MapGenerator.gd" id="2_yhpwh"] [ext_resource type="Script" path="res://Scripts/MapGenerator.gd" id="2_yhpwh"]
[ext_resource type="Script" path="res://Scripts/EntitySystem/BunnyGenerator.gd" id="3_dvklj"] [ext_resource type="Script" path="res://Scripts/EntitySystem/BunnyGenerator.gd" id="3_dvklj"]
[ext_resource type="PackedScene" uid="uid://cpl4tllohhyel" path="res://Prefabs/bunny.tscn" id="4_0fyd5"] [ext_resource type="PackedScene" uid="uid://cpl4tllohhyel" path="res://Prefabs/bunny.tscn" id="4_0fyd5"]
[ext_resource type="Script" path="res://Scripts/PlayerController.gd" id="5_uv7bh"] [ext_resource type="Script" path="res://Scripts/Player.gd" id="5_uv7bh"]
[ext_resource type="Texture2D" uid="uid://ojlfqxj5bilo" path="res://Assets/Sprites/Jesus/jesus_spritesheet.png" id="6_es2l8"] [ext_resource type="Texture2D" uid="uid://ojlfqxj5bilo" path="res://Assets/Sprites/Jesus/jesus_spritesheet.png" id="6_es2l8"]
[ext_resource type="Script" path="res://Scripts/WeaponSystem/WeaponController.gd" id="7_8kdie"] [ext_resource type="Script" path="res://Scripts/WeaponSystem/WeaponController.gd" id="7_8kdie"]
[ext_resource type="PackedScene" uid="uid://csxh42o8twxwn" path="res://Prefabs/projectile.tscn" id="8_wx0kk"] [ext_resource type="PackedScene" uid="uid://csxh42o8twxwn" path="res://Prefabs/projectile.tscn" id="8_wx0kk"]

View file

@ -2,14 +2,19 @@ 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 attack_speed : float
var time_since_last_attack : float
var team : int var team : int
var player : Node2D var target : Node2D
var on_death_callbacks : Array var on_death_callbacks : Array
var move_velocity : Vector2 var move_velocity : Vector2
@ -34,24 +39,25 @@ 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() if target == null: return
if abs(player.velocity.length() - last_player_velocity) > 100.0: randomize()
if abs(target.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 target.velocity.length() > 0.1:
time_since_got_player = randf() * max_pos_check_time * 0.5 time_since_got_player = randf() * max_pos_check_time * 0.5
update_target_pos() update_target_pos()
if time_since_got_player >= max_pos_check_time * max_pos_check_time_inactive_scalar and player.velocity.length() < 0.1: if time_since_got_player >= max_pos_check_time * max_pos_check_time_inactive_scalar and target.velocity.length() < 0.1:
time_since_got_player = -(randf() * max_pos_check_time * 0.5) time_since_got_player = -(randf() * max_pos_check_time * 0.5)
update_target_pos() update_target_pos()
if self.global_position.distance_to(player.global_position) < max_distance_to_player and time_since_got_move_location > max_get_move_location_time: if self.global_position.distance_to(target.global_position) < max_distance_to_player and time_since_got_move_location > max_get_move_location_time:
time_since_got_move_location = 0 time_since_got_move_location = 0
if agent.is_target_reachable(): if agent.is_target_reachable():
next_location = agent.get_next_path_position() next_location = agent.get_next_path_position()
randomized_next_location = next_location + Vector2(randf() - 0.5, randf() - 0.5 ) * 2 * random_move_location_spread_factor randomized_next_location = next_location + Vector2(randf() - 0.5, randf() - 0.5 ) * 2 * random_move_location_spread_factor
dir = self.global_position.direction_to(randomized_next_location).normalized().rotated((randf() - 0.5) * 2 * random_angle_change) dir = self.global_position.direction_to(randomized_next_location).normalized().rotated((randf() - 0.5) * 2 * random_angle_change)
if self.global_position.distance_to(player.global_position) >= min_distance_to_player: if self.global_position.distance_to(target.global_position) >= min_distance_to_player:
move_velocity = dir * delta * 60 * speed move_velocity = dir * delta * 60 * speed
update_animation() update_animation()
if self.global_position.distance_to(next_location) < move_velocity.length(): if self.global_position.distance_to(next_location) < move_velocity.length():
@ -62,22 +68,30 @@ 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
last_player_velocity = player.velocity.length() time_since_last_attack += delta
last_player_velocity = target.velocity.length()
last_target_position = agent.target_position last_target_position = agent.target_position
pass pass
func update_target_pos(): func update_attack(delta : float):
agent.target_position = Vector2(player.global_position) + Vector2(randf() - 0.5 , randf() - 0.5) * 2 * random_goal_spread_factor if time_since_last_attack >= attack_speed:
time_since_last_attack = 0
target.damage(damage)
pass pass
func damage(damage_amount : int): func update_target_pos():
agent.target_position = Vector2(target.global_position) + Vector2(randf() - 0.5 , randf() - 0.5) * 2 * random_goal_spread_factor
pass
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

View file

@ -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, 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.attack_speed = attack_speed
bunny.team = team bunny.team = team
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, 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
@ -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, 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) -> 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) 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) 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

View file

@ -2,6 +2,7 @@ extends Node2D
@export var map_generator : Node @export var map_generator : Node
@export var bunny_generator : Node @export var bunny_generator : Node
@export var player : Node
var bunnys = [] var bunnys = []
var gen_data : Dictionary var gen_data : Dictionary
@ -17,9 +18,17 @@ 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, 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.target = get_enemy_target(bunny.team)
bunny.sub_on_death(func(bunny): bunny.queue_free()) bunny.sub_on_death(func(bunny): bunny.queue_free())
in_wave_gen = false in_wave_gen = false
pass pass
func get_enemy_target(own_team : int) -> Node:
match own_team:
TEAM.EVIL: return player
TEAM.GOOD: return null
_: return null
pass

View file

@ -1,7 +1,8 @@
extends CharacterBody2D extends CharacterBody2D
@export var speed = 200 @export var speed := 200.0
@export_range(0, 1) var damping_factor = 0.6 @export var health := 100
@export_range(0, 1) var damping_factor := 0.6
@export var animation_player : AnimationPlayer @export var animation_player : AnimationPlayer
func _physics_process(delta : float): func _physics_process(delta : float):
@ -42,3 +43,9 @@ func update_player_animation():
up_dot: animation_player.play("MoveUp") up_dot: animation_player.play("MoveUp")
down_dot: animation_player.play("MoveDown") down_dot: animation_player.play("MoveDown")
pass pass
func damage(amount : int):
health -= amount
if(health <= 0): print("Player Dead")
pass

View file

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