From f0920ce37dfb488444748739d52d534d7f7f9774 Mon Sep 17 00:00:00 2001 From: Moe Poi ~ Date: Sat, 7 Oct 2023 22:39:23 +0700 Subject: [PATCH] Add resource reward after killing enemy --- scripts/enemies/enemy.gd | 5 ++++- scripts/stages/1/config.gd | 36 +++++++++++++++++++++----------- scripts/stages/1/game_manager.gd | 4 ++++ 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/scripts/enemies/enemy.gd b/scripts/enemies/enemy.gd index 2b7a68b..0f57b49 100644 --- a/scripts/enemies/enemy.gd +++ b/scripts/enemies/enemy.gd @@ -5,6 +5,7 @@ var enemy_id: int = 0 var health: int = 0 var damage: int = 0 var speed: int = 0 +var reward: int = 0 var direction_progress = [] var direction = [] @@ -16,6 +17,7 @@ func set_enemy(id: int): health = config.enemy[enemy_id]['health'] damage = config.enemy[enemy_id]['damage'] speed = config.enemy[enemy_id]['speed'] + reward = config.enemy[enemy_id]['reward'] func set_direction(): var path_direction = config.game['path_direction'] @@ -26,7 +28,8 @@ func set_direction(): func _process(delta): update_healthbar() change_direction(get_progress()) - if health <= 0: + if health < 1: + get_tree().current_scene.on_enemy_reward(reward) queue_free() set_progress(get_progress() + speed * delta) diff --git a/scripts/stages/1/config.gd b/scripts/stages/1/config.gd index 151abf6..2ccc77d 100644 --- a/scripts/stages/1/config.gd +++ b/scripts/stages/1/config.gd @@ -68,42 +68,48 @@ var tower = [ "asset": preload("res://scenes/towers/cannon_1.tscn"), "timer": 0.2, "speed": 200, - "damage": 30 + "damage": 30, + "health": 100 }, { "name": "Railgun", "asset": preload("res://scenes/towers/railgun_1.tscn"), "timer": 0.2, "speed": 200, - "damage": 40 + "damage": 40, + "health": 100 }, { "name": "Cannon (V2)", "asset": preload("res://scenes/towers/cannon_2.tscn"), "timer": 0.2, "speed": 200, - "damage": 40 + "damage": 40, + "health": 100 }, { "name": "Railgun (V2)", "asset": preload("res://scenes/towers/railgun_2.tscn"), "timer": 0.2, "speed": 200, - "damage": 40 + "damage": 40, + "health": 100 }, { "name": "Cannon (V3)", "asset": preload("res://scenes/towers/cannon_3.tscn"), "timer": 0.2, "speed": 200, - "damage": 40 + "damage": 40, + "health": 100 }, { "name": "Railgun (V3)", "asset": preload("res://scenes/towers/railgun_3.tscn"), "timer": 0.2, "speed": 200, - "damage": 40 + "damage": 40, + "health": 100 } ] @@ -112,36 +118,42 @@ var enemy = [ "name": "Demon", "health": 100, "speed": 30, - "damage": 1 + "damage": 1, + "reward": 10 }, { "name": "Orc", "health": 100, "speed": 30, - "damage": 1 + "damage": 1, + "reward": 20 }, { "name": "Cyclops", "health": 100, "speed": 30, - "damage": 1 + "damage": 1, + "reward": 30 }, { "name": "Demon Boar", "health": 100, "speed": 30, - "damage": 1 + "damage": 1, + "reward": 40 }, { "name": "Demon Fungus", "health": 100, "speed": 30, - "damage": 1 + "damage": 1, + "reward": 50 }, { "name": "Demon Shark", "health": 100, "speed": 30, - "damage": 1 + "damage": 1, + "reward": 60 } ] diff --git a/scripts/stages/1/game_manager.gd b/scripts/stages/1/game_manager.gd index 368019a..f7b6de6 100644 --- a/scripts/stages/1/game_manager.gd +++ b/scripts/stages/1/game_manager.gd @@ -66,3 +66,7 @@ func on_enemy_entered_base(enemy): if data['health'] < 1: print("Game Over") + +func on_enemy_reward(value: int): + data['resource'] += value + $CanvasLayer/GameStats.set_resource(data['resource'])