diff --git a/project.godot b/project.godot index b6df76d..b41f90b 100644 --- a/project.godot +++ b/project.godot @@ -88,4 +88,4 @@ hotkey_fullscreen={ [layer_names] 2d_physics/layer_1="World" -2d_physics/layer_2="Dialog" +2d_physics/layer_2="Interactable" diff --git a/scenes/gui/dialog_trigger_area.tscn b/scenes/gui/dialog_trigger_area.tscn index 508ee05..4655591 100644 --- a/scenes/gui/dialog_trigger_area.tscn +++ b/scenes/gui/dialog_trigger_area.tscn @@ -3,6 +3,8 @@ [ext_resource type="Script" path="res://src/scene-scripts/gui/dialog_trigger_area.cs" id="1_wosjw"] [node name="dialog_trigger_area" type="Area2D"] +collision_layer = 2 +collision_mask = 2 script = ExtResource("1_wosjw") [node name="collision_shape_2d" type="CollisionShape2D" parent="."] diff --git a/scenes/player.tscn b/scenes/player.tscn index bc8a65f..f2e2bbf 100644 --- a/scenes/player.tscn +++ b/scenes/player.tscn @@ -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="Texture2D" uid="uid://ciidukjv5k6oa" path="res://assets/textures/debug/banana.png" id="2_1l1co"] @@ -15,8 +15,6 @@ animations = [{ radius = 21.0 height = 66.0 -[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_jpkwv"] - [node name="player" type="CharacterBody2D"] script = ExtResource("1_qehox") @@ -30,10 +28,7 @@ shape = SubResource("CapsuleShape2D_38v5o") current = true zoom = Vector2(0.8, 0.8) -[node name="interaction_area" type="Area2D" parent="."] - -[node name="interaction_collision" type="CollisionShape2D" parent="interaction_area"] -position = Vector2(-2.27374e-13, 65) -rotation = 1.5708 -scale = Vector2(3, 5) -shape = SubResource("CapsuleShape2D_jpkwv") +[node name="ray_cast_2d" type="RayCast2D" parent="."] +target_position = Vector2(0, 64) +collision_mask = 2 +collide_with_areas = true diff --git a/scenes/worlds/first_world.tscn b/scenes/worlds/first_world.tscn index 88ed65b..536490c 100644 --- a/scenes/worlds/first_world.tscn +++ b/scenes/worlds/first_world.tscn @@ -15,4 +15,4 @@ tile_set = ExtResource("2_kvjhj") cell_quadrant_size = 64 format = 2 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) diff --git a/src/scene-scripts/gui/dialog_trigger_area.cs b/src/scene-scripts/gui/dialog_trigger_area.cs index d784309..cf4c085 100644 --- a/src/scene-scripts/gui/dialog_trigger_area.cs +++ b/src/scene-scripts/gui/dialog_trigger_area.cs @@ -8,7 +8,7 @@ public partial class dialog_trigger_area : Area2D string dialogFile; public string currentKey = "randomWelcomeText"; - public override void _Ready() + public void OnInteraction() { using var file = FileAccess.Open(dialogFile, FileAccess.ModeFlags.Read); string text = file.GetAsText(); @@ -20,5 +20,4 @@ public partial class dialog_trigger_area : Area2D GD.Print(dialogPart[GD.Randi() % dialogPart.Length]); } else GD.Print(allDialog[currentKey]); } - } diff --git a/src/scene-scripts/player.cs b/src/scene-scripts/player.cs index 18df842..70aad7f 100644 --- a/src/scene-scripts/player.cs +++ b/src/scene-scripts/player.cs @@ -5,9 +5,6 @@ public partial class player : CharacterBody2D [Export] public int speed = 400; - public override void _Ready() - { - } public override void _PhysicsProcess(double delta) { MoveAndCollide(new Vector2 @@ -22,10 +19,14 @@ public partial class player : CharacterBody2D } public override void _Process(double delta) { - //rotates just interaction_area instead of whole player - if (Input.IsActionJustPressed("move_right")) GetNode("interaction_area").Rotation = Mathf.Pi / -2; - if (Input.IsActionJustPressed("move_left")) GetNode("interaction_area").Rotation = Mathf.Pi / 2; - if (Input.IsActionJustPressed("move_down")) GetNode("interaction_area").Rotation = 0; - if (Input.IsActionJustPressed("move_up")) GetNode("interaction_area").Rotation = Mathf.Pi; + //set ray_cast target position + if (Input.IsActionJustPressed("move_right")) GetNode("ray_cast_2d").TargetPosition = new Vector2(64, 0); + if (Input.IsActionJustPressed("move_left")) GetNode("ray_cast_2d").TargetPosition = new Vector2(-64, 0); + if (Input.IsActionJustPressed("move_down")) GetNode("ray_cast_2d").TargetPosition = new Vector2(0, 64); + if (Input.IsActionJustPressed("move_up")) GetNode("ray_cast_2d").TargetPosition = new Vector2(0, -64); + + //call event in raycasted object + var raycastedObject = GetNode("ray_cast_2d").GetCollider(); + if(Input.IsActionJustPressed("ui_accept") && raycastedObject!=null) raycastedObject.Call("OnInteraction"); } }