parallax background, pickups, slime enemies

This commit is contained in:
OddlyTimbot committed 2026-10-27 21:03:58 -04:00
1 parent c3ab17230b
commit 04f421901c
21 files changed
+710 -7

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
class_name Coin extends Area2D
signal coinCollisionSignal(body, coin)
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _on_body_entered(body: Node2D) -> void:
coinCollisionSignal.emit(body, self)
+1
View File
@@ -0,0 +1 @@
uid://dhc6762deonm2
+20
View File
@@ -3,6 +3,11 @@ class_name GameController extends Node2D
signal teleportSignal(body:RigidBody2D)
signal destroySignal(body)
var numberOfCrates = 2
var totalCoins = 0
var coinsRemaining = 0
var coinsCollected = 0
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
get_window().grab_focus()
@@ -30,3 +35,18 @@ func _on_bullet_hit(body, bullet) -> void:
destroySignal.emit(body)
destroySignal.emit(bullet)
func crateTotal(amount)->void:
numberOfCrates = amount
if numberOfCrates<=0:
print("YOU WON!!!")
func coinTotal(amount)->void:
if totalCoins == 0:
totalCoins = amount
coinsRemaining = amount
print("Collected "+str(totalCoins-coinsRemaining)+" of "+str(totalCoins) )
func coinCollected(body, coin)->void:
if body is Player:
#give them a coin
coinsCollected +=1
destroySignal.emit(coin)
+30 -1
View File
@@ -3,6 +3,8 @@ class_name SceneManager extends Node2D
@onready var triggers: Node2D = $"../Triggers"
@onready var game: GameController = $".."
@onready var player: Player = $"../Player"
@onready var crates: Node2D = $"../Crates"
@onready var coins: Node2D = $"../Coins"
#recipe for bullets
var bullet = preload("res://scenes/bullet.tscn")
@@ -16,13 +18,38 @@ func _ready() -> void:
game.teleportSignal.connect(teleport)
game.destroySignal.connect(destroy)
player.bulletSignal.connect(makeBullet)
updateCrates()
updateCoins()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func updateCrates()->void:
var totalCrates = 0
# loop through all crates
for obj in crates.get_children():
if obj is Crate:
#check if the tree exit signal is wired up
if not obj.tree_exited.is_connected(updateCrates):
obj.tree_exited.connect(updateCrates)
totalCrates +=1
# tell the gamecontroller how many crates
game.crateTotal(totalCrates)
func updateCoins()->void:
var totalCoins = 0
#loop through the coins
for obj in coins.get_children():
if obj is Coin:
if not obj.tree_exited.is_connected(updateCoins):
obj.tree_exited.connect(updateCoins)
if not obj.coinCollisionSignal.is_connected(game.coinCollected):
obj.coinCollisionSignal.connect(game.coinCollected)
totalCoins +=1
game.coinTotal(totalCoins)
func buildLevel()->void:
if triggers:
for obj in triggers.get_children():
@@ -68,6 +95,8 @@ func destroy(target)->void:
stash(target)
if target is Crate:
target.queue_free()
if target is Coin:
target.queue_free()
func stash(target:Bullet)->void:
print("stash a bullet")
+80
View File
@@ -0,0 +1,80 @@
class_name Slime extends Area2D
@onready var right_cast: RayCast2D = $RightCast
@onready var left_cast: RayCast2D = $LeftCast
@onready var right_down_cast: RayCast2D = $RightDownCast
@onready var left_down_cast: RayCast2D = $LeftDownCast
@onready var slime_graphic: AnimatedSprite2D = $SlimeGraphic
var speed = 100
enum FaceDirection {RIGHT, LEFT}
var facing:FaceDirection = FaceDirection.RIGHT
#direction 1 move to right, 0 no movement, -1 to the left
var direction = 1
enum EnemyStates {RUN, ATTACK, SPAWN}
var currentEnemyState:EnemyStates = EnemyStates.SPAWN
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
handleMovement(delta)
handleStates()
handleAnimation()
handleCollisions()
func handleMovement(delta)->void:
position.x += direction*speed*delta
match facing:
FaceDirection.LEFT:
slime_graphic.flip_h = true
FaceDirection.RIGHT:
slime_graphic.flip_h = false
func handleStates()->void:
match currentEnemyState:
EnemyStates.SPAWN when not direction ==0:
currentEnemyState = EnemyStates.RUN
func handleAnimation()->void:
match currentEnemyState:
EnemyStates.SPAWN:
slime_graphic.play("spawn")
EnemyStates.RUN:
slime_graphic.play("run")
EnemyStates.ATTACK:
slime_graphic.play("attack")
func handleCollisions()->void:
if not right_down_cast.is_colliding():
direction = -1
facing = FaceDirection.LEFT
if not left_down_cast.is_colliding():
direction = 1
facing= FaceDirection.RIGHT
if right_cast.is_colliding() and not right_cast.get_collider() is Player:
direction = -1
facing = FaceDirection.LEFT
if left_cast.is_colliding() and not left_cast.get_collider() is Player:
direction = 1
facing= FaceDirection.RIGHT
pass
func _on_body_entered(body: Node2D) -> void:
print("Slime Attack!")
func _on_animation_finished() -> void:
match currentEnemyState:
EnemyStates.SPAWN:
currentEnemyState = EnemyStates.RUN
direction = 1
EnemyStates.ATTACK:
currentEnemyState = EnemyStates.RUN
direction = (randi() % 2) *2 -1
+1
View File
@@ -0,0 +1 @@
uid://bltdu3mbpch5n