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
+9 -5
View File
@@ -9,6 +9,7 @@
[ext_resource type="PackedScene" uid="uid://dfu6aj67vqwfn" path="res://Scenes/LockedDoor/locked_door.tscn" id="6_elpgg"]
[ext_resource type="Script" uid="uid://decx4kt8ftrb5" path="res://Scenes/LockedDoor/locked_door.gd" id="7_nr542"]
[ext_resource type="PackedScene" uid="uid://onpen57mc6i8" path="res://Scenes/PuzzleButton/puzzle_button.tscn" id="7_ohrk8"]
[ext_resource type="PackedScene" uid="uid://dsb83tlcapw8l" path="res://Scenes/NPC/npc.tscn" id="10_g3lhp"]
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_04h35"]
texture = ExtResource("1_l6yvh")
@@ -800,11 +801,8 @@ y_sort_enabled = true
tile_map_data = PackedByteArray("AAAIAP7/AAAAAAIAAAAKAP3/AAAAAAIAAAAMAP7/AAAAAAIAAAAIAP//AAAAAAIAAAALAAAAAAAAAAIAAAAIAAEAAAAAAAIAAAALAAIAAAAAAAIAAAACAAQAAAAAAAIAAAAFAAMAAAAAAAIAAAAFAAUAAAAAAAIAAAAHAAMAAAAAAAIAAAAIAAQAAAAAAAIAAAAJAAMAAAAAAAIAAAALAAQAAAAAAAIAAAD///f/AAAAAAIAAAD///j/AAAAAAIAAAD///n/AAAAAAIAAAACAPf/AAAAAAIAAAACAPj/AAAAAAIAAAACAPn/AAAAAAIAAAAAAPr/AAAAAAIAAAAEAPr/AAAAAAIAAAD8//f/AAAAAAIAAAD5//f/AAAAAAIAAAD2//f/AAAAAAIAAADz//f/AAAAAAIAAAD1//b/AAAAAAIAAAD3//b/AAAAAAIAAAD5//b/AAAAAAIAAAD8//b/AAAAAAIAAAABAPb/AAAAAAIAAAAEAPX/AAAAAAIAAAADAPb/AAAAAAIAAAAHAPX/AAAAAAIAAAAKAPX/AAAAAAIAAAANAPb/AAAAAAIAAAANAPf/AAAAAAIAAAANAPj/AAAAAAIAAAANAPz/AAAAAAIAAAANAPv/AAAAAAIAAAAIAPn/AQAAAAcAAAA=")
tile_set = SubResource("TileSet_ilnae")
[node name="Player" parent="ObstacleLayer" unique_id=1991398375 instance=ExtResource("1_2p8i2")]
push_strength = 100
[node name="Camera2D" type="Camera2D" parent="ObstacleLayer/Player" unique_id=1335060572]
zoom = Vector2(5, 5)
[node name="NPC" parent="ObstacleLayer" unique_id=687608910 groups=["interactable"] instance=ExtResource("10_g3lhp")]
position = Vector2(40, -29)
[node name="SceneEntrance" parent="." unique_id=1734357035 instance=ExtResource("5_oi8ly")]
position = Vector2(137, -107)
@@ -817,5 +815,11 @@ script = ExtResource("7_nr542")
position = Vector2(163, -75)
lock_rotation = true
[node name="Player" parent="." unique_id=1991398375 instance=ExtResource("1_2p8i2")]
push_strength = 100
[node name="Camera2D" type="Camera2D" parent="Player" unique_id=1335060572]
zoom = Vector2(5, 5)
[connection signal="pressed" from="PuzzleButton" to="LockedDoor" method="_on_puzzle_button_pressed"]
[connection signal="unpressed" from="PuzzleButton" to="LockedDoor" method="_on_puzzle_button_unpressed"]
+11
View File
@@ -0,0 +1,11 @@
extends StaticBody2D
var can_interact: bool = false
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
if Input.is_action_just_pressed("Interact") and can_interact:
if $CanvasLayer.visible == false:
$CanvasLayer.visible = true
else:
$CanvasLayer.visible = false
+1
View File
@@ -0,0 +1 @@
uid://b54jmbhu1hrbt
+55
View File
@@ -0,0 +1,55 @@
[gd_scene format=3 uid="uid://dsb83tlcapw8l"]
[ext_resource type="Texture2D" uid="uid://by4iu18wmj6ui" path="res://Ninja Adventure - Asset Pack/Actor/Characters/NinjaBlue/SpriteSheet.png" id="1_3am0f"]
[ext_resource type="Script" uid="uid://b54jmbhu1hrbt" path="res://Scenes/NPC/npc.gd" id="1_bjna2"]
[ext_resource type="Texture2D" uid="uid://ctpnixa3dpms5" path="res://Ninja Adventure - Asset Pack/Ui/Dialog/DialogBoxFaceset.png" id="3_0s07e"]
[ext_resource type="Texture2D" uid="uid://cn881vxquv6ub" path="res://Ninja Adventure - Asset Pack/Actor/Characters/NinjaBlue/Faceset.png" id="4_aqj1y"]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_chgu2"]
size = Vector2(14, 13)
[sub_resource type="AtlasTexture" id="AtlasTexture_chgu2"]
atlas = ExtResource("1_3am0f")
region = Rect2(0, 0, 16, 16)
[sub_resource type="LabelSettings" id="LabelSettings_0s07e"]
font_size = 48
font_color = Color(0, 0, 0, 1)
[node name="NPC" type="StaticBody2D" unique_id=687608910]
script = ExtResource("1_bjna2")
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1581401512]
position = Vector2(0, 0.5)
shape = SubResource("RectangleShape2D_chgu2")
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=2127209036]
texture = SubResource("AtlasTexture_chgu2")
[node name="CanvasLayer" type="CanvasLayer" parent="." unique_id=1510478417]
visible = false
[node name="TextureRect" type="TextureRect" parent="CanvasLayer" unique_id=2039853714]
offset_left = 428.0
offset_top = 498.0
offset_right = 728.0
offset_bottom = 556.0
offset_transform_enabled = true
offset_transform_scale = Vector2(3.7, 3.7)
texture = ExtResource("3_0s07e")
[node name="TextureRect" type="TextureRect" parent="CanvasLayer/TextureRect" unique_id=1385209557]
layout_mode = 0
offset_left = 5.0
offset_top = 14.0
offset_right = 45.0
offset_bottom = 54.0
texture = ExtResource("4_aqj1y")
[node name="Label" type="Label" parent="CanvasLayer" unique_id=439922902]
offset_left = 208.0
offset_top = 472.0
offset_right = 492.0
offset_bottom = 539.0
text = "Hello World!"
label_settings = SubResource("LabelSettings_0s07e")
+21 -4
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()
@@ -41,3 +47,14 @@ func _physics_process(delta: float) -> void:
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"]
+10
View File
@@ -27,6 +27,16 @@ window/stretch/mode="canvas_items"
wall="A wall tilemap layer"
pushable="A pushuable object"
interactable="An interactable node"
[input]
Interact={
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":88,"key_label":0,"unicode":120,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
]
}
[layer_names]