diff --git a/scenes/level.tscn b/scenes/Levels/level.tscn similarity index 73% rename from scenes/level.tscn rename to scenes/Levels/level.tscn index 62bc598..747bdee 100644 --- a/scenes/level.tscn +++ b/scenes/Levels/level.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=9 format=3 uid="uid://dchj6g2i8ebph"] +[gd_scene load_steps=10 format=3 uid="uid://dchj6g2i8ebph"] -[ext_resource type="Script" uid="uid://bpxggc8nr6tf6" path="res://scenes/player.gd" id="2_w7c3h"] +[ext_resource type="Script" uid="uid://bpxggc8nr6tf6" path="res://scenes/player.gd" id="1_muv8p"] +[ext_resource type="PackedScene" uid="uid://c5of6aaxop1hl" path="res://scenes/block.tscn" id="2_tc7dm"] [sub_resource type="PhysicsMaterial" id="PhysicsMaterial_2q6dc"] bounce = 0.5 @@ -39,14 +40,14 @@ mesh = SubResource("SphereMesh_w7c3h") [node name="Player" type="RigidBody3D" parent="."] physics_material_override = SubResource("PhysicsMaterial_w8frs") -gravity_scale = 0.0 -script = ExtResource("2_w7c3h") +script = ExtResource("1_muv8p") +camera_path = NodePath("Camera3D") [node name="CollisionShape3D" type="CollisionShape3D" parent="Player"] shape = SubResource("SphereShape3D_mx8sn") [node name="Camera3D" type="Camera3D" parent="Player"] -transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0) +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.31670225, 0) [node name="Ground" type="StaticBody3D" parent="."] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0) @@ -60,3 +61,11 @@ mesh = SubResource("BoxMesh_w7c3h") [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] transform = Transform3D(1, 0, 0, 0, 0.5, 0.8660253, 0, -0.8660253, 0.5, 0, 34, 0) shadow_enabled = true + +[node name="Starter Blocks" type="Node3D" parent="."] + +[node name="Block" parent="Starter Blocks" instance=ExtResource("2_tc7dm")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.298158, -7.0724635) + +[node name="Block2" parent="Starter Blocks" instance=ExtResource("2_tc7dm")] +transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.63255787, 2.596316, -6.980046) diff --git a/scenes/Settings.gd b/scenes/UI/Settings.gd similarity index 70% rename from scenes/Settings.gd rename to scenes/UI/Settings.gd index eb07472..dcb6380 100644 --- a/scenes/Settings.gd +++ b/scenes/UI/Settings.gd @@ -2,4 +2,4 @@ extends Node func _input(event): if event.is_action_pressed("ui_cancel"): # 'ui_cancel' is a built-in action defined in Project > Project Settings > Input Map - get_tree().change_scene_to_file("res://scenes/start_screen.tscn") + get_tree().change_scene_to_file("uid://b4k81taauef4q") diff --git a/scenes/Settings.gd.uid b/scenes/UI/Settings.gd.uid similarity index 100% rename from scenes/Settings.gd.uid rename to scenes/UI/Settings.gd.uid diff --git a/scenes/Settings.tscn b/scenes/UI/Settings.tscn similarity index 97% rename from scenes/Settings.tscn rename to scenes/UI/Settings.tscn index 519f01b..71eabce 100644 --- a/scenes/Settings.tscn +++ b/scenes/UI/Settings.tscn @@ -1,10 +1,11 @@ [gd_scene load_steps=5 format=3 uid="uid://d3tqrm4ry4l88"] -[ext_resource type="Script" uid="uid://h1slqbemgwvr" path="res://scenes/Settings.gd" id="1_1dggd"] +[ext_resource type="Script" uid="uid://h1slqbemgwvr" path="res://scenes/UI/Settings.gd" id="1_1dggd"] [ext_resource type="Texture2D" uid="uid://dhuosr0p605gj" path="res://assets/images/pp_start_bg.png" id="1_i47rn"] [ext_resource type="FontFile" uid="uid://m5ceou0rk6j6" path="res://assets/fonts/PlayfairDisplay-VariableFont_wght.ttf" id="2_46duy"] [ext_resource type="Theme" uid="uid://wpxmub0n2dr3" path="res://themes/button_theme.tres" id="3_46duy"] + [node name="settings_screen" type="Node2D"] script = ExtResource("1_1dggd") metadata/_edit_vertical_guides_ = [1152.0] diff --git a/scenes/start_screen.gd b/scenes/UI/start_screen.gd similarity index 53% rename from scenes/start_screen.gd rename to scenes/UI/start_screen.gd index 679568c..6470fce 100644 --- a/scenes/start_screen.gd +++ b/scenes/UI/start_screen.gd @@ -2,10 +2,10 @@ extends Control func _on_start_button_pressed(): - get_tree().change_scene_to_file("res://scenes/level.tscn") + get_tree().change_scene_to_file("uid://dchj6g2i8ebph") func _on_settings_button_pressed(): - get_tree().change_scene_to_file("res://scenes/Settings.tscn") + get_tree().change_scene_to_file("uid://d3tqrm4ry4l88") func _on_quit_button_pressed(): get_tree().quit() diff --git a/scenes/start_screen.gd.uid b/scenes/UI/start_screen.gd.uid similarity index 100% rename from scenes/start_screen.gd.uid rename to scenes/UI/start_screen.gd.uid diff --git a/scenes/start_screen.tscn b/scenes/UI/start_screen.tscn similarity index 98% rename from scenes/start_screen.tscn rename to scenes/UI/start_screen.tscn index c683b3f..fac67b3 100644 --- a/scenes/start_screen.tscn +++ b/scenes/UI/start_screen.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=5 format=3 uid="uid://b4k81taauef4q"] -[ext_resource type="Script" uid="uid://cc8lskf7y74kh" path="res://scenes/start_screen.gd" id="1_o7i0r"] +[ext_resource type="Script" uid="uid://cc8lskf7y74kh" path="res://scenes/UI/start_screen.gd" id="1_o7i0r"] [ext_resource type="Theme" uid="uid://wpxmub0n2dr3" path="res://themes/button_theme.tres" id="1_tx5wa"] [ext_resource type="Texture2D" uid="uid://dhuosr0p605gj" path="res://assets/images/pp_start_bg.png" id="2_r2jwc"] [ext_resource type="Theme" uid="uid://tn8qndst18d6" path="res://themes/title_font_theme.tres" id="4_hm208"] diff --git a/scenes/block.tscn b/scenes/block.tscn new file mode 100644 index 0000000..3e1244e --- /dev/null +++ b/scenes/block.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=4 format=3 uid="uid://c5of6aaxop1hl"] + +[sub_resource type="BoxShape3D" id="BoxShape3D_4du60"] + +[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_alp5v"] +albedo_color = Color(0.290196, 0.698039, 0.227451, 1) + +[sub_resource type="BoxMesh" id="BoxMesh_kryjk"] +material = SubResource("StandardMaterial3D_alp5v") + +[node name="Block" type="Node3D"] + +[node name="RigidBody3D" type="RigidBody3D" parent="."] +collision_layer = 3 +collision_mask = 3 + +[node name="CollisionShape3D" type="CollisionShape3D" parent="RigidBody3D"] +shape = SubResource("BoxShape3D_4du60") + +[node name="MeshInstance3D" type="MeshInstance3D" parent="RigidBody3D"] +mesh = SubResource("BoxMesh_kryjk") diff --git a/scenes/player.gd b/scenes/player.gd index c70aa30..d13f07f 100644 --- a/scenes/player.gd +++ b/scenes/player.gd @@ -1,16 +1,52 @@ extends RigidBody3D -# Initially I used a CharacterBody3D, however, I wanted the player to bounce off -# other objects in the environment and that would have required manual handling -# of collisions. So that's why we're using a RigidBody3D instead. +const MOVE_SPEED := 8.0 +const ACCELLERATION := 30.0 +const DECELLERATION := 40.0 +const JUMP_SPEED := 4.0 -const ACCELLERATION = 5.0 +@export var camera_path: NodePath +@onready var cam: Camera3D = get_node(camera_path) if camera_path != NodePath("") else null -func _integrate_forces(state): - var input_dir = Vector3.ZERO - input_dir.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left") - input_dir.z = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up") - input_dir = input_dir.normalized() +func _ready() -> void: + axis_lock_angular_x = true + axis_lock_angular_z = true + angular_damp = 6.0 + contact_monitor = true + max_contacts_reported = 4 - linear_velocity.x += input_dir.x * (ACCELLERATION * state.step) - linear_velocity.z += input_dir.z * (ACCELLERATION * state.step) +func _integrate_forces(state): + # Input as 2D vector + var input2v := Input.get_vector("ui_left", "ui_right", "ui_up", "ui_down") + + # Camera based movement + var forward := Vector3.FORWARD * -1.0 + var right := Vector3.RIGHT + if cam: + forward = cam.global_transform.basis.z + right = cam.global_transform.basis.x + # project onto ground plane so looking up/down doesn't tilt movement + forward.y = 0.0 + right.y = 0.0 + if forward.length() > 0.0001: + forward = forward.normalized() + if right.length() > 0.0001: + right = right.normalized() + + var dir := (right * input2v.x + forward * input2v.y).normalized() + var target_v := dir * MOVE_SPEED + + var ax := ACCELLERATION if dir != Vector3.ZERO else DECELLERATION + linear_velocity.x = move_toward(linear_velocity.x, target_v.x, ax * state.step) + linear_velocity.z = move_toward(linear_velocity.z, target_v.z, ax * state.step) + + # Jump Logic + var on_floor = false + for i in state.get_contact_count(): + var normal = state.get_contact_local_normal(i) + if normal.y > 0.5: + on_floor = true + break + + if on_floor and Input.is_action_just_pressed("ui_accept"): + linear_velocity.y = JUMP_SPEED