DariusGodotGame/dariusgodotproject/scripts/scenemanager.gd

51 lines
1.2 KiB
GDScript3
Raw Normal View History

2025-01-14 01:58:53 +00:00
extends Node
@onready var game: Node2D = $".."
2025-01-21 01:44:44 +00:00
@onready var crates: Node2D = $"../crates"
2025-01-14 01:58:53 +00:00
var bullet = preload("res://scenes/bullet.tscn")
2025-01-21 01:44:44 +00:00
var bulletArray:Array = []
var bulletsMadeTotal :=0
var totalCrates = 0
2025-01-14 01:58:53 +00:00
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
2025-01-21 01:44:44 +00:00
game.destroyBox.connect(boxDestroy)
for obj in crates.get_children():
if obj.is_in_group("destructable"):
#increase the box counter
totalCrates +=1
2025-01-14 01:58:53 +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:44 +00:00
var myBullet
if bulletArray.size() < 10:
myBullet = bullet.instantiate()
myBullet.connect("hit", onBulletHit)
owner.add_child(myBullet)
else:
myBullet = bulletArray.pop_back()
bulletArray.push_front(myBullet)
return myBullet
func makeBullet(position, speed):
var myBullet = bulletFactory()
myBullet.transform = position
myBullet.setSpeed(speed)
2025-01-14 01:58:53 +00:00
return myBullet
2025-01-21 01:44:44 +00:00
2025-01-14 01:58:53 +00:00
2025-01-21 01:44:44 +00:00
func onBulletHit(bullet, body):
bullet.position = Vector2(-100,-100)
bullet.setSpeed(0)
2025-01-14 01:58:53 +00:00
print("Scene manager knows bullet hit")
game.bulletHit(body)
2025-01-21 01:44:44 +00:00
func boxDestroy(body):
print("test")
body.queue_free()