feat: add new npc node; add interactable group to the project; add intreactable area to the player;
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
[ext_resource type="PackedScene" uid="uid://dfu6aj67vqwfn" path="res://Scenes/LockedDoor/locked_door.tscn" id="6_elpgg"]
|
[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="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://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"]
|
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_04h35"]
|
||||||
texture = ExtResource("1_l6yvh")
|
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/AAAAAAIAAA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ilnae")
|
tile_set = SubResource("TileSet_ilnae")
|
||||||
|
|
||||||
[node name="Player" parent="ObstacleLayer" unique_id=1991398375 instance=ExtResource("1_2p8i2")]
|
[node name="NPC" parent="ObstacleLayer" unique_id=687608910 groups=["interactable"] instance=ExtResource("10_g3lhp")]
|
||||||
push_strength = 100
|
position = Vector2(40, -29)
|
||||||
|
|
||||||
[node name="Camera2D" type="Camera2D" parent="ObstacleLayer/Player" unique_id=1335060572]
|
|
||||||
zoom = Vector2(5, 5)
|
|
||||||
|
|
||||||
[node name="SceneEntrance" parent="." unique_id=1734357035 instance=ExtResource("5_oi8ly")]
|
[node name="SceneEntrance" parent="." unique_id=1734357035 instance=ExtResource("5_oi8ly")]
|
||||||
position = Vector2(137, -107)
|
position = Vector2(137, -107)
|
||||||
@@ -817,5 +815,11 @@ script = ExtResource("7_nr542")
|
|||||||
position = Vector2(163, -75)
|
position = Vector2(163, -75)
|
||||||
lock_rotation = true
|
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="pressed" from="PuzzleButton" to="LockedDoor" method="_on_puzzle_button_pressed"]
|
||||||
[connection signal="unpressed" from="PuzzleButton" to="LockedDoor" method="_on_puzzle_button_unpressed"]
|
[connection signal="unpressed" from="PuzzleButton" to="LockedDoor" method="_on_puzzle_button_unpressed"]
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
uid://b54jmbhu1hrbt
|
||||||
@@ -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")
|
||||||
+23
-6
@@ -14,24 +14,30 @@ func _ready() -> void:
|
|||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||||
func _physics_process(delta: float) -> void:
|
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")
|
var move_vector: Vector2 = Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down")
|
||||||
velocity = move_vector * move_speed
|
velocity = move_vector * move_speed
|
||||||
|
|
||||||
if velocity.x > 0:
|
if velocity.x > 0:
|
||||||
$AnimatedSprite2D.play("move_right")
|
$AnimatedSprite2D.play("move_right")
|
||||||
|
$Area2D.position = Vector2(5, 2)
|
||||||
elif velocity.x < 0:
|
elif velocity.x < 0:
|
||||||
$AnimatedSprite2D.play("move_left")
|
$AnimatedSprite2D.play("move_left")
|
||||||
|
$Area2D.position = Vector2(-5, 2)
|
||||||
elif velocity.y > 0:
|
elif velocity.y > 0:
|
||||||
$AnimatedSprite2D.play("move_down")
|
$AnimatedSprite2D.play("move_down")
|
||||||
|
$Area2D.position = Vector2(0, 8)
|
||||||
elif velocity.y < 0:
|
elif velocity.y < 0:
|
||||||
$AnimatedSprite2D.play("move_up")
|
$AnimatedSprite2D.play("move_up")
|
||||||
|
$Area2D.position = Vector2(0, -4)
|
||||||
else:
|
else:
|
||||||
$AnimatedSprite2D.stop()
|
$AnimatedSprite2D.stop()
|
||||||
|
|
||||||
# test
|
|
||||||
# get the last collision
|
func push_blocks():
|
||||||
# check if it's the block
|
|
||||||
# if it is the block then push it
|
|
||||||
var collision: KinematicCollision2D = get_last_slide_collision()
|
var collision: KinematicCollision2D = get_last_slide_collision()
|
||||||
if collision:
|
if collision:
|
||||||
var collisision_node = collision.get_collider()
|
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)
|
collisision_node.apply_central_force(-collision_normal * push_strength)
|
||||||
|
|
||||||
move_and_slide()
|
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!")
|
||||||
|
|||||||
@@ -142,6 +142,9 @@ animations = [{
|
|||||||
radius = 5.0
|
radius = 5.0
|
||||||
height = 10.0
|
height = 10.0
|
||||||
|
|
||||||
|
[sub_resource type="RectangleShape2D" id="RectangleShape2D_chgu2"]
|
||||||
|
size = Vector2(8, 8)
|
||||||
|
|
||||||
[node name="CharacterBody2D" type="CharacterBody2D" unique_id=1991398375]
|
[node name="CharacterBody2D" type="CharacterBody2D" unique_id=1991398375]
|
||||||
collision_mask = 7
|
collision_mask = 7
|
||||||
motion_mode = 1
|
motion_mode = 1
|
||||||
@@ -154,3 +157,13 @@ animation = &"move_down"
|
|||||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=129222135]
|
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=129222135]
|
||||||
position = Vector2(0, 3)
|
position = Vector2(0, 3)
|
||||||
shape = SubResource("CapsuleShape2D_bqpwv")
|
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"]
|
||||||
|
|||||||
@@ -27,6 +27,16 @@ window/stretch/mode="canvas_items"
|
|||||||
|
|
||||||
wall="A wall tilemap layer"
|
wall="A wall tilemap layer"
|
||||||
pushable="A pushuable object"
|
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]
|
[layer_names]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user