KieranGodot/august26godotcompkieran/Sripts/scene_manager.gd

74 lines
1.9 KiB
GDScript3
Raw Permalink Normal View History

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"
@onready var coins: Node = $"../coins"
@onready var enemies: Node = $"../Enemies"
@onready var player: CharacterBody2D = $"../CharacterBody2D"
@onready var deathdelay: Timer = $Timer
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() ) )
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)
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
func killplayer():
print("kill player")
player.killplayer()
deathdelay.start(1)
func resetworld():
GameController.resetplayer()
get_tree().reload_current_scene()