FebGame/febfabgame/Scripts/gamecontroller.gd

135 lines
3.4 KiB
GDScript3
Raw Normal View History

class_name GameController extends Node2D
2025-02-25 02:10:45 +00:00
# Game Data
var totalCrates = 4
var cratesDestroyed = 0
var coinsCollected = 0
var totalCoinsAvailable = 0
var enemies = 0
signal destroySignal(body)
signal LevelCompleteSignal(level)
signal playerHurtSignal(healthRemaining, maxHealth)
signal playerKillSignal
signal timerUpdateSignal(timeRemaining, totalTimeForLevel)
signal coinUpdateSignal(coinsCollectedTotal, coinsAvailableTotal)
#Level Info
var timer:= Timer.new()
var levels = ["res://Scenes/feb_fab_game.tscn","res://Scenes/feb_fab_game lv2.tscn","res://Scenes/feb_fab_game lv3.tscn"]
var timers = [20,15,25]
var currentLevel = 0
var countdown=0
var player:Resource
var slime:Resource
2025-02-25 02:10:45 +00:00
var enemiesDict={}
2025-02-25 02:10:45 +00:00
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
player = load("res://Scripts/res/playerStats.tres")
slime = load("res://Scripts/res/slimeStats.tres")
countdown = timers[currentLevel]
add_child(timer)
timer.wait_time = 1
timer.one_shot = false
timer.connect("timeout", secondCounter)
timer.start()
func reset():
countdown = timers[currentLevel]
player.health = player.max_health
coinsCollected = 0
func secondCounter():
#print("tick")
countdown -=1
timerUpdateSignal.emit(countdown, timers[currentLevel])
if countdown <=0:
print("LOSER")
LevelCompleteSignal.emit(levels[currentLevel])
2025-02-25 02:10:45 +00:00
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _on_trigger_area_trigger(effect, body) -> void:
print("Do effect "+effect)
match effect:
"destroy":
#write code to destroy
if body is Crate:
#%SceneManager.destroy(body)
destroySignal.emit(body)
cratesDestroyed +=1
"powerup":
#write code to powerup
if body is Player:
print("POWERRRRRR UP")
#Player.SPEED = 700
func bulletHit(body):
print("game controller knows bullet hit")
if body is Crate:
print("you've hit a crate")
totalCrates -=1
#%SceneManager.destroy(body)
destroySignal.emit(body)
print("crates Remaining :: "+str(totalCrates - cratesDestroyed))
if totalCrates <=0:
print("WIN")
currentLevel +=1
if currentLevel >= levels.size():
currentLevel = 0
LevelCompleteSignal.emit(levels[currentLevel])
func numberOfCrates(value):
totalCrates = value
print("Game Controller know scrates "+str(totalCrates))
func numberOfCoins(value):
totalCoinsAvailable = value
func coinCollected(body, coin):
print("GC knows coin collected")
if body is Player:
#increase coins collected count
coinsCollected +=1
coinUpdateSignal.emit(coinsCollected, totalCoinsAvailable)
print("total coins =" + str(coinsCollected))
destroySignal.emit(coin)
func playerDamage(body, badguy):
if body is Player:
print("GC knows player taking damage")
print("player health "+str(player.health)+"takes damage "+str(slime.meleeDamage))
player.health -= slime.meleeDamage
if player.health > 0:
playerHurtSignal.emit(player.health, player.max_health)
else:
playerKillSignal.emit()
print(enemiesDict[badguy]["health"])
func addBadGuy(enemy):
print("adding an enemy")
#use a dictionary
var enemyStats = {
"health": slime.health,
"damage": slime.meleeDamage
}
enemiesDict[enemy] = enemyStats
func numberOfBadguys(value):
enemies = value
func deathComplete():
print("GC knows death is complete")
LevelCompleteSignal.emit(levels[currentLevel])