GodotGameWorkshop/Scripts/scene_manager.gd

45 lines
1.1 KiB
GDScript

extends Node2D
var bullet = preload("res://Scenes/bullet.tscn")
var bulletArray =[]
var totalAllowedBullets = 7
@onready var triggers: Node2D = $"../Triggers"
@onready var gameController: Node2D = $".."
@onready var coins: Node2D = $"../Coins"
func _ready() -> void:
for obj in triggers.get_children():
obj.areatrigger.connect(gameController._on_areatrigger)
var coinCount = 0
for obj in coins.get_children():
obj.coinCollectedSignal.connect(gameController.coinCollected)
coinCount +=1
#send information to the game controller
gameController.totalCoinCount(coinCount)
#makes bullets
func bulletFactory():
var mybullet
if bulletArray.size() < totalAllowedBullets:
#make a new bullet
mybullet = bullet.instantiate()
owner.add_child(mybullet)
else:
#recycle bullet
mybullet = bulletArray.pop_back()
bulletArray.push_front(mybullet)
return mybullet
#order desk
func makeBullet(position, speed):
print("Scenemanger orders a bullet")
#ask the factory for a bullet
var mybullet = bulletFactory()
#set the speed for the bullet
mybullet.setSpeed(speed)
#position the bullet
mybullet.transform = position