JeremyGodot/scripts/gamecontroller.gd

58 lines
1.3 KiB
GDScript3
Raw Normal View History

2024-08-13 01:10:25 +00:00
extends Node
2024-07-29 22:14:14 +00:00
2024-07-30 01:03:42 +00:00
var myBox = preload("res://scenes/crate.tscn")
2024-08-13 01:10:25 +00:00
@onready var box_trap = $"../BoxTrap"
@onready var timer = $Timer
@onready var player = $"../CharacterBody2D"
2024-08-20 01:11:17 +00:00
@onready var coins = $"../Coins"
@onready var enemies = $"../enemies"
@onready var ui = $"../CanvasLayer/UI"
2024-08-13 01:10:25 +00:00
2024-07-29 22:14:14 +00:00
# Called when the node enters the scene tree for the first time.
func _ready():
2024-08-20 01:11:17 +00:00
GameManager.resetPlayer()
for n in coins.get_children():
if n is Coin:
#wire up our listener
n.coinCollected.connect(_on_coin_coin_collected)
for n in enemies.get_children():
if n is BadGuy:
n.playerDamage.connect(playerDamage)
2024-07-29 22:14:14 +00:00
func _process(delta):
2024-08-20 01:11:17 +00:00
if GameManager.player.health <= 0 && player.living:
player.die()
2024-07-29 22:14:14 +00:00
2024-07-30 01:03:42 +00:00
func _on_area_2d_areatrigger(effect, body):
print("Game Controller sees the trigger" +effect )
match effect:
"alert":
#do stuff
print("hi")
if body.is_in_group("player"):
for n in 3:
var box = myBox.instantiate()
2024-08-13 01:10:25 +00:00
owner.add_child(box)
2024-07-30 01:03:42 +00:00
box.position = box_trap.position
"powerup":
print("you got power")
2024-08-13 01:10:25 +00:00
func resetWorld():
get_tree().reload_current_scene()
2024-08-20 01:11:17 +00:00
func _on_coin_coin_collected():
GameManager.coinCollected()
ui.coinUpdate(GameManager.coinCollectedTotal)
func playerDamage():
GameManager.playerDamage()
ui.healthUpdate(GameManager.player.health)
func _on_death_complete():
#This is where we reset the world
timer.start(.5)