working bullets
This commit is contained in:
1 parent
e50ead9360
commit
614fc9860b
5 files changed
+27
-9
No files matched your search
@@ -15,4 +15,10 @@ func _physics_process(delta: float) -> void:
|
||||
position += transform.x * speed * delta
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
print("I done hit somethin")
|
||||
if body is Enemy:
|
||||
print("blow away enemy")
|
||||
|
||||
func _on_area_entered(area: Area2D) -> void:
|
||||
if area is Enemy:
|
||||
print("blow this enemy away")
|
||||
hit.emit(self, area)
|
||||
@@ -28,14 +28,14 @@ var punchTarget:Enemy
|
||||
var bullet = preload("res://scenes/bullet.tscn")
|
||||
|
||||
func killPlayer():
|
||||
print("kill the player")
|
||||
|
||||
if living:
|
||||
living = false
|
||||
#play death animation
|
||||
animPlaying="death"
|
||||
playerSprite.play(animPlaying)
|
||||
func hurtPlayer(currentHealth):
|
||||
print("current health is : "+str(currentHealth))
|
||||
|
||||
animPlaying="hurt"
|
||||
playerSprite.play(animPlaying)
|
||||
|
||||
@@ -112,7 +112,7 @@ func _physics_process(delta: float) -> void:
|
||||
pushLeftEnabled = true
|
||||
pushTarget = collider
|
||||
if collider is Enemy:
|
||||
print("I can punch on left")
|
||||
|
||||
punchTarget = collider
|
||||
punchLeftEnabled = true
|
||||
else:
|
||||
@@ -127,7 +127,7 @@ func _physics_process(delta: float) -> void:
|
||||
pushRightEnabled = true
|
||||
pushTarget = collider
|
||||
if collider is Enemy:
|
||||
print("I can punch on the right")
|
||||
|
||||
punchTarget = collider
|
||||
punchRightEnabled = true
|
||||
else:
|
||||
@@ -136,7 +136,7 @@ func _physics_process(delta: float) -> void:
|
||||
|
||||
|
||||
func _on_animation_finished() -> void:
|
||||
print("animation finished "+animPlaying)
|
||||
|
||||
if animPlaying=="hurt":
|
||||
animPlaying="idle"
|
||||
if animPlaying=="death":
|
||||
|
||||
@@ -51,6 +51,7 @@ func bulletFactory():
|
||||
myBullet = bullet.instantiate()
|
||||
owner.add_child(myBullet)
|
||||
#or....recycles bullets
|
||||
myBullet.visible = true
|
||||
return myBullet
|
||||
|
||||
func placeBullet(speed, markerpos):
|
||||
@@ -63,6 +64,17 @@ func placeBullet(speed, markerpos):
|
||||
# set the position of the bullet
|
||||
myBullet.transform = markerpos
|
||||
# make the bullet visible by adding it
|
||||
myBullet.hit.connect(bulletHit)
|
||||
|
||||
func bulletHit(bullet, body):
|
||||
print("bullet hit a target")
|
||||
body.queue_free()
|
||||
bullet.setSpeed(0)
|
||||
bullet.visible = false
|
||||
|
||||
func spendBullet():
|
||||
#place a spent bullet back in the pool
|
||||
pass
|
||||
|
||||
func crateFactory():
|
||||
var myCrate = crate.instantiate()
|
||||
|
||||
Reference in new issue
Block a user