Kaynağa Gözat

Make the player able to die

DricomDragon 5 yıl önce
ebeveyn
işleme
0333be48b3
2 değiştirilmiş dosya ile 14 ekleme ve 1 silme
  1. 13 1
      Player.gd
  2. 1 0
      Player.tscn

+ 13 - 1
Player.gd

@@ -1,11 +1,17 @@
 extends Area2D
 
+signal hit
+
 export var speed = 400 # pixel / sec
 var screen
 
 func spawn():
-	show()
 	position = (screen.position + screen.end) / 2
+	show()
+	$CollisionShape2D.disabled = false
+
+func die():
+	hide()
 
 func _ready():
 	hide()
@@ -40,3 +46,9 @@ func _process(delta):
 	elif velocity.y != 0:
 		$AnimatedSprite.animation = "up"
 		$AnimatedSprite.flip_v = velocity.y > 0
+
+
+func _on_Player_body_entered(body):
+	die()
+	emit_signal("hit")
+	$CollisionShape2D.set_deferred("disabled", true)

+ 1 - 0
Player.tscn

@@ -39,3 +39,4 @@ __meta__ = {
 
 [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
 shape = SubResource( 2 )
+[connection signal="body_entered" from="." to="." method="_on_Player_body_entered"]