AugGodotGameCourse/augustgamecourse/scripts/scene_manager.gd

50 lines
1.4 KiB
GDScript

extends Node
var crate = preload("res://scenes/crate.tscn")
var bullet = preload("res://scenes/bullet.tscn")
var bulletPool:Array = []
# crate stuff
var cratePool:Array = []
@onready var box_trap_target: Node2D = $"../BoxTrapTarget"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
#pool all the crates
for obj in owner.get_children():
if obj.is_in_group("pushables"):
cratePool.push_back(obj)
print("Total crates on screen : "+str(cratePool.size() ) )
func boxTrap():
print("Trigger a box trap!")
var myCrate = crateFactory()
myCrate.transform = box_trap_target.transform
owner.add_child(myCrate)
func bulletFactory():
# makes bullets!!
var myBullet
print("total bullets in play : "+str(bulletPool.size() ))
if bulletPool.size() > 3:
myBullet = bulletPool.pop_front()
else:
myBullet = bullet.instantiate()
owner.add_child(myBullet)
#or....recycles bullets
return myBullet
func placeBullet(speed, markerpos):
print("SceneManager: make a bullet")
var myBullet = bulletFactory()
bulletPool.push_back(myBullet)
print("Total bullets in play: "+str(bulletPool.size() ) )
# set the speed of bullet
myBullet.setSpeed(speed)
# set the position of the bullet
myBullet.transform = markerpos
# make the bullet visible by adding it
func crateFactory():
var myCrate = crate.instantiate()
myCrate.add_to_group("pushables")
return myCrate