110 lines
2.7 KiB
GDScript
110 lines
2.7 KiB
GDScript
class_name GameController extends Node2D
|
|
|
|
# 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)
|
|
|
|
#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
|
|
|
|
|
|
# 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]
|
|
|
|
func secondCounter():
|
|
#print("tick")
|
|
countdown -=1
|
|
if countdown <=0:
|
|
print("LOSER")
|
|
LevelCompleteSignal.emit(levels[currentLevel])
|
|
|
|
# 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
|
|
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)
|
|
else:
|
|
print("dead")
|
|
|
|
func numberOfBadguys(value):
|
|
enemies = value
|