GodotCourse/week2/updated_files/scripts/SceneManager.gd

28 lines
546 B
GDScript3
Raw Normal View History

2024-09-09 20:36:12 +00:00
extends Node
2024-07-15 21:33:43 +00:00
2024-09-09 20:36:12 +00:00
var bulletsFiredTotal := 0
2024-09-09 21:27:42 +00:00
var bulletsMadeTotal := 0
var bulletArray:Array = []
2024-07-15 21:33:43 +00:00
2024-09-09 21:27:42 +00:00
var bullet = preload("res://scenes/bullet.tscn")
2024-07-15 21:33:43 +00:00
2024-09-09 21:27:42 +00:00
func bulletFactory():
var mybullet
if bulletArray.size() < 4:
mybullet = bullet.instantiate()
mybullet.connect("hit", onBulletHit)
owner.add_child(mybullet)
else:
mybullet = bulletArray.pop_back()
mybullet.setSpeed(700)
bulletArray.push_front(mybullet)
bulletsMadeTotal +=1
return mybullet
2024-07-15 21:33:43 +00:00
2024-09-09 21:27:42 +00:00
func onBulletHit(bullet, body):
#deactivate bullet
#put back in queue
bullet.setSpeed(1)