multi levels, timer, health, coins
This commit is contained in:
1 parent
a5f092f125
commit
c4af95fa6b
11 files changed
+687
-28
No files matched your search
@@ -9,6 +9,7 @@ const PUSHFORCE = 750
|
||||
@onready var right_ray: RayCast2D = $RightRay
|
||||
@onready var left_ray: RayCast2D = $LeftRay
|
||||
@onready var playerSprite: AnimatedSprite2D = $AnimatedSprite2D
|
||||
@onready var gun: Sprite2D = $Gun
|
||||
|
||||
var faceLeft = false
|
||||
|
||||
@@ -26,7 +27,6 @@ signal playerDead
|
||||
@onready var left_target: Node2D = $LeftTarget
|
||||
|
||||
func hurtPlayer(amt):
|
||||
print("Character knows it should be hurt")
|
||||
animPlaying = "hurt"
|
||||
playerSprite.play("hurt")
|
||||
|
||||
@@ -35,6 +35,12 @@ func killPlayer():
|
||||
living = false
|
||||
animPlaying = "death"
|
||||
playerSprite.play(animPlaying)
|
||||
func gunCollected():
|
||||
print("Player knows to show gun")
|
||||
gun.visible = true
|
||||
|
||||
func gunDrop():
|
||||
gun.visible = false
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if living and not animPlaying =="hurt":
|
||||
@@ -50,7 +56,6 @@ func _physics_process(delta: float) -> void:
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
var direction := Input.get_axis("ui_left", "ui_right")
|
||||
if Input.is_action_just_pressed("shove") && pushRightEnabled && faceLeft == false:
|
||||
print("Shove a box")
|
||||
pushTarget.apply_central_impulse(Vector2(1,0) * PUSHFORCE * 2 )
|
||||
pushRightEnabled = false
|
||||
|
||||
@@ -59,7 +64,6 @@ func _physics_process(delta: float) -> void:
|
||||
pushLeftEnabled = false
|
||||
|
||||
if Input.is_action_just_pressed("shoot"):
|
||||
print("Shoot a bullet")
|
||||
var myBullet = %SceneManager.bulletFactory()
|
||||
if not faceLeft:
|
||||
myBullet.transform = right_target.global_transform
|
||||
@@ -96,7 +100,6 @@ func _physics_process(delta: float) -> void:
|
||||
|
||||
move_and_slide()
|
||||
if right_ray.is_colliding():
|
||||
print("Something is on my right")
|
||||
if not faceLeft:
|
||||
var collider = right_ray.get_collider()
|
||||
if collider is Node:
|
||||
|
||||
@@ -2,22 +2,49 @@ extends Node
|
||||
|
||||
var coinsCollected:int = 0
|
||||
var player:Resource
|
||||
var totalCoinsLevel = 0
|
||||
var levels = ["res://scenes/game.tscn","res://scenes/game_level2.tscn"]
|
||||
var timers = [5, 30]
|
||||
var currentLevel = 0
|
||||
|
||||
var gameSeconds = 0
|
||||
|
||||
var gotGun = false
|
||||
|
||||
signal playerHurt(amt)
|
||||
signal playerDeath()
|
||||
signal coinsUpdate(amt, total)
|
||||
signal levelComplete(level)
|
||||
signal tick(seconds)
|
||||
signal playerOptions(gun)
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
player = load("res://scripts/res/playerstats.tres")
|
||||
|
||||
|
||||
func setTotalCoins(amt):
|
||||
totalCoinsLevel = amt
|
||||
print(str(coinsCollected)+" "+str(totalCoinsLevel) )
|
||||
coinsUpdate.emit(coinsCollected, totalCoinsLevel)
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func gunCollected():
|
||||
gotGun = true
|
||||
|
||||
func coinCollected():
|
||||
coinsCollected +=1
|
||||
print("Total coins collected "+str(coinsCollected) )
|
||||
coinsUpdate.emit(coinsCollected, totalCoinsLevel)
|
||||
#did you complete the level
|
||||
if coinsCollected >= totalCoinsLevel:
|
||||
#level complete
|
||||
currentLevel +=1
|
||||
if currentLevel < levels.size():
|
||||
levelComplete.emit(levels[currentLevel])
|
||||
else:
|
||||
currentLevel = 0
|
||||
levelComplete.emit(levels[currentLevel])
|
||||
|
||||
func playerDamage():
|
||||
if player.health > 0:
|
||||
@@ -27,8 +54,19 @@ func playerDamage():
|
||||
playerDeath.emit()
|
||||
else:
|
||||
## damage him
|
||||
playerHurt.emit(20)
|
||||
playerHurt.emit(player.health)
|
||||
func reset():
|
||||
gameSeconds = 0
|
||||
player.health = player.max_health
|
||||
coinsCollected = 0
|
||||
|
||||
|
||||
func timeOut():
|
||||
gameSeconds +=1
|
||||
if gameSeconds >= timers[currentLevel]:
|
||||
playerDeath.emit()
|
||||
tick.emit(timers[currentLevel] - gameSeconds)
|
||||
|
||||
func sendOptions():
|
||||
playerOptions.emit(gotGun)
|
||||
|
||||
@@ -3,29 +3,57 @@ extends Node
|
||||
var bulletsFiredTotal :=0
|
||||
var bulletsMadeTotal :=0
|
||||
var bulletArray:Array = []
|
||||
var timer:= Timer.new()
|
||||
|
||||
@onready var coins: Node = $"../coins"
|
||||
@onready var enemies: Node = $"../enemies"
|
||||
|
||||
@onready var player: CharacterBody2D = $"../CharacterBody2D"
|
||||
@onready var ui: Control = $"../CanvasLayer/Control"
|
||||
@onready var gun_trigger: Area2D = $"../GunTrigger"
|
||||
|
||||
var bullet = preload("res://scenes/bullet.tscn")
|
||||
|
||||
func _ready() -> void:
|
||||
add_child(timer)
|
||||
timer.wait_time = 1
|
||||
timer.one_shot = false
|
||||
timer.connect("timeout", GameController.timeOut)
|
||||
timer.start()
|
||||
|
||||
var totalCoins = 0
|
||||
var totalEnemies = 0
|
||||
### coins loop
|
||||
for n in coins.get_children():
|
||||
print("coin found")
|
||||
totalCoins +=1
|
||||
n.coinCollected.connect(GameController.coinCollected)
|
||||
### enemies loop
|
||||
for n in enemies.get_children():
|
||||
print("enemy found")
|
||||
totalEnemies +=1
|
||||
n.playerDamage.connect(GameController.playerDamage)
|
||||
|
||||
|
||||
|
||||
|
||||
## wire up GameController signals to Player
|
||||
GameController.playerHurt.connect(hurtPlayer)
|
||||
GameController.playerHurt.connect(ui.healthUpdate)
|
||||
GameController.playerDeath.connect(killPlayer)
|
||||
GameController.levelComplete.connect(changeLevel)
|
||||
GameController.tick.connect(ui.timerUpdate)
|
||||
GameController.playerOptions.connect(showGun)
|
||||
|
||||
gun_trigger.gunCollect.connect(GameController.gunCollected)
|
||||
gun_trigger.gunCollect.connect(player.gunCollected)
|
||||
|
||||
player.playerDead.connect(deadPlayer)
|
||||
|
||||
|
||||
GameController.coinsUpdate.connect(ui.coinsUpdate)
|
||||
|
||||
GameController.setTotalCoins(totalCoins)
|
||||
|
||||
GameController.sendOptions()
|
||||
|
||||
func bulletFactory():
|
||||
print("Make a bullet at the factory")
|
||||
var mybullet
|
||||
@@ -58,4 +86,16 @@ func killPlayer():
|
||||
func deadPlayer():
|
||||
GameController.reset()
|
||||
get_tree().reload_current_scene()
|
||||
|
||||
func showGun(gun):
|
||||
print("Show the gun? "+str(gun) )
|
||||
if gun:
|
||||
player.gunCollected()
|
||||
else:
|
||||
player.gunDrop()
|
||||
|
||||
func changeLevel(level):
|
||||
print("Scene Manager should change level")
|
||||
GameController.reset()
|
||||
get_tree().change_scene_to_file(level)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
extends Area2D
|
||||
var BoxCount = 0
|
||||
var MaxBoxes = 3
|
||||
|
||||
signal gunCollect
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
@@ -14,9 +14,7 @@ func _process(delta: float) -> void:
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
print("Trigger saw a thing")
|
||||
if body.is_in_group("box"):
|
||||
print("box hit the trigger")
|
||||
BoxCount +=1
|
||||
if BoxCount >= MaxBoxes:
|
||||
print("YU WUN")
|
||||
if body.is_in_group("player"):
|
||||
print("player entered area")
|
||||
gunCollect.emit()
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
extends Control
|
||||
@onready var health: Label = $VBoxContainer/HBoxContainer/MarginContainer/health
|
||||
@onready var coins: Label = $VBoxContainer/HBoxContainer/MarginContainer2/coins
|
||||
@onready var timer: Label = $VBoxContainer/HBoxContainer/MarginContainer3/timer
|
||||
|
||||
var tempCoinCount = 0
|
||||
var tempCoinTotal = 0
|
||||
|
||||
func timerUpdate(amt):
|
||||
timer.text = "Seconds : "+str(amt)
|
||||
func healthUpdate(amt):
|
||||
health.text=("Health : "+str(amt) )
|
||||
func coinsUpdate(amt, total):
|
||||
tempCoinCount = amt
|
||||
tempCoinTotal = total
|
||||
if coins:
|
||||
coins.text = ("Coins : "+str(amt)+" of "+str(total) )
|
||||
func _ready() -> void:
|
||||
coins.text = ("Coins : "+str(tempCoinCount)+" of "+str(tempCoinTotal) )
|
||||
Reference in new issue
Block a user