bad guy mvmnt, player death, UI with health, timer, and coins, and we started looking into adding a dictionary for bad guys
This commit is contained in:
1 parent
9ceb59f89f
commit
3943a4c1a3
17 files changed
+386
-11
No files matched your search
@@ -20,6 +20,8 @@ var isJumping = false
|
||||
var animPlaying = "idle"
|
||||
var living = true
|
||||
|
||||
signal deathCompleteSignal
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if living and not animPlaying == "hurt":
|
||||
# Add the gravity.
|
||||
@@ -106,8 +108,16 @@ func hurtPlayer(health):
|
||||
print("Player takes damage, health remaining::"+str(health))
|
||||
animPlaying = "hurt"
|
||||
playerGraphic.play(animPlaying)
|
||||
func killPlayer():
|
||||
print("KILL")
|
||||
living = false
|
||||
animPlaying = "death"
|
||||
playerGraphic.play(animPlaying)
|
||||
|
||||
|
||||
|
||||
func _on_animated_finished() -> void:
|
||||
if animPlaying == "hurt":
|
||||
animPlaying=="idle"
|
||||
animPlaying = "idle"
|
||||
if animPlaying == "death":
|
||||
deathCompleteSignal.emit()
|
||||
@@ -9,7 +9,10 @@ var enemies = 0
|
||||
|
||||
signal destroySignal(body)
|
||||
signal LevelCompleteSignal(level)
|
||||
signal playerHurtSignal(healthRemaining)
|
||||
signal playerHurtSignal(healthRemaining, maxHealth)
|
||||
signal playerKillSignal
|
||||
signal timerUpdateSignal(timeRemaining, totalTimeForLevel)
|
||||
signal coinUpdateSignal(coinsCollectedTotal, coinsAvailableTotal)
|
||||
|
||||
#Level Info
|
||||
var timer:= Timer.new()
|
||||
@@ -21,6 +24,7 @@ var countdown=0
|
||||
var player:Resource
|
||||
var slime:Resource
|
||||
|
||||
var enemiesDict={}
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
@@ -33,12 +37,17 @@ func _ready() -> void:
|
||||
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])
|
||||
@@ -92,8 +101,10 @@ func coinCollected(body, coin):
|
||||
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:
|
||||
@@ -101,9 +112,23 @@ func playerDamage(body, badguy):
|
||||
print("player health "+str(player.health)+"takes damage "+str(slime.meleeDamage))
|
||||
player.health -= slime.meleeDamage
|
||||
if player.health > 0:
|
||||
playerHurtSignal.emit(player.health)
|
||||
playerHurtSignal.emit(player.health, player.max_health)
|
||||
else:
|
||||
print("dead")
|
||||
|
||||
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])
|
||||
@@ -5,6 +5,7 @@ extends Node
|
||||
@onready var coins: Node2D = $"../coins"
|
||||
@onready var badguys: Node2D = $"../badguys"
|
||||
@onready var player: Player = $"../CharacterBody2D"
|
||||
@onready var ui: Control = $"../CanvasLayer/UI"
|
||||
|
||||
|
||||
|
||||
@@ -71,6 +72,7 @@ func buildLevel():
|
||||
if obj is Slime:
|
||||
totalBadguys +=1
|
||||
obj.playerDamagSignal.connect(Gamecontroller.playerDamage)
|
||||
Gamecontroller.addBadGuy(obj)
|
||||
Gamecontroller.numberOfBadguys(totalBadguys)
|
||||
|
||||
#wire up the triggers
|
||||
@@ -84,6 +86,13 @@ func buildLevel():
|
||||
Gamecontroller.destroySignal.connect(destroy)
|
||||
Gamecontroller.LevelCompleteSignal.connect(loadLevel)
|
||||
Gamecontroller.playerHurtSignal.connect(playerHurt)
|
||||
Gamecontroller.playerHurtSignal.connect(ui.healthUpdate)
|
||||
Gamecontroller.playerKillSignal.connect(playerKill)
|
||||
Gamecontroller.timerUpdateSignal.connect(ui.timerUpdate)
|
||||
Gamecontroller.coinUpdateSignal.connect(ui.coinsUpdate)
|
||||
|
||||
#listen to player
|
||||
player.deathCompleteSignal.connect(Gamecontroller.deathComplete)
|
||||
|
||||
func loadLevel(level):
|
||||
get_tree().change_scene_to_file(level)
|
||||
@@ -92,5 +101,8 @@ func _ready() -> void:
|
||||
buildLevel()
|
||||
Gamecontroller.reset()
|
||||
|
||||
func playerHurt(health):
|
||||
func playerHurt(health, _maxHealth):
|
||||
player.hurtPlayer(health)
|
||||
|
||||
func playerKill():
|
||||
player.killPlayer()
|
||||
@@ -1,8 +1,33 @@
|
||||
class_name Slime extends Area2D
|
||||
|
||||
signal playerDamagSignal
|
||||
@onready var right_cast: RayCast2D = $rightCast
|
||||
@onready var left_cast: RayCast2D = $leftCast
|
||||
@onready var right_cast_floor: RayCast2D = $rightCastFloor
|
||||
@onready var left_cast_floor: RayCast2D = $leftCastFloor
|
||||
|
||||
|
||||
var speed = 100
|
||||
var direction = 1
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if not right_cast_floor.is_colliding():
|
||||
direction = -1
|
||||
if not left_cast_floor.is_colliding():
|
||||
direction = 1
|
||||
|
||||
|
||||
if right_cast.is_colliding():
|
||||
var body = right_cast.get_collider()
|
||||
if not body is Player:
|
||||
direction = -1
|
||||
if left_cast.is_colliding():
|
||||
var body = left_cast.get_collider()
|
||||
if not body is Player:
|
||||
direction = 1
|
||||
|
||||
position.x += direction*speed*delta
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
playerDamagSignal.emit(body, self)
|
||||
print("bad guy yum yum")
|
||||
@@ -0,0 +1,26 @@
|
||||
extends Control
|
||||
|
||||
@onready var timer: Label = $VBoxContainer/HBoxContainer/MarginContainer2/timer
|
||||
@onready var coins: Label = $VBoxContainer/HBoxContainer/MarginContainer3/coins
|
||||
@onready var health: Label = $VBoxContainer/HBoxContainer/MarginContainer/VBoxContainer/health
|
||||
@onready var health_progress: ProgressBar = $VBoxContainer/HBoxContainer/MarginContainer/VBoxContainer/healthProgress
|
||||
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
health.text="HEALTH"
|
||||
timer.text="TIMER"
|
||||
coins.text="COINS"
|
||||
|
||||
func healthUpdate(currentHealth, maxHealth):
|
||||
print( float(currentHealth) / maxHealth* 100)
|
||||
health.text = "Health: "+str(currentHealth)+" of "+str(maxHealth)
|
||||
health_progress.value = (float(currentHealth) / maxHealth* 100)
|
||||
|
||||
func timerUpdate(timeRemaining, _timeAvailable):
|
||||
#print(timeRemaining, _timeAvailable)
|
||||
timer.text= "Time: "+str(timeRemaining)
|
||||
func coinsUpdate(coinsCollected, CoinsAvailable):
|
||||
print(coinsCollected, CoinsAvailable)
|
||||
coins.text ="coins: "+str(coinsCollected)+" of "+str(CoinsAvailable)
|
||||
Reference in new issue
Block a user