diff --git a/Assets/Objects/Robot.glb b/Assets/Objects/Robot.glb index 943d273..c839f86 100644 Binary files a/Assets/Objects/Robot.glb and b/Assets/Objects/Robot.glb differ diff --git a/Game.tscn b/Game.tscn index 9c82753..d0d9037 100644 --- a/Game.tscn +++ b/Game.tscn @@ -3,6 +3,7 @@ [ext_resource type="Script" uid="uid://br2udyi6t8yvf" path="res://Scripts/World.cs" id="1_xkndl"] [ext_resource type="Script" uid="uid://dqrdb3bvws6b6" path="res://Scripts/SteamworksHandler.cs" id="2_xkndl"] [ext_resource type="Script" uid="uid://c7khr6oist3ku" path="res://Scripts/Camera3d.cs" id="3_u44n3"] +[ext_resource type="Script" uid="uid://bm7knir4552j5" path="res://Scripts/Helpers/UIHandler.cs" id="4_sb48q"] [sub_resource type="CompressedTexture2D" id="CompressedTexture2D_u44n3"] @@ -16,6 +17,7 @@ sky_material = SubResource("PanoramaSkyMaterial_u44n3") background_mode = 1 background_color = Color(0.27141052, 0.1874483, 0.13788113, 1) sky = SubResource("Sky_u44n3") +glow_enabled = true [node name="Main" type="Node3D" unique_id=234207355] @@ -32,3 +34,43 @@ script = ExtResource("3_u44n3") [node name="WorldEnvironment" type="WorldEnvironment" parent="." unique_id=377970686] environment = SubResource("Environment_sb48q") + +[node name="Control" type="Control" parent="." unique_id=1713248285] +layout_mode = 3 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_right = -2.0 +offset_bottom = 2.0 +grow_horizontal = 2 +grow_vertical = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 +script = ExtResource("4_sb48q") + +[node name="CodingWindow" type="Panel" parent="Control" unique_id=1765248892] +layout_mode = 1 +anchors_preset = 11 +anchor_left = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = -500.0 +grow_horizontal = 0 +grow_vertical = 2 + +[node name="Button" type="Button" parent="Control/CodingWindow" unique_id=2015284121] +layout_mode = 0 +offset_left = 100.0 +offset_top = 600.0 +offset_right = 400.0 +offset_bottom = 635.0 +text = "Move" + +[node name="PositionInput" type="LineEdit" parent="Control/CodingWindow" unique_id=1834676849] +layout_mode = 0 +offset_left = 125.0 +offset_top = 50.0 +offset_right = 375.0 +offset_bottom = 85.0 +placeholder_text = "Position... (X/Y OR X,Y)" +alignment = 1 diff --git a/Prefabs/Robot.tscn b/Prefabs/Robot.tscn index a1faeac..81ca16b 100644 --- a/Prefabs/Robot.tscn +++ b/Prefabs/Robot.tscn @@ -1,5 +1,17 @@ -[gd_scene format=3 uid="uid://cjae60v4c60vb"] +[gd_scene format=3 uid="uid://dciwxejdji2lg"] -[ext_resource type="PackedScene" uid="uid://bccs6xik7xv8s" path="res://Assets/Objects/Robot.glb" id="1_8peeh"] +[ext_resource type="PackedScene" uid="uid://cjae60v4c60vb" path="res://Prefabs/RobotVisual.tscn" id="2_3hvm5"] +[ext_resource type="Script" uid="uid://e0pgy7jya41y" path="res://Scripts/Robot.cs" id="2_j80uv"] -[node name="Robot" unique_id=1113392384 instance=ExtResource("1_8peeh")] +[sub_resource type="BoxShape3D" id="BoxShape3D_vquur"] +size = Vector3(1.1176758, 0.7307129, 1.0234375) + +[node name="RobotBase" type="CharacterBody3D" unique_id=2075379542] +collision_layer = 2 +script = ExtResource("2_j80uv") + +[node name="RobotVisual" parent="." unique_id=516119901 instance=ExtResource("2_3hvm5")] + +[node name="CollisionShape3D" type="CollisionShape3D" parent="." unique_id=1405728816] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -0.05883789, 0.29821777, -0.01171875) +shape = SubResource("BoxShape3D_vquur") diff --git a/Prefabs/RobotVisual.tscn b/Prefabs/RobotVisual.tscn new file mode 100644 index 0000000..e9aba3f --- /dev/null +++ b/Prefabs/RobotVisual.tscn @@ -0,0 +1,5 @@ +[gd_scene format=3 uid="uid://cjae60v4c60vb"] + +[ext_resource type="PackedScene" uid="uid://bccs6xik7xv8s" path="res://Assets/Objects/Robot.glb" id="1_wvvfd"] + +[node name="Robot" unique_id=516119901 instance=ExtResource("1_wvvfd")] diff --git a/Scripts/Camera3d.cs b/Scripts/Camera3d.cs index bf5968a..2b0ea57 100644 --- a/Scripts/Camera3d.cs +++ b/Scripts/Camera3d.cs @@ -36,4 +36,42 @@ public partial class Camera3d : Camera3D Position = new Vector3(Position.X, 10 - visibleLayer * 4, Position.Z); } } + + public override void _Input(InputEvent @event) + { + if (@event is InputEventMouseButton mouse && + mouse.ButtonIndex == MouseButton.Left && + mouse.Pressed) + { + var camera = GetViewport().GetCamera3D(); + + Vector2 mousePos = mouse.Position; + + Vector3 from = camera.ProjectRayOrigin(mousePos); + Vector3 to = from + camera.ProjectRayNormal(mousePos) * 1000f; + + var spaceState = GetWorld3D().DirectSpaceState; + + var query = PhysicsRayQueryParameters3D.Create(from, to); + + query.CollisionMask = 1 << 1; + + var result = spaceState.IntersectRay(query); + + if (result.Count > 0) + { + Variant colliderVariant = result["collider"]; + + Node hit = colliderVariant.As(); + + GD.Print($"Clicked robot: {hit.Name}"); + + // Optional: call method on robot + if (hit is Node robot) + { + robot.Call("OnClicked"); + } + } + } + } } diff --git a/Scripts/Helpers/GameData.cs b/Scripts/Helpers/GameData.cs index 1d4eff2..e6f37d3 100644 --- a/Scripts/Helpers/GameData.cs +++ b/Scripts/Helpers/GameData.cs @@ -8,5 +8,7 @@ public partial class GameData public static int currentLayer = 0; //The layer that is currently visible public static int visibleLayer = 0; + //Determines if the player can move the camera or not (Necessary for input and options menu) + public static bool canMove = true; } diff --git a/Scripts/Helpers/UIHandler.cs b/Scripts/Helpers/UIHandler.cs new file mode 100644 index 0000000..2f72bd5 --- /dev/null +++ b/Scripts/Helpers/UIHandler.cs @@ -0,0 +1,19 @@ +using Godot; + +public partial class UIHandler : Control +{ + public override void _Ready() + { + + } + + // Called every frame. 'delta' is the elapsed time since the previous frame. + public override void _Process(double delta) + { + if (Input.IsActionJustPressed("codingwindow")) + { + GetNode("./CodingWindow").Visible = !GetNode("./CodingWindow").Visible; + } + } + +} diff --git a/Scripts/Helpers/UIHandler.cs.uid b/Scripts/Helpers/UIHandler.cs.uid new file mode 100644 index 0000000..6ae2d27 --- /dev/null +++ b/Scripts/Helpers/UIHandler.cs.uid @@ -0,0 +1 @@ +uid://bm7knir4552j5 diff --git a/Scripts/Robot.cs b/Scripts/Robot.cs new file mode 100644 index 0000000..64b6c9d --- /dev/null +++ b/Scripts/Robot.cs @@ -0,0 +1,14 @@ +using Godot; + +public partial class Robot : Node3D +{ + public void Move() + { + + } + + public void OnClicked() + { + GD.Print("Test!"); + } +} diff --git a/Scripts/Robot.cs.uid b/Scripts/Robot.cs.uid new file mode 100644 index 0000000..bc84dea --- /dev/null +++ b/Scripts/Robot.cs.uid @@ -0,0 +1 @@ +uid://e0pgy7jya41y diff --git a/Scripts/World.cs b/Scripts/World.cs index 654f799..c5f088a 100644 --- a/Scripts/World.cs +++ b/Scripts/World.cs @@ -16,12 +16,6 @@ public partial class World : Node3D Layer layerNode; private MultiMeshHandler multiMeshHandler; - FastNoiseLite noise = new FastNoiseLite() - { - NoiseType = FastNoiseLite.NoiseTypeEnum.Perlin, - Frequency = 0.05f, - Seed = 1337 - }; public override void _Ready() { @@ -90,6 +84,13 @@ public partial class World : Node3D HandleRenderData(BuildRenderData(currentLayer)); visibleLayer = currentLayer; } + + if (Input.IsActionJustPressed("spawn_robot")) + { + Robot robot = ResourceLoader.LoadRobotPrefab().Instantiate(); + robot.Position = map[0].tiles[1,1].Position; + AddChild(robot); + } } private void GenerateWorld() diff --git a/project.godot b/project.godot index e0b9b32..f25e0d0 100644 --- a/project.godot +++ b/project.godot @@ -70,11 +70,22 @@ sprint={ "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":4194325,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } +spawn_robot={ +"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":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null) +] +} +codingwindow={ +"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":67,"key_label":0,"unicode":99,"location":0,"echo":false,"script":null) +] +} [layer_names] 2d_render/layer_1="BackgroundUI" 2d_render/layer_2="World" +3d_physics/layer_2="Robots" [steam]