2024-11-26 01:52:14 +00:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
var bulletsFiredTotal := 0
|
|
|
|
var bulletsMadeTotal := 0
|
|
|
|
var bulletArray:Array = []
|
2024-12-24 02:28:19 +00:00
|
|
|
var timer:= Timer.new()
|
|
|
|
|
2024-12-17 02:14:40 +00:00
|
|
|
@onready var coins: Node = $"../Coins"
|
|
|
|
@onready var enemies: Node = $"../enemies"
|
2024-12-24 02:28:19 +00:00
|
|
|
@onready var gun_trigger: Area2D = $"../GunTrigger"
|
2024-12-17 02:14:40 +00:00
|
|
|
|
|
|
|
@onready var player: CharacterBody2D = $"../CharacterBody2D"
|
2024-12-24 02:28:19 +00:00
|
|
|
@onready var ui: Control = $"../CanvasLayer/Control"
|
2024-12-17 02:14:40 +00:00
|
|
|
|
2024-11-26 01:52:14 +00:00
|
|
|
|
|
|
|
var bullet = preload("res://scenes/bullet.tscn")
|
|
|
|
|
2024-12-17 02:14:40 +00:00
|
|
|
func _ready() -> void:
|
2024-12-24 02:28:19 +00:00
|
|
|
add_child(timer)
|
|
|
|
timer.wait_time = 1
|
|
|
|
timer.one_shot = false
|
|
|
|
timer.connect("timeout", GameController.timeOut)
|
|
|
|
timer.start()
|
|
|
|
|
|
|
|
var totalCoins = 0
|
|
|
|
var totalEnemies = 0
|
2024-12-17 02:14:40 +00:00
|
|
|
## Coins loop
|
|
|
|
for n in coins.get_children():
|
2024-12-24 02:28:19 +00:00
|
|
|
totalCoins += 1
|
2024-12-17 02:14:40 +00:00
|
|
|
n.coinCollected.connect(GameController.coinCollected)
|
|
|
|
## enemy loop
|
|
|
|
for n in enemies.get_children():
|
2024-12-24 02:28:19 +00:00
|
|
|
totalEnemies += 1
|
2024-12-17 02:14:40 +00:00
|
|
|
n.playerDamage.connect(GameController.playerDamage)
|
|
|
|
|
2024-12-24 02:28:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
## wire up GameController signals to Player
|
2024-12-17 02:14:40 +00:00
|
|
|
GameController.playerHurt.connect(hurtPlayer)
|
2024-12-24 02:28:19 +00:00
|
|
|
GameController.playerHurt.connect(ui.healthUpdate)
|
2024-12-17 02:14:40 +00:00
|
|
|
GameController.playerDeath.connect(killPlayer)
|
2024-12-24 02:28:19 +00:00
|
|
|
GameController.levelComplete.connect(changeLevel)
|
|
|
|
GameController.tick.connect(ui.timerUpdate)
|
|
|
|
GameController.playerOptions.connect(showGun)
|
|
|
|
|
|
|
|
gun_trigger.gunCollect.connect(GameController.gunCollected)
|
|
|
|
gun_trigger.gunCollect.connect(player.gunCollected)
|
2024-12-17 02:14:40 +00:00
|
|
|
|
|
|
|
player.playerDead.connect(deadPlayer)
|
|
|
|
|
2024-12-24 02:28:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
GameController.coinsUpdate.connect(ui.coinsUpdate)
|
|
|
|
|
|
|
|
GameController.setTotalCoins(totalCoins)
|
|
|
|
|
|
|
|
GameController.sendOptions()
|
|
|
|
|
2024-11-26 01:52:14 +00:00
|
|
|
func bulletFactory():
|
|
|
|
print("Make a bullet at the factory")
|
|
|
|
var mybullet
|
|
|
|
|
|
|
|
# How many bullet have been made
|
|
|
|
if bulletArray.size() < 4:
|
|
|
|
# make a new bullet
|
|
|
|
mybullet = bullet.instantiate()
|
|
|
|
mybullet.connect("hit", onBulletHit)
|
|
|
|
owner.add_child(mybullet)
|
|
|
|
else:
|
|
|
|
mybullet = bulletArray.pop_back()
|
|
|
|
bulletArray.push_front(mybullet)
|
|
|
|
bulletsMadeTotal += 1
|
|
|
|
return mybullet
|
|
|
|
|
|
|
|
func onBulletHit(bullet, body):
|
|
|
|
print("Scene Manager knows a bullet hit something")
|
|
|
|
bullet.setSpeed(0)
|
|
|
|
|
|
|
|
if body.is_in_group("shootable"):
|
|
|
|
print("explode this thing")
|
|
|
|
body.queue_free()
|
2024-12-17 02:14:40 +00:00
|
|
|
|
|
|
|
func hurtPlayer(amt):
|
|
|
|
player.hurtPlayer(amt)
|
|
|
|
|
|
|
|
func killPlayer():
|
|
|
|
player.killPlayer()
|
|
|
|
|
|
|
|
func deadPlayer():
|
|
|
|
GameController.reset()
|
|
|
|
get_tree().reload_current_scene()
|
2024-12-24 02:28:19 +00:00
|
|
|
|
|
|
|
func showGun(gun):
|
|
|
|
if gun == true:
|
|
|
|
player.gunCollected()
|
|
|
|
else:
|
|
|
|
player.gunDrop()
|
|
|
|
|
|
|
|
func changeLevel(level):
|
|
|
|
print("Scene Manager should change level")
|
|
|
|
GameController.reset()
|
|
|
|
get_tree().change_scene_to_file(level)
|