33 lines
767 B
GDScript3
33 lines
767 B
GDScript3
|
extends Node
|
||
|
|
||
|
var bulletsFiredTotal = 0
|
||
|
var bulletsMadeTotal = 0
|
||
|
var bulletArray= []
|
||
|
|
||
|
var bullet = preload("res://scenes/bullet.tscn")
|
||
|
|
||
|
# bullet factory - makes bullets
|
||
|
func bulletFactory():
|
||
|
var mybullet
|
||
|
if bulletArray.size() < 7:
|
||
|
print("new bullet at factory")
|
||
|
mybullet = bullet.instantiate()
|
||
|
mybullet.connect("hit", bulletHit)
|
||
|
else:
|
||
|
print("recycled bullet at factory")
|
||
|
mybullet = bulletArray.pop_back()
|
||
|
|
||
|
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 the game controller a bullet hit something")
|