86 lines
1.5 KiB
GDScript
86 lines
1.5 KiB
GDScript
@tool
|
|
extends Node
|
|
## Game
|
|
|
|
|
|
signal cube_integrity_changed
|
|
signal money_changed
|
|
signal loose
|
|
signal allowed_tower_has_change
|
|
|
|
|
|
var towerPackedScenes : Dictionary
|
|
var enmies : Dictionary
|
|
var towers : Dictionary
|
|
|
|
|
|
var max_health : int = 50
|
|
var health : int = max_health :
|
|
set(value):
|
|
health = value
|
|
cube_integrity_changed.emit()
|
|
if health <= 0:
|
|
death()
|
|
|
|
|
|
var money : int = 0:
|
|
set(value):
|
|
money = value
|
|
money_changed.emit()
|
|
|
|
|
|
func _ready() -> void:
|
|
process_mode = Node.PROCESS_MODE_ALWAYS
|
|
EventBus.player_has_won.connect(win)
|
|
Helper.preloadSceneInGlobal(towerPackedScenes, Helper.RESOURCE_TYPE.TOWER)
|
|
#Helper.preloadSceneInGlobal(towerPackedScenes, Helper.RESOURCE_TYPE.ENEMY)
|
|
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if Engine.is_editor_hint():
|
|
return
|
|
|
|
if event.is_action_pressed("pause_game"):
|
|
get_tree().paused = not get_tree().paused
|
|
|
|
|
|
func initTowers(allowedTowers : Array[Tower.TYPE]) -> void:
|
|
towers.clear()
|
|
for towerType in allowedTowers:
|
|
var tower : Tower = towerPackedScenes.get(towerType).instantiate()
|
|
towers.set(towerType, tower)
|
|
|
|
allowed_tower_has_change.emit()
|
|
|
|
|
|
func resetGame() -> void:
|
|
initTowers([])
|
|
money = 0
|
|
health = max_health
|
|
|
|
|
|
func win():
|
|
Transition.goto("res://UI/win_screen.tscn")
|
|
resetGame()
|
|
|
|
|
|
func quitLevel() -> void:
|
|
Transition.goto("res://UI/start_menu.tscn")
|
|
resetGame()
|
|
|
|
|
|
func quitGame() -> void:
|
|
get_tree().quit()
|
|
|
|
|
|
func spendMoney(amount : int) -> bool:
|
|
if money >= amount:
|
|
money -= amount
|
|
return true
|
|
return false
|
|
|
|
|
|
func death():
|
|
loose.emit()
|
|
Transition.goto("res://UI/defeat_screen.tscn")
|
|
resetGame()
|