bad guy movement, player death, ui with health, timer, coins, added a dictionary for bad guys
This commit is contained in:
1 parent
31d586b386
commit
c111513980
18 files changed
+466
-52
No files matched your search
@@ -10,7 +10,11 @@ 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()
|
||||
var levels = ["res://scenes/game.tscn","res://scenes/level2.tscn","res://scenes/level3.tscn"]
|
||||
@@ -21,6 +25,8 @@ 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:
|
||||
player = load("res://scripts/res/playerStats.tres")
|
||||
@@ -34,9 +40,12 @@ func _ready() -> void:
|
||||
timer.start()
|
||||
func reset():
|
||||
countdown = timers[currentLevel]
|
||||
player.health = player.max_health
|
||||
coinsCollected = 0
|
||||
|
||||
func secondCounter():
|
||||
countdown -=1
|
||||
timerUpdateSignal.emit(countdown, timers[currentLevel])
|
||||
if countdown <=0:
|
||||
print("YOU LOSE")
|
||||
levelCompleteSignal.emit(levels[currentLevel])
|
||||
@@ -82,17 +91,31 @@ func coinCollected(body, coin):
|
||||
if body is Player:
|
||||
#increase coins collected count
|
||||
coinsCollected +=1
|
||||
coinUpdateSignal.emit(coinsCollected, totalCoinsAvailable)
|
||||
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
|
||||
player.health -= enemiesDict[badguy]["damage"]
|
||||
if player.health > 0:
|
||||
playerHurtSignal.emit(player.health)
|
||||
playerHurtSignal.emit(player.health, player.max_health)
|
||||
else:
|
||||
print("kill em")
|
||||
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])
|
||||
@@ -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":
|
||||
@@ -99,8 +101,14 @@ func hurtPlayer(health):
|
||||
print("Player takes damage, health remaining:: "+str(health))
|
||||
animPlaying = "hurt"
|
||||
playerGraphic.play(animPlaying)
|
||||
|
||||
func killPlayer():
|
||||
print("Kill the player")
|
||||
living = false
|
||||
animPlaying="death"
|
||||
playerGraphic.play(animPlaying)
|
||||
|
||||
func _on_animation_finished() -> void:
|
||||
if animPlaying=="hurt":
|
||||
animPlaying=="idle"
|
||||
animPlaying="idle"
|
||||
if animPlaying=="death":
|
||||
deathCompleteSignal.emit()
|
||||
@@ -7,5 +7,5 @@ script = ExtResource("1_ev6pb")
|
||||
max_health = 50
|
||||
starting_health = 50
|
||||
health = 50
|
||||
meleeDamage = 30
|
||||
meleeDamage = 5
|
||||
rangeDamage = 0
|
||||
@@ -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"
|
||||
|
||||
var bulletsFiredTotal = 0
|
||||
var bulletsMadeTotal = 0
|
||||
@@ -66,6 +67,7 @@ func buildLevel():
|
||||
if obj is Slime:
|
||||
totalBadguys +=1
|
||||
obj.playerDamageSignal.connect(Gamecontroller.playerDamage)
|
||||
Gamecontroller.addBadGuy(obj)
|
||||
Gamecontroller.numberOfBadguys(totalBadguys)
|
||||
#wire up the triggers
|
||||
for obj in triggers.get_children():
|
||||
@@ -77,6 +79,12 @@ 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)
|
||||
@@ -84,5 +92,7 @@ func loadLevel(level):
|
||||
func _ready() -> void:
|
||||
buildLevel()
|
||||
Gamecontroller.reset()
|
||||
func playerHurt(health):
|
||||
func playerHurt(health, _maxHealth):
|
||||
player.hurtPlayer(health)
|
||||
func playerKill():
|
||||
player.killPlayer()
|
||||
@@ -1,7 +1,31 @@
|
||||
class_name Slime extends Area2D
|
||||
|
||||
signal playerDamageSignal
|
||||
@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:
|
||||
print("Bad guy contact")
|
||||
playerDamageSignal.emit(body, self)
|
||||
@@ -0,0 +1,24 @@
|
||||
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):
|
||||
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