added coins, bad guys
This commit is contained in:
1 parent
e0f48061e7
commit
f6ad5142bf
17 files changed
+384
-28
No files matched your search
@@ -0,0 +1,32 @@
|
||||
class_name BadGuy extends Area2D
|
||||
|
||||
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D
|
||||
@onready var right_ray: RayCast2D = $RightRay
|
||||
@onready var left_ray: RayCast2D = $LeftRay
|
||||
@onready var right_floor_ray: RayCast2D = $RightFloorRay
|
||||
@onready var left_floor_ray: RayCast2D = $LeftFloorRay
|
||||
|
||||
const speed := 60
|
||||
|
||||
var direction = 1
|
||||
|
||||
signal playerHurt
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if not right_floor_ray.is_colliding():
|
||||
#about to fall off the right
|
||||
direction = -1
|
||||
sprite.flip_h = not sprite.flip_h
|
||||
if not left_floor_ray.is_colliding():
|
||||
#about to fall off the left
|
||||
sprite.flip_h = not sprite.flip_h
|
||||
direction = 1
|
||||
|
||||
position.x += direction*speed*delta
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if body.is_in_group("player"):
|
||||
print("player hurt")
|
||||
playerHurt.emit()
|
||||
# queue_free()
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class_name Coin extends Area2D
|
||||
|
||||
signal coinCollected
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if body.is_in_group("player"):
|
||||
coinCollected.emit()
|
||||
queue_free()
|
||||
|
||||
@@ -3,11 +3,16 @@ extends Node2D
|
||||
var timer:= Timer.new()
|
||||
var secondCount= 99
|
||||
var totalCrates := 0
|
||||
var totalCoins := 0
|
||||
var totalBadGuys := 0
|
||||
var totalCoinsCollected := 0
|
||||
var cratesDestroyed := 0
|
||||
|
||||
var player:Resource
|
||||
|
||||
# level info
|
||||
var levels = ["res://scenes/game.tscn", "res://scenes/level2.tscn"]
|
||||
var timers = [20, 15]
|
||||
var timers = [30, 30]
|
||||
var currentLevel = 0
|
||||
|
||||
#Gamecontroller signals
|
||||
@@ -16,6 +21,8 @@ signal levelComplete(leveltoLoad)
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
player = load("res://scripts/res/playerstats.tres")
|
||||
print("Player Health: "+str(player.health))
|
||||
print("Number of levels: "+str(levels.size()))
|
||||
add_child(timer)
|
||||
timer.wait_time = 1
|
||||
@@ -33,6 +40,17 @@ func secondCounter():
|
||||
print("TIME IS UP")
|
||||
levelComplete.emit(levels[currentLevel])
|
||||
|
||||
func playerDamaged():
|
||||
print("GC knows player took damage")
|
||||
player.health = max(player.health-10, 0)
|
||||
print("Player Health: "+str(player.health))
|
||||
|
||||
|
||||
|
||||
func coinCollected():
|
||||
totalCoinsCollected += 1
|
||||
print("DING! Coins collected: "+ str(totalCoinsCollected) )
|
||||
|
||||
func bulletHit(body):
|
||||
print("Game controller knows bullet hit something")
|
||||
if body.is_in_group("destructables"):
|
||||
@@ -48,7 +66,14 @@ func bulletHit(body):
|
||||
levelComplete.emit(levels[currentLevel])
|
||||
else:
|
||||
print("Crates Remaining: "+str(totalCrates) )
|
||||
|
||||
|
||||
# Coming from scenemanager
|
||||
func countCrates(value):
|
||||
totalCrates = value
|
||||
|
||||
func countCoins(value):
|
||||
totalCoins = value
|
||||
|
||||
func countBadGuys(value):
|
||||
totalBadGuys = value
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class_name CharacterStats extends Resource
|
||||
|
||||
@export var max_health:int = 100
|
||||
@export var starting_health:int = 100
|
||||
@export var health:int = 100
|
||||
@@ -0,0 +1,9 @@
|
||||
[gd_resource type="Resource" script_class="CharacterStats" load_steps=2 format=3 uid="uid://hdyv13v8yr88"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/res/characterStats.gd" id="1_d4qjr"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_d4qjr")
|
||||
max_health = 150
|
||||
starting_health = 100
|
||||
health = 100
|
||||
@@ -0,0 +1,9 @@
|
||||
[gd_resource type="Resource" script_class="CharacterStats" load_steps=2 format=3 uid="uid://3vw8xffecvtj"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/res/characterStats.gd" id="1_74dik"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("1_74dik")
|
||||
max_health = 60
|
||||
starting_health = 50
|
||||
health = 50
|
||||
+18
-2
@@ -2,21 +2,37 @@ extends Node
|
||||
# @onready var game: Node2D = $".."
|
||||
|
||||
@onready var crates: Node2D = $"../crates"
|
||||
@onready var coins: Node2D = $"../coins"
|
||||
@onready var enemies: Node2D = $"../enemies"
|
||||
|
||||
var theBullet = preload("res://scenes/bullet.tscn")
|
||||
var bulletArray:Array = []
|
||||
|
||||
var totalCrates := 0
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
var totalCrates = 0
|
||||
GameController.reset()
|
||||
GameController.destroyBox.connect(boxDestroy)
|
||||
for obj in crates.get_children():
|
||||
if obj.is_in_group("destructables"):
|
||||
totalCrates += 1
|
||||
GameController.countCrates(totalCrates)
|
||||
|
||||
var totalCoins = 0
|
||||
for obj in coins.get_children():
|
||||
if obj.is_in_group("collectibles"):
|
||||
totalCoins += 1
|
||||
obj.coinCollected.connect(GameController.coinCollected)
|
||||
GameController.countCoins(totalCoins)
|
||||
|
||||
var totalEnemies = 0
|
||||
for obj in enemies.get_children():
|
||||
if obj.is_in_group("enemies"):
|
||||
totalEnemies += 1
|
||||
obj.playerHurt.connect(GameController.playerDamaged)
|
||||
GameController.countBadGuys(totalEnemies)
|
||||
|
||||
GameController.countCrates(totalCrates)
|
||||
# Subscribe to signals
|
||||
GameController.levelComplete.connect(changeLevel)
|
||||
|
||||
|
||||
Reference in new issue
Block a user