JanGodotGame/scripts/gameController.gd

98 lines
2.0 KiB
GDScript3
Raw Normal View History

2025-01-07 01:34:02 +00:00
extends Node2D
2025-01-07 01:51:49 +00:00
var timer:= Timer.new()
2025-02-04 02:03:41 +00:00
var secondCount= 99
2025-01-21 01:44:35 +00:00
var totalCrates := 0
2025-02-04 02:03:41 +00:00
var totalCoins := 0
var totalBadGuys := 0
var totalCoinsCollected := 0
2025-02-04 02:03:41 +00:00
var cratesDestroyed := 0
2025-02-04 02:03:41 +00:00
var player:Resource
2025-02-04 02:03:41 +00:00
# level info
var levels = ["res://scenes/game.tscn", "res://scenes/level2.tscn"]
2025-02-11 00:19:43 +00:00
var timers = [90, 90]
2025-02-04 02:03:41 +00:00
var currentLevel = 0
2025-01-21 01:44:35 +00:00
2025-02-04 02:03:41 +00:00
#Gamecontroller signals
signal destroyBox(body)
signal levelComplete(leveltoLoad)
2025-02-11 00:19:43 +00:00
signal playerHurt(amt)
signal playerDeath()
2025-01-07 01:34:02 +00:00
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
2025-02-04 02:03:41 +00:00
player = load("res://scripts/res/playerstats.tres")
print("Player Health: "+str(player.health))
2025-02-04 02:03:41 +00:00
print("Number of levels: "+str(levels.size()))
2025-01-07 01:51:49 +00:00
add_child(timer)
timer.wait_time = 1
timer.one_shot = false
timer.connect("timeout", secondCounter)
timer.start()
2025-02-11 00:19:43 +00:00
2025-02-04 02:03:41 +00:00
func reset():
secondCount = timers[currentLevel]
2025-02-11 00:19:43 +00:00
player.health = player.starting_health
2025-01-07 01:34:02 +00:00
2025-01-07 01:51:49 +00:00
func secondCounter():
print("time left: ", secondCount)
secondCount -=1
if secondCount <= 0:
2025-02-04 02:03:41 +00:00
print("TIME IS UP")
levelComplete.emit(levels[currentLevel])
2025-01-07 01:34:02 +00:00
2025-02-11 00:19:43 +00:00
2025-02-04 02:03:41 +00:00
func playerDamaged():
print("GC knows player took damage")
2025-02-11 00:19:43 +00:00
player.health = max(player.health-20, 0)
2025-02-04 02:03:41 +00:00
print("Player Health: "+str(player.health))
2025-02-11 00:19:43 +00:00
if player.health > 0:
playerHurt.emit(player.health)
else:
playerDeath.emit()
2025-02-04 02:03:41 +00:00
func coinCollected():
totalCoinsCollected += 1
print("DING! Coins collected: "+ str(totalCoinsCollected) )
2025-02-11 00:19:43 +00:00
2025-01-21 01:44:35 +00:00
func bulletHit(body):
print("Game controller knows bullet hit something")
if body.is_in_group("destructables"):
destroyBox.emit(body)
2025-02-04 02:03:41 +00:00
totalCrates -= 1
cratesDestroyed += 1
if totalCrates <=0:
print("You Won...")
currentLevel +=1
if currentLevel >= levels.size():
currentLevel = 0
levelComplete.emit(levels[currentLevel])
else:
print("Crates Remaining: "+str(totalCrates) )
2025-02-11 00:19:43 +00:00
2025-02-04 02:03:41 +00:00
# Coming from scenemanager
2025-01-21 01:44:35 +00:00
func countCrates(value):
totalCrates = value
2025-02-11 00:19:43 +00:00
2025-02-04 02:03:41 +00:00
func countCoins(value):
totalCoins = value
2025-02-11 00:19:43 +00:00
2025-02-04 02:03:41 +00:00
func countBadGuys(value):
totalBadGuys = value
2025-02-11 00:19:43 +00:00
func playerDead():
print("GC knows player is dead")
levelComplete.emit(levels[currentLevel])