2 Commits
11 changed files with 155 additions and 19 deletions
+55 -5
View File
@@ -1,6 +1,8 @@
[gd_scene load_steps=9 format=3 uid="uid://dchj6g2i8ebph"] [gd_scene load_steps=11 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"]
[ext_resource type="Script" uid="uid://b7fopt7sx74g8" path="res://scenes/Levels/menu.gd" id="3_tc7dm"]
[sub_resource type="PhysicsMaterial" id="PhysicsMaterial_2q6dc"] [sub_resource type="PhysicsMaterial" id="PhysicsMaterial_2q6dc"]
bounce = 0.5 bounce = 0.5
@@ -39,14 +41,14 @@ mesh = SubResource("SphereMesh_w7c3h")
[node name="Player" type="RigidBody3D" parent="."] [node name="Player" type="RigidBody3D" parent="."]
physics_material_override = SubResource("PhysicsMaterial_w8frs") physics_material_override = SubResource("PhysicsMaterial_w8frs")
gravity_scale = 0.0 script = ExtResource("1_muv8p")
script = ExtResource("2_w7c3h") camera_path = NodePath("Camera3D")
[node name="CollisionShape3D" type="CollisionShape3D" parent="Player"] [node name="CollisionShape3D" type="CollisionShape3D" parent="Player"]
shape = SubResource("SphereShape3D_mx8sn") shape = SubResource("SphereShape3D_mx8sn")
[node name="Camera3D" type="Camera3D" parent="Player"] [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="."] [node name="Ground" type="StaticBody3D" parent="."]
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, -1, 0)
@@ -60,3 +62,51 @@ mesh = SubResource("BoxMesh_w7c3h")
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."] [node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.5, 0.8660253, 0, -0.8660253, 0.5, 0, 34, 0) transform = Transform3D(1, 0, 0, 0, 0.5, 0.8660253, 0, -0.8660253, 0.5, 0, 34, 0)
shadow_enabled = true 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)
[node name="Menu" type="CanvasLayer" parent="."]
process_mode = 3
visible = false
script = ExtResource("3_tc7dm")
[node name="Control" type="Control" parent="Menu"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 4
size_flags_vertical = 4
[node name="VBoxContainer" type="VBoxContainer" parent="Menu/Control"]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -39.5
offset_top = -33.0
offset_right = 39.5
offset_bottom = 33.0
grow_horizontal = 2
grow_vertical = 2
[node name="ContinueButton" type="Button" parent="Menu/Control/VBoxContainer"]
layout_mode = 2
text = "Continue"
[node name="QuitButton" type="Button" parent="Menu/Control/VBoxContainer"]
layout_mode = 2
text = "Quit"
[connection signal="pressed" from="Menu/Control/VBoxContainer/ContinueButton" to="Menu" method="_on_continue_button_pressed"]
[connection signal="pressed" from="Menu/Control/VBoxContainer/QuitButton" to="Menu" method="_on_quit_button_pressed"]
+24
View File
@@ -0,0 +1,24 @@
extends CanvasLayer
@onready var pause_menu = $Control
func _input(event):
if event.is_action_pressed("ui_cancel"):
if get_tree().paused:
resume_game()
else:
pause_game()
func pause_game():
get_tree().paused = true
visible = true
func resume_game():
get_tree().paused = false
visible = false
func _on_quit_button_pressed():
get_tree().quit()
func _on_continue_button_pressed():
resume_game()
+1
View File
@@ -0,0 +1 @@
uid://b7fopt7sx74g8
+1 -1
View File
@@ -2,4 +2,4 @@ extends Node
func _input(event): func _input(event):
if event.is_action_pressed("ui_cancel"): # 'ui_cancel' is a built-in action defined in Project > Project Settings > Input Map 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")
@@ -1,10 +1,11 @@
[gd_scene load_steps=5 format=3 uid="uid://d3tqrm4ry4l88"] [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="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="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"] [ext_resource type="Theme" uid="uid://wpxmub0n2dr3" path="res://themes/button_theme.tres" id="3_46duy"]
[node name="settings_screen" type="Node2D"] [node name="settings_screen" type="Node2D"]
script = ExtResource("1_1dggd") script = ExtResource("1_1dggd")
metadata/_edit_vertical_guides_ = [1152.0] metadata/_edit_vertical_guides_ = [1152.0]
@@ -2,10 +2,10 @@ extends Control
func _on_start_button_pressed(): 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(): 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(): func _on_quit_button_pressed():
get_tree().quit() get_tree().quit()
@@ -1,6 +1,6 @@
[gd_scene load_steps=5 format=3 uid="uid://b4k81taauef4q"] [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="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="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"] [ext_resource type="Theme" uid="uid://tn8qndst18d6" path="res://themes/title_font_theme.tres" id="4_hm208"]
+21
View File
@@ -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")
+48 -9
View File
@@ -1,16 +1,55 @@
extends RigidBody3D extends RigidBody3D
# Initially I used a CharacterBody3D, however, I wanted the player to bounce off # 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 # other objects in the environment and that would have required manual handling
# of collisions. So that's why we're using a RigidBody3D instead. # of collisions. So that's why we're using a RigidBody3D instead.
const ACCELLERATION = 5.0 const MOVE_SPEED := 8.0
const ACCELLERATION := 30.0
const DECELLERATION := 40.0
const JUMP_SPEED := 4.0
func _integrate_forces(state): @export var camera_path: NodePath
var input_dir = Vector3.ZERO @onready var cam: Camera3D = get_node(camera_path) if camera_path != NodePath("") else null
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") func _ready() -> void:
input_dir = input_dir.normalized() 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) func _integrate_forces(state):
linear_velocity.z += input_dir.z * (ACCELLERATION * state.step) # 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