feat: add enemy node; add player/enemy collision; add player hp to the scene manager; add hit by enemy logic;
This commit is contained in:
+17
-4
@@ -8,6 +8,7 @@ class_name Player
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
update_scrolls()
|
||||
print("HP: ", SceneManager.player_hp)
|
||||
var damage: float = 2
|
||||
if SceneManager.player_next_scene_spawn_pos != Vector2(0, 0):
|
||||
position = SceneManager.player_next_scene_spawn_pos
|
||||
@@ -26,16 +27,16 @@ func move_player():
|
||||
|
||||
if velocity.x > 0:
|
||||
$AnimatedSprite2D.play("move_right")
|
||||
$Area2D.position = Vector2(5, 2)
|
||||
$InteractArea2D.position = Vector2(5, 2)
|
||||
elif velocity.x < 0:
|
||||
$AnimatedSprite2D.play("move_left")
|
||||
$Area2D.position = Vector2(-5, 2)
|
||||
$InteractArea2D.position = Vector2(-5, 2)
|
||||
elif velocity.y > 0:
|
||||
$AnimatedSprite2D.play("move_down")
|
||||
$Area2D.position = Vector2(0, 8)
|
||||
$InteractArea2D.position = Vector2(0, 8)
|
||||
elif velocity.y < 0:
|
||||
$AnimatedSprite2D.play("move_up")
|
||||
$Area2D.position = Vector2(0, -4)
|
||||
$InteractArea2D.position = Vector2(0, -4)
|
||||
else:
|
||||
$AnimatedSprite2D.stop()
|
||||
|
||||
@@ -59,3 +60,15 @@ func _on_area_2d_body_entered(body: Node2D) -> void:
|
||||
func _on_area_2d_body_exited(body: Node2D) -> void:
|
||||
if body.is_in_group("interactable"):
|
||||
body.can_interact = false
|
||||
|
||||
|
||||
func _on_hit_box_area_2d_body_entered(body: Node2D) -> void:
|
||||
SceneManager.player_hp -= 1
|
||||
print("HP: ", SceneManager.player_hp)
|
||||
if SceneManager.player_hp <= 0:
|
||||
die()
|
||||
|
||||
func die():
|
||||
print("DED")
|
||||
get_tree().call_deferred("reload_current_scene")
|
||||
SceneManager.player_hp = 3
|
||||
|
||||
Reference in New Issue
Block a user