40 lines
905 B
GDScript3
40 lines
905 B
GDScript3
|
extends Node
|
||
|
@onready var game: GameController = $".."
|
||
|
@onready var crates: Node2D = $"../Crates"
|
||
|
|
||
|
var bullet = preload("res://Scenes/Bullet.tscn")
|
||
|
var bulletArray=[]
|
||
|
var totalAllowedBullets = 7
|
||
|
|
||
|
func buildLevel () -> void:
|
||
|
#count crates
|
||
|
var totalCrates = 0
|
||
|
for obj in crates.get_children():
|
||
|
if obj is Crate:
|
||
|
totalCrates +=1
|
||
|
#tell the game controller
|
||
|
game.numberOfCrates(totalCrates)
|
||
|
|
||
|
|
||
|
func _ready() -> void:
|
||
|
buildLevel()
|
||
|
|
||
|
func bulletFarm():
|
||
|
var mybullet
|
||
|
if bulletArray.size() < totalAllowedBullets:
|
||
|
mybullet = bullet.instantiate()
|
||
|
mybullet.connect("bulletHit", game.bulletDamage)
|
||
|
owner.add_child(mybullet)
|
||
|
else:
|
||
|
#recyclebullet\
|
||
|
mybullet = bulletArray.pop_back()
|
||
|
|
||
|
bulletArray.push_front(mybullet)
|
||
|
return mybullet
|
||
|
|
||
|
func makeBullet(position, speed):
|
||
|
print ("scene manager makes a bullet")
|
||
|
var mybullet = bulletFarm()
|
||
|
mybullet.setSpeed(speed)
|
||
|
mybullet.transform = position
|