From 71e3b6ae4aa221773a4e87ce700b9f6485bc4bcb Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Sun, 23 Apr 2023 14:50:34 +0200 Subject: [PATCH 1/3] Adding Damage stat to bunnys --- Scripts/EntitySystem/Bunny.gd | 5 +++-- Scripts/EntitySystem/BunnyGenerator.gd | 13 +++++++------ Scripts/GameManager.gd | 2 +- Scripts/WeaponSystem/Projectile.gd | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Scripts/EntitySystem/Bunny.gd b/Scripts/EntitySystem/Bunny.gd index 76c73ae..cf16778 100644 --- a/Scripts/EntitySystem/Bunny.gd +++ b/Scripts/EntitySystem/Bunny.gd @@ -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 diff --git a/Scripts/EntitySystem/BunnyGenerator.gd b/Scripts/EntitySystem/BunnyGenerator.gd index 5087540..d38e0e1 100644 --- a/Scripts/EntitySystem/BunnyGenerator.gd +++ b/Scripts/EntitySystem/BunnyGenerator.gd @@ -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 diff --git a/Scripts/GameManager.gd b/Scripts/GameManager.gd index a391bef..10cc48a 100644 --- a/Scripts/GameManager.gd +++ b/Scripts/GameManager.gd @@ -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()) diff --git a/Scripts/WeaponSystem/Projectile.gd b/Scripts/WeaponSystem/Projectile.gd index 345c8a6..ee4df99 100644 --- a/Scripts/WeaponSystem/Projectile.gd +++ b/Scripts/WeaponSystem/Projectile.gd @@ -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 -- 2.45.2 From 66ae4054c6e739843895e72931a4dda4efa66ee3 Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Sun, 23 Apr 2023 15:00:28 +0200 Subject: [PATCH 2/3] Adding Bunny Attackspeed and Basic Attack Logic --- Scripts/EntitySystem/Bunny.gd | 17 ++++++++++++++--- Scripts/EntitySystem/BunnyGenerator.gd | 13 +++++++------ Scripts/GameManager.gd | 2 +- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/Scripts/EntitySystem/Bunny.gd b/Scripts/EntitySystem/Bunny.gd index cf16778..5c55e3d 100644 --- a/Scripts/EntitySystem/Bunny.gd +++ b/Scripts/EntitySystem/Bunny.gd @@ -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 diff --git a/Scripts/EntitySystem/BunnyGenerator.gd b/Scripts/EntitySystem/BunnyGenerator.gd index d38e0e1..8a7a714 100644 --- a/Scripts/EntitySystem/BunnyGenerator.gd +++ b/Scripts/EntitySystem/BunnyGenerator.gd @@ -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 diff --git a/Scripts/GameManager.gd b/Scripts/GameManager.gd index 10cc48a..5c7dc16 100644 --- a/Scripts/GameManager.gd +++ b/Scripts/GameManager.gd @@ -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()) -- 2.45.2 From 2a9b0bbef0b6fccdfdc1a51fb49b9cf6cf9aac24 Mon Sep 17 00:00:00 2001 From: Snoweuph Date: Sun, 23 Apr 2023 15:21:22 +0200 Subject: [PATCH 3/3] Implement Player Taking Damage --- Assets/UI/Theme.tres | 4 ++-- Scenes/Game.tscn | 9 +++++---- Scenes/GameBunnyAnims.tscn | 4 ++-- Scenes/GamePauseTest.tscn | 4 ++-- Scenes/Test.tscn | 4 ++-- Scripts/EntitySystem/Bunny.gd | 20 +++++++++++--------- Scripts/EntitySystem/BunnyGenerator.gd | 1 - Scripts/GameManager.gd | 9 +++++++++ Scripts/{PlayerController.gd => Player.gd} | 11 +++++++++-- 9 files changed, 42 insertions(+), 24 deletions(-) rename Scripts/{PlayerController.gd => Player.gd} (89%) diff --git a/Assets/UI/Theme.tres b/Assets/UI/Theme.tres index 0508281..4c4b32b 100644 --- a/Assets/UI/Theme.tres +++ b/Assets/UI/Theme.tres @@ -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="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": 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", @@ -51,7 +51,7 @@ data = { } [sub_resource type="ImageTexture" id="ImageTexture_g5bup"] -image = SubResource("Image_iuu86") +image = SubResource("Image_dx2gc") [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_sj7h5"] diff --git a/Scenes/Game.tscn b/Scenes/Game.tscn index afd09ac..03f5582 100644 --- a/Scenes/Game.tscn +++ b/Scenes/Game.tscn @@ -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="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/EntitySystem/BunnyGenerator.gd" id="3_o045y"] [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="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="PackedScene" uid="uid://csxh42o8twxwn" path="res://Prefabs/projectile.tscn" id="8_fp1vx"] @@ -119,10 +119,11 @@ _data = { "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") map_generator = NodePath("Map Generator") bunny_generator = NodePath("Bunny Generator") +player = NodePath("Player") [node name="Map Generator" type="TileMap" parent="."] scale = Vector2(1.5, 1.5) @@ -141,7 +142,7 @@ player = NodePath("../Player") [node name="Player" type="CharacterBody2D" parent="." node_paths=PackedStringArray("animation_player")] position = Vector2(1440, 810) collision_layer = 0 -script = ExtResource("5_d2cbj") +script = ExtResource("6_q3xml") animation_player = NodePath("Player Animator") [node name="Player Sprite" type="Sprite2D" parent="Player"] diff --git a/Scenes/GameBunnyAnims.tscn b/Scenes/GameBunnyAnims.tscn index efe7362..5eefd45 100644 --- a/Scenes/GameBunnyAnims.tscn +++ b/Scenes/GameBunnyAnims.tscn @@ -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="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/EntitySystem/BunnyGenerator.gd" id="4_0by8r"] [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="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"] diff --git a/Scenes/GamePauseTest.tscn b/Scenes/GamePauseTest.tscn index ea52aa3..9c3bb0d 100644 --- a/Scenes/GamePauseTest.tscn +++ b/Scenes/GamePauseTest.tscn @@ -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="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/EntitySystem/BunnyGenerator.gd" id="4_38mjq"] [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="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"] diff --git a/Scenes/Test.tscn b/Scenes/Test.tscn index 55d7259..9ef9596 100644 --- a/Scenes/Test.tscn +++ b/Scenes/Test.tscn @@ -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="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="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="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"] diff --git a/Scripts/EntitySystem/Bunny.gd b/Scripts/EntitySystem/Bunny.gd index 5c55e3d..a027b43 100644 --- a/Scripts/EntitySystem/Bunny.gd +++ b/Scripts/EntitySystem/Bunny.gd @@ -14,7 +14,7 @@ var attack_speed : float var time_since_last_attack : float var team : int -var player : Node2D +var target : Node2D var on_death_callbacks : Array var move_velocity : Vector2 @@ -40,22 +40,24 @@ func _ready(): pass func _physics_process(delta : float): + if target == null: return + randomize() - if abs(player.velocity.length() - last_player_velocity) > 100.0: + if abs(target.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: + 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 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) 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 if agent.is_target_reachable(): 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 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 update_animation() if self.global_position.distance_to(next_location) < move_velocity.length(): @@ -70,18 +72,18 @@ func _physics_process(delta : float): time_since_got_player += delta time_since_got_move_location += delta time_since_last_attack += delta - last_player_velocity = player.velocity.length() + last_player_velocity = target.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") + target.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 + 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): diff --git a/Scripts/EntitySystem/BunnyGenerator.gd b/Scripts/EntitySystem/BunnyGenerator.gd index 8a7a714..f5b6d6f 100644 --- a/Scripts/EntitySystem/BunnyGenerator.gd +++ b/Scripts/EntitySystem/BunnyGenerator.gd @@ -14,7 +14,6 @@ func spawn_bunny(pos : Vector2, team : int, health : int, damage : int, attack_s 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, attack_speed : float) -> Array: diff --git a/Scripts/GameManager.gd b/Scripts/GameManager.gd index 5c7dc16..eff74b3 100644 --- a/Scripts/GameManager.gd +++ b/Scripts/GameManager.gd @@ -2,6 +2,7 @@ extends Node2D @export var map_generator : Node @export var bunny_generator : Node +@export var player : Node var bunnys = [] var gen_data : Dictionary @@ -20,6 +21,14 @@ func _process(_delta): 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.target = get_enemy_target(bunny.team) bunny.sub_on_death(func(bunny): bunny.queue_free()) in_wave_gen = false pass + +func get_enemy_target(own_team : int) -> Node: + match own_team: + TEAM.EVIL: return player + TEAM.GOOD: return null + _: return null + pass diff --git a/Scripts/PlayerController.gd b/Scripts/Player.gd similarity index 89% rename from Scripts/PlayerController.gd rename to Scripts/Player.gd index 6dc4630..90fa1d0 100644 --- a/Scripts/PlayerController.gd +++ b/Scripts/Player.gd @@ -1,7 +1,8 @@ extends CharacterBody2D -@export var speed = 200 -@export_range(0, 1) var damping_factor = 0.6 +@export var speed := 200.0 +@export var health := 100 +@export_range(0, 1) var damping_factor := 0.6 @export var animation_player : AnimationPlayer func _physics_process(delta : float): @@ -42,3 +43,9 @@ func update_player_animation(): up_dot: animation_player.play("MoveUp") down_dot: animation_player.play("MoveDown") pass + + +func damage(amount : int): + health -= amount + if(health <= 0): print("Player Dead") + pass -- 2.45.2