AhmedFebruary2025/ahmedgg/scripts/scene_manager.gd

57 lines
1.4 KiB
GDScript3
Raw Normal View History

2025-03-04 01:41:41 +00:00
extends Node
@onready var gameController: GameController = $".."
@onready var crates: Node2D = $"../crates"
@onready var triggers: Node2D = $"../Triggers"
2025-03-04 01:41:41 +00:00
var bulletsFiredTotal = 0
var bulletsMadeTotal = 0
var bulletArray = []
var bullet = preload("res://scenes/bullet.tscn")
# Bullet factor - makes bullets
func bulletFactory():
var mybullet
if bulletArray.size()<4:
print("new bullet at factory")
mybullet = bullet.instantiate()
mybullet.connect("hit", bulletHit)
else:
mybullet = bulletArray.pop_back()
print("recycled bullet")
bulletArray.push_front(mybullet)
return mybullet
# Order desk for bullets
func makeBullet(position,speed):
print("make a bullet")
var newBullet = bulletFactory()
owner.add_child(newBullet)
newBullet.setSpeed(speed)
newBullet.transform = position
func bulletHit(bullet, body):
print("tell game controller we hit something")
gameController.bulletHit(body)
bullet.setSpeed(0)
bullet.position = Vector2(-100,-100)
func destroy(body):
body.queue_free()
func buildLevel():
#how many crates?
var totalCrates = 0
for obj in crates.get_children():
if obj is Crate:
totalCrates +=1
gameController.numberofCrates(totalCrates)
#wire up the triggers
for obj in triggers.get_children():
if obj is Trigger:
#wire out to GC
obj.areatrigger.connect(gameController._on_trigger_areatrigger)
func _ready() -> void:
buildLevel()