added interaction system
This commit is contained in:
@@ -88,4 +88,4 @@ hotkey_fullscreen={
|
|||||||
[layer_names]
|
[layer_names]
|
||||||
|
|
||||||
2d_physics/layer_1="World"
|
2d_physics/layer_1="World"
|
||||||
2d_physics/layer_2="Dialog"
|
2d_physics/layer_2="Interactable"
|
||||||
|
@@ -3,6 +3,8 @@
|
|||||||
[ext_resource type="Script" path="res://src/scene-scripts/gui/dialog_trigger_area.cs" id="1_wosjw"]
|
[ext_resource type="Script" path="res://src/scene-scripts/gui/dialog_trigger_area.cs" id="1_wosjw"]
|
||||||
|
|
||||||
[node name="dialog_trigger_area" type="Area2D"]
|
[node name="dialog_trigger_area" type="Area2D"]
|
||||||
|
collision_layer = 2
|
||||||
|
collision_mask = 2
|
||||||
script = ExtResource("1_wosjw")
|
script = ExtResource("1_wosjw")
|
||||||
|
|
||||||
[node name="collision_shape_2d" type="CollisionShape2D" parent="."]
|
[node name="collision_shape_2d" type="CollisionShape2D" parent="."]
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
[gd_scene load_steps=6 format=3 uid="uid://ujfhvssvbgpg"]
|
[gd_scene load_steps=5 format=3 uid="uid://ujfhvssvbgpg"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://src/scene-scripts/player.cs" id="1_qehox"]
|
[ext_resource type="Script" path="res://src/scene-scripts/player.cs" id="1_qehox"]
|
||||||
[ext_resource type="Texture2D" uid="uid://ciidukjv5k6oa" path="res://assets/textures/debug/banana.png" id="2_1l1co"]
|
[ext_resource type="Texture2D" uid="uid://ciidukjv5k6oa" path="res://assets/textures/debug/banana.png" id="2_1l1co"]
|
||||||
@@ -15,8 +15,6 @@ animations = [{
|
|||||||
radius = 21.0
|
radius = 21.0
|
||||||
height = 66.0
|
height = 66.0
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_jpkwv"]
|
|
||||||
|
|
||||||
[node name="player" type="CharacterBody2D"]
|
[node name="player" type="CharacterBody2D"]
|
||||||
script = ExtResource("1_qehox")
|
script = ExtResource("1_qehox")
|
||||||
|
|
||||||
@@ -30,10 +28,7 @@ shape = SubResource("CapsuleShape2D_38v5o")
|
|||||||
current = true
|
current = true
|
||||||
zoom = Vector2(0.8, 0.8)
|
zoom = Vector2(0.8, 0.8)
|
||||||
|
|
||||||
[node name="interaction_area" type="Area2D" parent="."]
|
[node name="ray_cast_2d" type="RayCast2D" parent="."]
|
||||||
|
target_position = Vector2(0, 64)
|
||||||
[node name="interaction_collision" type="CollisionShape2D" parent="interaction_area"]
|
collision_mask = 2
|
||||||
position = Vector2(-2.27374e-13, 65)
|
collide_with_areas = true
|
||||||
rotation = 1.5708
|
|
||||||
scale = Vector2(3, 5)
|
|
||||||
shape = SubResource("CapsuleShape2D_jpkwv")
|
|
||||||
|
@@ -15,4 +15,4 @@ tile_set = ExtResource("2_kvjhj")
|
|||||||
cell_quadrant_size = 64
|
cell_quadrant_size = 64
|
||||||
format = 2
|
format = 2
|
||||||
layer_0/z_index = 1
|
layer_0/z_index = 1
|
||||||
layer_0/tile_data = PackedInt32Array(65535, 0, 0, 0, 0, 0, 1, 0, 0, 65534, 0, 0, 65533, 0, 0, -3, 0, 0, -2, 0, 0, -1, 0, 0, -65536, 0, 0, -65535, 0, 0, 65529, 1, 65536, 65530, 1, 65536, 65541, 1, 65536, -196605, 1, 65536)
|
layer_0/tile_data = PackedInt32Array(65535, 0, 0, 0, 0, 0, 1, 0, 0, 65534, 0, 0, 65533, 0, 0, -3, 0, 0, -2, 0, 0, -1, 0, 0, -65536, 0, 0, -65535, 0, 0, 65529, 1, 65536, 65541, 1, 65536, -196605, 1, 65536, 196603, 1, 65536)
|
||||||
|
@@ -8,7 +8,7 @@ public partial class dialog_trigger_area : Area2D
|
|||||||
string dialogFile;
|
string dialogFile;
|
||||||
|
|
||||||
public string currentKey = "randomWelcomeText";
|
public string currentKey = "randomWelcomeText";
|
||||||
public override void _Ready()
|
public void OnInteraction()
|
||||||
{
|
{
|
||||||
using var file = FileAccess.Open(dialogFile, FileAccess.ModeFlags.Read);
|
using var file = FileAccess.Open(dialogFile, FileAccess.ModeFlags.Read);
|
||||||
string text = file.GetAsText();
|
string text = file.GetAsText();
|
||||||
@@ -20,5 +20,4 @@ public partial class dialog_trigger_area : Area2D
|
|||||||
GD.Print(dialogPart[GD.Randi() % dialogPart.Length]);
|
GD.Print(dialogPart[GD.Randi() % dialogPart.Length]);
|
||||||
} else GD.Print(allDialog[currentKey]);
|
} else GD.Print(allDialog[currentKey]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -5,9 +5,6 @@ public partial class player : CharacterBody2D
|
|||||||
[Export]
|
[Export]
|
||||||
public int speed = 400;
|
public int speed = 400;
|
||||||
|
|
||||||
public override void _Ready()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
MoveAndCollide(new Vector2
|
MoveAndCollide(new Vector2
|
||||||
@@ -22,10 +19,14 @@ public partial class player : CharacterBody2D
|
|||||||
}
|
}
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
//rotates just interaction_area instead of whole player
|
//set ray_cast target position
|
||||||
if (Input.IsActionJustPressed("move_right")) GetNode<Area2D>("interaction_area").Rotation = Mathf.Pi / -2;
|
if (Input.IsActionJustPressed("move_right")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(64, 0);
|
||||||
if (Input.IsActionJustPressed("move_left")) GetNode<Area2D>("interaction_area").Rotation = Mathf.Pi / 2;
|
if (Input.IsActionJustPressed("move_left")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(-64, 0);
|
||||||
if (Input.IsActionJustPressed("move_down")) GetNode<Area2D>("interaction_area").Rotation = 0;
|
if (Input.IsActionJustPressed("move_down")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(0, 64);
|
||||||
if (Input.IsActionJustPressed("move_up")) GetNode<Area2D>("interaction_area").Rotation = Mathf.Pi;
|
if (Input.IsActionJustPressed("move_up")) GetNode<RayCast2D>("ray_cast_2d").TargetPosition = new Vector2(0, -64);
|
||||||
|
|
||||||
|
//call event in raycasted object
|
||||||
|
var raycastedObject = GetNode<RayCast2D>("ray_cast_2d").GetCollider();
|
||||||
|
if(Input.IsActionJustPressed("ui_accept") && raycastedObject!=null) raycastedObject.Call("OnInteraction");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user