2025-01-14 01:58:52 +00:00
|
|
|
extends Node
|
|
|
|
@onready var game: Node2D = $".."
|
2025-01-21 01:44:30 +00:00
|
|
|
@onready var crates: Node2D = $"../crates"
|
2025-01-14 01:58:52 +00:00
|
|
|
|
|
|
|
var bullet = preload("res://scenes/bullet.tscn")
|
2025-01-21 01:44:30 +00:00
|
|
|
var bulletArray:Array = []
|
|
|
|
var bulletMadeTotal:= 0
|
2025-01-14 01:58:52 +00:00
|
|
|
|
2025-01-21 01:44:30 +00:00
|
|
|
var totalCrates := 0
|
2025-01-14 01:58:52 +00:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready() -> void:
|
2025-01-21 01:44:30 +00:00
|
|
|
game.destroyBox.connect(boxDestroy)
|
|
|
|
for obj in crates.get_children():
|
|
|
|
if obj.is_in_group("destructable"):
|
|
|
|
#increase box counter
|
|
|
|
totalCrates +=1
|
|
|
|
|
2025-01-14 01:58:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
pass
|
|
|
|
|
|
|
|
func bulletFactory():
|
|
|
|
print("factory will make a bullet")
|
2025-01-21 01:44:30 +00:00
|
|
|
var myBullet
|
|
|
|
if bulletArray.size() < 4:
|
|
|
|
myBullet = bullet.instantiate()
|
|
|
|
myBullet.connect("hit", onBulletHit)
|
|
|
|
owner.add_child(myBullet)
|
|
|
|
else:
|
|
|
|
myBullet = bulletArray.pop_back()
|
|
|
|
|
|
|
|
bulletArray.push_front(myBullet)
|
2025-01-14 01:58:52 +00:00
|
|
|
return myBullet
|
|
|
|
|
2025-01-21 01:44:30 +00:00
|
|
|
func makeBullet(position, speed):
|
|
|
|
var myBullet = bulletFactory()
|
|
|
|
myBullet.transform = position
|
|
|
|
myBullet.setSpeed(speed)
|
|
|
|
return myBullet
|
|
|
|
|
|
|
|
func onBulletHit(bullet, body):
|
|
|
|
bullet.position = Vector2(-100,-100)
|
|
|
|
bullet.setSpeed(0)
|
|
|
|
|
2025-01-14 01:58:52 +00:00
|
|
|
print("Scene manager knows bullet hit")
|
|
|
|
game.bulletHit(body)
|
2025-01-21 01:44:30 +00:00
|
|
|
|
|
|
|
func boxDestroy(body):
|
|
|
|
body.queue_free()
|