bad guys and collectibles working

This commit is contained in:
OddlyTimbot committed 2024-08-12 15:19:54 -04:00
1 parent 16cd986048
commit aa44b13532
49 files changed
+1337 -54

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
extends Area2D
const speed = 60
var direction = 1
@onready var cast_right = $CastRight
@onready var cast_left = $CastLeft
@onready var sprite = $AnimatedSprite2D
@onready var game = $".."
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if cast_right.is_colliding():
direction = -1
sprite.flip_h = true
if cast_left.is_colliding():
direction = 1
sprite.flip_h = false
position.x += direction * speed * delta
func _on_body_entered(body):
if body.is_in_group("player"):
game.playerDeath()
+7
View File
@@ -0,0 +1,7 @@
extends Area2D
@onready var game = $".."
func _on_body_entered(body):
if body.is_in_group("player"):
game.coinCollected()
@@ -1,14 +1,16 @@
extends Node2D
var coinsCollected = 0
var crate = preload("res://scenes/crate.tscn")
@onready var boxtrap = $crates/boxtrap
@onready var player = $CharacterBody2D
func _on_area_2d_areatrigger(effect, body):
print("Game Controller sees the trigger "+effect)
match effect:
"alert":
#do stuff
print("hi")
if body.is_in_group("player"):
for n in 3:
var box = crate.instantiate()
@@ -16,3 +18,12 @@ func _on_area_2d_areatrigger(effect, body):
box.position = boxtrap.position
"powerup":
print("you got power")
"kill":
print("kill the player")
func coinCollected():
coinsCollected +=1
print("coins collected "+str(coinsCollected) )
func playerDeath():
print("kill the player")