65 lines
1.4 KiB
GDScript
65 lines
1.4 KiB
GDScript
extends Node
|
|
|
|
var bulletsFiredTotal := 0
|
|
var bulletsMadeTotal := 0
|
|
var bulletArray:Array = []
|
|
@onready var coins: Node = $"../Coins"
|
|
@onready var bad_guys: Node = $"../BadGuys"
|
|
|
|
@onready var player: CharacterBody2D = $"../CharacterBody2D"
|
|
|
|
|
|
|
|
var bullet = preload("res://scenes/bullet.tscn")
|
|
|
|
func _ready() -> void:
|
|
### coins loop
|
|
for n in coins.get_children():
|
|
print("coin found")
|
|
n.coinCollected.connect(GameController.coinCollected)
|
|
### enemies loop
|
|
for n in bad_guys.get_children():
|
|
print("enemy found")
|
|
n.playerDamage.connect(GameController.playerDamage)
|
|
|
|
### wire up GameController signals to Player
|
|
GameController.playerHurt.connect(hurtPlayer)
|
|
GameController.playerDeath.connect(killPlayer)
|
|
|
|
player.playerDead.connect(deadPlayer)
|
|
|
|
|
|
func bulletFactory():
|
|
print("Make a bullet at the factory")
|
|
var mybullet
|
|
|
|
#how many bullets 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("RIP")
|
|
body.queue_free()
|
|
|
|
func hurtPlayer(amt):
|
|
player.hurtPlayer(amt)
|
|
|
|
func killPlayer():
|
|
player.killPlayer()
|
|
|
|
func deadPlayer():
|
|
GameController.reset()
|
|
get_tree().reload_current_scene()
|
|
|