Add resource reward after killing enemy

This commit is contained in:
Moe Poi ~ 2023-10-07 22:39:23 +07:00
parent 85c09ac63f
commit f0920ce37d
3 changed files with 32 additions and 13 deletions

View file

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

View file

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

View file

@ -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'])