then there were numbered rockets
This commit is contained in:
parent
404f518ddd
commit
17a077d186
@ -1,4 +1,5 @@
|
|||||||
class_name Rocket extends RigidBody2D
|
class_name Rocket extends RigidBody2D
|
||||||
|
signal splodeSignal(rocket)
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
#Rockets expolode in time
|
#Rockets expolode in time
|
||||||
@ -12,6 +13,6 @@ func _ready() -> void:
|
|||||||
func _on_body_entered(body: Node) -> void:
|
func _on_body_entered(body: Node) -> void:
|
||||||
print("Rocket hit a target")
|
print("Rocket hit a target")
|
||||||
|
|
||||||
#should i splode myself?
|
#should i splode myself? No. Scene manager job.
|
||||||
func splode()->void:
|
func splode()->void:
|
||||||
self.queue_free()
|
splodeSignal.emit(self)
|
||||||
|
|||||||
@ -8,6 +8,8 @@ var rocket = preload("res://scenes/rocket.tscn")
|
|||||||
|
|
||||||
var bulletArray:Array[Bullet] = []
|
var bulletArray:Array[Bullet] = []
|
||||||
var totalAllowedBullets:int = 7
|
var totalAllowedBullets:int = 7
|
||||||
|
var rocketArray:Array[Rocket] = []
|
||||||
|
var totalAllowedRockets:int = 3
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
@ -46,6 +48,8 @@ func pushTarget(body,pushDirection)->void:
|
|||||||
if body is RigidBody2D:
|
if body is RigidBody2D:
|
||||||
body.apply_central_impulse(pushDirection)
|
body.apply_central_impulse(pushDirection)
|
||||||
func destroy(body)->void:
|
func destroy(body)->void:
|
||||||
|
if body is Rocket:
|
||||||
|
print("removing rocket")
|
||||||
body.queue_free()
|
body.queue_free()
|
||||||
func teleportTarget(body)->void:
|
func teleportTarget(body)->void:
|
||||||
if body is Crate:
|
if body is Crate:
|
||||||
@ -74,9 +78,15 @@ func makeBullet(spawnPosition, speed)->void:
|
|||||||
myBullet.transform = spawnPosition
|
myBullet.transform = spawnPosition
|
||||||
myBullet.setSpeed(speed)
|
myBullet.setSpeed(speed)
|
||||||
|
|
||||||
|
func rocketFactory()->Rocket:
|
||||||
|
var myRocket:Rocket
|
||||||
|
myRocket = rocket.instantiate()
|
||||||
|
add_sibling(myRocket)
|
||||||
|
return myRocket
|
||||||
|
|
||||||
func makeRocket(spawnPosition, direction, speed)->void:
|
func makeRocket(spawnPosition, direction, speed)->void:
|
||||||
print("make a rocket")
|
print("make a rocket")
|
||||||
var myRocket = rocket.instantiate()
|
var myRocket:Rocket = rocketFactory()
|
||||||
add_sibling(myRocket)
|
myRocket.splodeSignal.connect(destroy)
|
||||||
myRocket.transform = spawnPosition
|
myRocket.transform = spawnPosition
|
||||||
pushTarget(myRocket,direction*speed)
|
pushTarget(myRocket,direction*speed)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user