feat: add new npc node; add interactable group to the project; add intreactable area to the player;

This commit is contained in:
2026-09-19 16:46:29 +02:00
parent 5b7c474f32
commit 5c3a533559
7 changed files with 122 additions and 11 deletions
+23 -6
View File
@@ -14,24 +14,30 @@ func _ready() -> void:
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta: float) -> void:
move_player()
push_blocks()
func move_player():
var move_vector: Vector2 = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
velocity = move_vector * move_speed
if velocity.x > 0:
$AnimatedSprite2D.play("move_right")
$Area2D.position = Vector2(5, 2)
elif velocity.x < 0:
$AnimatedSprite2D.play("move_left")
$Area2D.position = Vector2(-5, 2)
elif velocity.y > 0:
$AnimatedSprite2D.play("move_down")
$Area2D.position = Vector2(0, 8)
elif velocity.y < 0:
$AnimatedSprite2D.play("move_up")
$Area2D.position = Vector2(0, -4)
else:
$AnimatedSprite2D.stop()
# test
# get the last collision
# check if it's the block
# if it is the block then push it
func push_blocks():
var collision: KinematicCollision2D = get_last_slide_collision()
if collision:
var collisision_node = collision.get_collider()
@@ -40,4 +46,15 @@ func _physics_process(delta: float) -> void:
collisision_node.apply_central_force(-collision_normal * push_strength)
move_and_slide()
func _on_area_2d_body_entered(body: Node2D) -> void:
if body.is_in_group("interactable"):
body.can_interact = true
print("Able to intreact!")
func _on_area_2d_body_exited(body: Node2D) -> void:
if body.is_in_group("interactable"):
body.can_interact = false
print("Left interactable!")
+13
View File
@@ -142,6 +142,9 @@ animations = [{
radius = 5.0
height = 10.0
[sub_resource type="RectangleShape2D" id="RectangleShape2D_chgu2"]
size = Vector2(8, 8)
[node name="CharacterBody2D" type="CharacterBody2D" unique_id=1991398375]
collision_mask = 7
motion_mode = 1
@@ -154,3 +157,13 @@ animation = &"move_down"
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=129222135]
position = Vector2(0, 3)
shape = SubResource("CapsuleShape2D_bqpwv")
[node name="Area2D" type="Area2D" parent="." unique_id=145023444]
collision_layer = 2
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D" unique_id=775673729]
shape = SubResource("RectangleShape2D_chgu2")
debug_color = Color(0.9427947, 0.09120729, 0.5535774, 0.41960785)
[connection signal="body_entered" from="Area2D" to="." method="_on_area_2d_body_entered"]
[connection signal="body_exited" from="Area2D" to="." method="_on_area_2d_body_exited"]