2024-09-17 01:13:05 +00:00
|
|
|
extends Node
|
|
|
|
var crate = preload("res://Scenes/Crate.tscn")
|
|
|
|
var bullet = preload("res://Scenes/Bullet.tscn")
|
|
|
|
var bulletPool:Array = []
|
|
|
|
# crate pool thing
|
|
|
|
var cratePool:Array = []
|
|
|
|
@onready var box_trap_target: Node2D = $"../BoxTrapTarget"
|
2024-10-01 01:14:46 +00:00
|
|
|
@onready var coins: Node = $"../coins"
|
|
|
|
@onready var enemies: Node = $"../Enemies"
|
|
|
|
@onready var player: CharacterBody2D = $"../CharacterBody2D"
|
|
|
|
@onready var deathdelay: Timer = $Timer
|
2024-09-17 01:13:05 +00:00
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
# pool crates
|
|
|
|
for obj in owner.get_children():
|
|
|
|
if obj.is_in_group("Pushable"):
|
|
|
|
cratePool.push_back(obj)
|
|
|
|
print("Total crate in play: "+str(cratePool.size() ) )
|
2024-10-01 01:14:46 +00:00
|
|
|
for n in coins.get_children():
|
|
|
|
# hook up the coincollected signal
|
|
|
|
print("coin found")
|
|
|
|
n.coincollected.connect(GameController.coincollected)
|
|
|
|
# Enemy routine
|
|
|
|
for n in enemies.get_children():
|
|
|
|
if n is Enemy:
|
|
|
|
#wire up the signal
|
|
|
|
n.playerdamage.connect(GameController.playerdamaged)
|
|
|
|
# gamecontroller signals
|
|
|
|
GameController.playerdeath.connect(killplayer)
|
|
|
|
|
2024-09-17 01:13:05 +00:00
|
|
|
|
|
|
|
func boxTrap():
|
|
|
|
print("boxTrap active")
|
|
|
|
var myCrate = crateFactory()
|
|
|
|
myCrate.transform = box_trap_target.transform
|
|
|
|
owner.add_child(myCrate)
|
|
|
|
|
|
|
|
func bulletFactory():
|
|
|
|
#make/reuse bullets
|
|
|
|
var myBullet
|
|
|
|
print("Total bullets in play: "+str(bulletPool.size() ) )
|
|
|
|
if bulletPool.size() > 5:
|
|
|
|
myBullet = bulletPool.pop_front()
|
|
|
|
else:
|
|
|
|
myBullet = bullet.instantiate()
|
|
|
|
owner.add_child(myBullet)
|
|
|
|
return myBullet
|
|
|
|
|
|
|
|
func placeBullet(speed, markerpos):
|
|
|
|
print("make a bullet")
|
|
|
|
var myBullet = bulletFactory()
|
|
|
|
bulletPool.push_back(myBullet)
|
|
|
|
print("Total bullets in play: "+str(bulletPool.size() ) )
|
|
|
|
# set speed
|
|
|
|
myBullet.setSpeed(speed)
|
|
|
|
# set position of bullet
|
|
|
|
myBullet.transform = markerpos
|
|
|
|
# make bullet
|
|
|
|
|
|
|
|
|
|
|
|
func crateFactory():
|
|
|
|
var myCrate = crate.instantiate()
|
|
|
|
myCrate.add_to_group("Pushable")
|
|
|
|
return myCrate
|
2024-10-01 01:14:46 +00:00
|
|
|
|
|
|
|
func killplayer():
|
|
|
|
print("kill player")
|
|
|
|
player.killplayer()
|
|
|
|
deathdelay.start(1)
|
|
|
|
|
|
|
|
func resetworld():
|
|
|
|
GameController.resetplayer()
|
|
|
|
get_tree().reload_current_scene()
|