add ui and prettify
This commit is contained in:
1 parent
f31033dd59
commit
d08cfff850
8 files changed
+145
-8
No files matched your search
@@ -22,7 +22,7 @@ var bullet = preload("res://scenes/bullet.tscn")
|
||||
var isJumping = false
|
||||
|
||||
var living = true
|
||||
var animPlaying = "idle"
|
||||
var animPlaying = "playerIdle"
|
||||
|
||||
signal deathAnimDone
|
||||
|
||||
|
||||
@@ -18,9 +18,12 @@ var currentLevel = 0
|
||||
#Gamecontroller signals
|
||||
signal destroyBox(body)
|
||||
signal levelComplete(leveltoLoad)
|
||||
signal playerHurt(amt)
|
||||
signal playerHurt(amt, max)
|
||||
signal playerDeath()
|
||||
|
||||
signal tick(timeRemaining)
|
||||
signal coinsUpdate(collected, remaining)
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
player = load("res://scripts/res/playerstats.tres")
|
||||
@@ -33,14 +36,22 @@ func _ready() -> void:
|
||||
timer.start()
|
||||
|
||||
|
||||
|
||||
func reset():
|
||||
secondCount = timers[currentLevel]
|
||||
player.health = player.starting_health
|
||||
playerHurt.emit.call_deferred(player.health, player.max_health)
|
||||
tick.emit.call_deferred(secondCount)
|
||||
totalCoinsCollected = 0
|
||||
coinsUpdate.emit.call_deferred(totalCoinsCollected, totalCoins)
|
||||
|
||||
|
||||
|
||||
|
||||
func secondCounter():
|
||||
print("time left: ", secondCount)
|
||||
secondCount -=1
|
||||
tick.emit(secondCount)
|
||||
if secondCount <= 0:
|
||||
print("TIME IS UP")
|
||||
levelComplete.emit(levels[currentLevel])
|
||||
@@ -50,9 +61,9 @@ func playerDamaged():
|
||||
print("GC knows player took damage")
|
||||
player.health = max(player.health-20, 0)
|
||||
print("Player Health: "+str(player.health))
|
||||
if player.health > 0:
|
||||
playerHurt.emit(player.health)
|
||||
else:
|
||||
playerHurt.emit(player.health, player.max_health)
|
||||
|
||||
if player.health <= 0:
|
||||
playerDeath.emit()
|
||||
|
||||
|
||||
@@ -60,6 +71,7 @@ func playerDamaged():
|
||||
func coinCollected():
|
||||
totalCoinsCollected += 1
|
||||
print("DING! Coins collected: "+ str(totalCoinsCollected) )
|
||||
coinsUpdate.emit(totalCoinsCollected, totalCoins)
|
||||
|
||||
|
||||
func bulletHit(body):
|
||||
|
||||
@@ -6,6 +6,7 @@ extends Node
|
||||
@onready var enemies: Node2D = $"../enemies"
|
||||
|
||||
@onready var player: CharacterBody2D = $"../CharacterBody2D"
|
||||
@onready var ui: Control = $"../CanvasLayer/ui"
|
||||
|
||||
var theBullet = preload("res://scenes/bullet.tscn")
|
||||
var bulletArray:Array = []
|
||||
@@ -42,6 +43,11 @@ func _ready() -> void:
|
||||
# Subscribe to signals
|
||||
GameController.levelComplete.connect(changeLevel)
|
||||
player.deathAnimDone.connect(GameController.playerDead)
|
||||
|
||||
GameController.tick.connect(ui.timerUpdate)
|
||||
GameController.playerHurt.connect(ui.healthUpdate, ConnectFlags.CONNECT_DEFERRED)
|
||||
GameController.coinsUpdate.connect(ui.coinsUpdate)
|
||||
|
||||
GameController.reset()
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
extends Control
|
||||
|
||||
@onready var timer: Label = $VBoxContainer/HBoxContainer/MarginContainer3/timer
|
||||
@onready var health: Label = $VBoxContainer/HBoxContainer/MarginContainer/health
|
||||
@onready var coins: Label = $VBoxContainer/HBoxContainer/MarginContainer2/coins
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
|
||||
func timerUpdate(timeRemaining):
|
||||
if timeRemaining <= 0:
|
||||
timer.text = "OUT OF TIME"
|
||||
else:
|
||||
timer.text = "🕔: "+str(timeRemaining)
|
||||
|
||||
|
||||
func healthUpdate(healthRemaining, healthMax):
|
||||
if healthRemaining <= 0:
|
||||
health.text = " 💀 💀 💀 💀 "
|
||||
else:
|
||||
health.text = (" ❤️: "+str(healthRemaining)+"/"+str(healthMax))
|
||||
|
||||
|
||||
func coinsUpdate(collected, remaining):
|
||||
coins.text = ("🪙: "+str(collected)+"/"+str(remaining)+" ")
|
||||
Reference in new issue
Block a user