FebGame/febfabgame/Scripts/scene_manager.gd

109 lines
2.9 KiB
GDScript3
Raw Permalink Normal View History

2025-03-04 01:40:24 +00:00
extends Node
#@onready var gameController: GameController = $".."
@onready var crates: Node2D = $"../Crates"
@onready var triggers: Node2D = $"../triggers"
@onready var coins: Node2D = $"../coins"
@onready var badguys: Node2D = $"../badguys"
@onready var player: Player = $"../CharacterBody2D"
@onready var ui: Control = $"../CanvasLayer/UI"
2025-03-04 01:40:24 +00:00
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() < 8:
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
2025-03-04 01:40:24 +00:00
# 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
2025-03-04 01:40:24 +00:00
func bulletHit(bullet, body):
print("tell the game controller a bullet hit smthn")
#gameController.bulletHit(body)
Gamecontroller.bulletHit(body)
bullet.setSpeed(0)
bullet.position = Vector2(-100,-100)
2025-03-04 01:40:24 +00:00
func destroy(body):
body.queue_free()
2025-03-04 01:40:24 +00:00
func buildLevel():
#how many crates?
var totalCrates = 0
for obj in crates.get_children():
if obj is Crate:
totalCrates +=1
#gameController.numberOfCrates(totalCrates)
Gamecontroller.numberOfCrates(totalCrates)
#how many coints?
var totalCoins =0
if coins:
for obj in coins.get_children():
if obj is Coin:
totalCoins +=1
obj.coinCollectedSignal.connect(Gamecontroller.coinCollected)
Gamecontroller.numberOfCoins(totalCoins)
#how many bad guys
var totalBadguys =0
if badguys:
for obj in badguys.get_children():
if obj is Slime:
totalBadguys +=1
obj.playerDamagSignal.connect(Gamecontroller.playerDamage)
Gamecontroller.addBadGuy(obj)
Gamecontroller.numberOfBadguys(totalBadguys)
2025-03-04 01:40:24 +00:00
#wire up the triggers
for obj in triggers.get_children():
if obj is Trigger:
#wire up to GC
#obj.areaTrigger.connect(gameController._on_trigger_area_trigger)
obj.areaTrigger.connect(Gamecontroller._on_trigger_area_trigger)
#Listen to gameController
Gamecontroller.destroySignal.connect(destroy)
Gamecontroller.LevelCompleteSignal.connect(loadLevel)
Gamecontroller.playerHurtSignal.connect(playerHurt)
Gamecontroller.playerHurtSignal.connect(ui.healthUpdate)
Gamecontroller.playerKillSignal.connect(playerKill)
Gamecontroller.timerUpdateSignal.connect(ui.timerUpdate)
Gamecontroller.coinUpdateSignal.connect(ui.coinsUpdate)
#listen to player
player.deathCompleteSignal.connect(Gamecontroller.deathComplete)
func loadLevel(level):
get_tree().change_scene_to_file(level)
2025-03-04 01:40:24 +00:00
func _ready() -> void:
buildLevel()
Gamecontroller.reset()
2025-03-04 01:40:24 +00:00
func playerHurt(health, _maxHealth):
player.hurtPlayer(health)
func playerKill():
player.killPlayer()