badguys, autoloads, custom resources, collectibles

This commit is contained in:
Darius committed 2025-02-03 21:02:30 -05:00
1 parent a0f311aad6
commit 542251725c
16 files changed
+898 -30

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
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
#signals
signal playerDamage
func _process(delta: float) -> void:
if not right_floor_ray.is_colliding():
#about to fall on the right...
direction = -1
sprite.flip_h = true
if not left_floor_ray.is_colliding():
#about to fall on the left...
direction = 1
sprite.flip_h = false
position.x += direction * speed * delta
func _on_body_entered(body: Node2D) -> void:
if body.is_in_group("player"):
print("Bad Guy Collided")
playerDamage.emit()
+8
View File
@@ -0,0 +1,8 @@
class_name Coin extends Area2D
signal coinCollected
func _on_body_entered(body: Node2D) -> void:
if body.is_in_group("player"):
coinCollected.emit()
queue_free()
+51 -21
View File
@@ -1,45 +1,75 @@
extends Node2D
var boxTotal = 4
var boxTotal := 4
var timer:=Timer.new()
var countdown = 10
var totalCrates = 0
var countdown := 10
var totalCrates := 0
var cratesDestroyed := 0
var totalCoins := 0
var totalCoinsCollected := 0
var totalBadGuys := 0
var player:Resource
#level information
var levels = ["res://scenes/game.tscn","res://scenes/level2.tscn"]
var timers = [10, 15]
var currentLevel = 0
#Signals from GC
signal destroyBox(body)
signal levelComplete (levelToLoad)
# C alled 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()))
reset()
add_child(timer)
timer.wait_time = 1
timer.one_shot = false
timer.connect("timeout", secondCounter)
#timer.start()
timer.start()
pass # Replace with function body.
func reset():
countdown = timers[currentLevel]
func secondCounter():
# print("one second")
countdown -=1
if countdown <=0:
print("YOU LOSE")
get_tree().reload_current_scene()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _on_trigger(effect: Variant, body) -> void:
print("Game Controller sees an alert.")
if body is RigidBody2D:
print("I see a rigid body.")
body.queue_free()
boxTotal -=1
if boxTotal <=0:
print("YOU WON!!")
get_tree().reload_current_scene()
levelComplete.emit(levels[currentLevel])
func coinCollected():
totalCoinsCollected +=1
print("GC knows coin collected")
func playerDamaged():
print("GC knows player taking damage")
player.health -=20
print("Health remaining: " +str(player.health))
func bulletHit(body):
print("Game controller knows bullet hit something")
if body.is_in_group("destructable"):
destroyBox.emit(body)
totalCrates -=1
cratesDestroyed +=1
if totalCrates <=0:
print("YOU WON!!")
currentLevel +=1
if currentLevel >= levels.size():
currentLevel = 0
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://c3v847h6im2q4"]
[ext_resource type="Script" path="res://scripts/res/characterstats.gd" id="1_80q3k"]
[resource]
script = ExtResource("1_80q3k")
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://cfc2x0bcvbp4k"]
[ext_resource type="Script" path="res://scripts/res/characterstats.gd" id="1_34pqp"]
[resource]
script = ExtResource("1_34pqp")
max_health = 60
starting_health = 50
health = 50
+27 -4
View File
@@ -1,22 +1,45 @@
extends Node
@onready var game: Node2D = $".."
@onready var crates: Node2D = $"../crates"
@onready var coins: Node2D = $"../coins"
@onready var enemies: Node2D = $"../enemies"
var bullet = preload("res://scenes/bullet.tscn")
var bulletArray:Array = []
var bulletsMadeTotal :=0
var totalCrates = 0
var totalCrates := 0
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
game.destroyBox.connect(boxDestroy)
#Give GC number of crates
Gamecontroller.destroyBox.connect(boxDestroy)
for obj in crates.get_children():
if obj.is_in_group("destructable"):
#increase the box counter
totalCrates +=1
var totalCoins = 0
for obj in coins.get_children():
if obj.is_in_group("collectibles"):
totalCoins +=1
obj.coinCollected.connect(Gamecontroller.coinCollected)
var totalEnemies = 0
for obj in enemies.get_children():
if obj.is_in_group("enemies"):
totalEnemies +=1
obj.playerDamage.connect(Gamecontroller.playerDamaged)
Gamecontroller.countBadGuys(totalEnemies)
Gamecontroller.countCoins(totalCoins)
Gamecontroller.countCrates(totalCrates)
#Subscribe to vital events from GC
Gamecontroller.levelComplete.connect(changeLevel)
Gamecontroller.reset()
func changeLevel(level):
get_tree().change_scene_to_file(level)
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
@@ -46,7 +69,7 @@ func onBulletHit(bullet, body):
bullet.position = Vector2(-100,-100)
bullet.setSpeed(0)
print("Scene manager knows bullet hit")
game.bulletHit(body)
Gamecontroller.bulletHit(body)
func boxDestroy(body):
print("test")
body.queue_free()