JanuaryGame/GodotProject/scripts/gamecontroller.gd

75 lines
1.8 KiB
GDScript3
Raw Normal View History

extends Node2D
var timer:= Timer.new()
var countdown = 10
2025-02-04 02:02:52 +00:00
var totalCrates := 0
var cratesDestroyed := 0
var totalCoins := 0
var totalCoinsCollected := 0
2025-01-21 01:44:30 +00:00
2025-02-04 02:02:52 +00:00
var totalEnemies := 0
#level information
var levels = ["res://scenes/game.tscn","res://scenes/level2.tscn"]
var timers = [10,15]
var currentLevel = 0
2025-01-21 01:44:30 +00:00
2025-02-04 02:02:52 +00:00
var player:Resource
# signals from game controller
signal destroyBox(body)
signal levelComplete(levelToLoad)
# Called when the node enters the scene tree for the first time.
func _ready():
2025-02-04 02:02:52 +00:00
player = load("res://scripts/res/playerstats.tres")
print("Player health: "+str(player.health))
print("Number of levels: "+str(levels.size()))
reset()
add_child(timer)
timer.wait_time = 1
timer.one_shot = false
timer.connect("timeout", secondCounter)
2025-02-04 02:02:52 +00:00
timer.start()
2025-02-04 02:02:52 +00:00
func reset():
countdown = timers[currentLevel]
func secondCounter():
countdown -=1
2025-02-04 02:02:52 +00:00
print("minus one")
if countdown <=0:
print("you lose")
2025-02-04 02:02:52 +00:00
levelComplete.emit(levels[currentLevel])
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
2025-02-04 02:02:52 +00:00
func coinCollected():
print("gane cotroller knows coin collected")
totalCoinsCollected+=1
func playerDamaged():
player.health -= 20
print("game controller knows player damaged, health is now "+str(player.health))
2025-01-14 01:58:52 +00:00
func bulletHit(body):
print("game controller knows bullet hit something")
if body.is_in_group("destructable"):
2025-01-21 01:44:30 +00:00
destroyBox.emit(body)
2025-02-04 02:02:52 +00:00
totalCrates -=1
cratesDestroyed +=1
body.queue_free()
if totalCrates <=0:
print("you won")
#refactor this --make it a single
currentLevel +=1
if currentLevel >= levels.size():
currentLevel = 0
levelComplete.emit(levels[currentLevel])
else:
print("crates remaining: "+str(totalCrates))
# scene manager stuff
func countCrates(value):
2025-01-21 01:44:30 +00:00
totalCrates = value
2025-02-04 02:02:52 +00:00
func countCoins(value):
totalCoins = value