Skip to content

Commit 766d842

Browse files
authored
Core game mechanics implementation (#138)
1 parent 300b9c3 commit 766d842

3,669 files changed

Lines changed: 115074 additions & 38225 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Normalize EOL for all files that Git considers text files.
2+
# Godot expects all files to be LF, not CRLF, even on windows.
3+
* text=auto eol=lf

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
.import/
66
export.cfg
77
export_presets.cfg
8+
*.tmp
89

910
# Mono-specific ignores
1011
.mono/
@@ -20,3 +21,4 @@ build
2021

2122
# Custom folders to ignore
2223
Builds/
24+
DevTools/conda

.vscode/launch.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "WorldDev2D.tscn",
9+
"type": "godot",
10+
"request": "launch",
11+
"scene": "Assets/World/WorldDev2D.tscn",
12+
"project": "",
13+
"additional_options": ""
14+
},
15+
{
16+
"name": "WorldDev2D_simple.tscn",
17+
"type": "godot",
18+
"request": "launch",
19+
"scene": "Assets/World/WorldDev2D_simple.tscn",
20+
"project": "",
21+
"additional_options": ""
22+
},
23+
{
24+
"name": "WorldDev2D_perf.tscn",
25+
"type": "godot",
26+
"request": "launch",
27+
"scene": "Assets/World/WorldDev2D_perf.tscn",
28+
"project": "",
29+
"additional_options": ""
30+
},
31+
{
32+
"name": "GDScript: Launch Pinned File",
33+
"type": "godot",
34+
"request": "launch",
35+
"scene": "pinned",
36+
"project": "",
37+
"additional_options": ""
38+
},
39+
{
40+
"name": "GDScript: Launch Project",
41+
"type": "godot",
42+
"request": "launch",
43+
"project": "${workspaceFolder}",
44+
"debug_collisions": false,
45+
"debug_paths": false,
46+
"debug_navigation": false,
47+
"additional_options": ""
48+
},
49+
50+
]
51+
}

.vscode/settings.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"editor.insertSpaces": true,
3+
"editor.tabSize": 2,
4+
"terminal.sourceControlRepositoriesKind": "integrated",
5+
"git.alwaysShowStagedChangesResourceGroup": false,
6+
"git.discardUntrackedChangesToTrash": true,
7+
"git.untrackedChanges": "mixed",
8+
"git.branchSortOrder": "committerdate",
9+
"git.branchRandomName.enable": false,
10+
"git.checkoutType": [
11+
"remote",
12+
"tags",
13+
"local"
14+
],
15+
"git.enableCommitSigning": false,
16+
"git.replaceTagsWhenPull": false,
17+
"editor.renderWhitespace": "all",
18+
"python-envs.defaultEnvManager": "ms-python.python:conda",
19+
"python-envs.defaultPackageManager": "ms-python.python:conda",
20+
"python-envs.pythonProjects": [],
21+
"explorer.fileNesting.enabled": true,
22+
"explorer.fileNesting.patterns": {
23+
"*.gd": "${capture}.gd.uid",
24+
"*.gdshader": "${capture}.gdshader.uid",
25+
"*.png": "${capture}.png.import"
26+
},
27+
"explorer.fileNesting.expand": false
28+
}

Assets/Audio/Music/GameMusic.gd

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,44 @@ var _music_files := []
77
var _music_streams := [] # Note: Does not show up in remote inspector.
88

99
func _ready() -> void:
10-
var dir := DirAccess.open("res://Assets/Audio/Music/Ambient")
11-
dir.list_dir_begin() # TODOGODOT4: Fill missing arguments https://github.com/godotengine/godot/pull/40547
10+
var dir := DirAccess.open("res://Assets/Audio/Music/Ambient")
11+
dir.list_dir_begin() # TODOGODOT4: Fill missing arguments https://github.com/godotengine/godot/pull/40547
1212

13-
# Load all the files from the Ambient folder.
14-
while true:
15-
var file: String = dir.get_next()
16-
if file == "":
17-
break
18-
elif file.ends_with(".ogg"):
19-
_music_files.append(file)
13+
# Load all the files from the Ambient folder.
14+
while true:
15+
var file: String = dir.get_next()
16+
if file == "":
17+
break
18+
elif file.ends_with(".ogg"):
19+
_music_files.append(file)
2020

21-
for i in _music_files:
22-
_music_streams.append(load("Assets/Audio/Music/Ambient/" + i))
21+
for i in _music_files:
22+
_music_streams.append(load("Assets/Audio/Music/Ambient/" + i))
2323

24-
# Always play a specific song when the game starts.
25-
stream = preload("res://Assets/Audio/Music/Ambient/newfrontier.ogg")
26-
play()
24+
# Always play a specific song when the game starts.
25+
stream = preload("res://Assets/Audio/Music/Ambient/newfrontier.ogg")
26+
play()
2727

28-
randomize() # Godot will always generate the same random numbers otherwise.
28+
randomize() # Godot will always generate the same random numbers otherwise.
2929

3030
func play_song_random() -> void:
31-
play_song_index(randi() % _music_streams.size())
31+
play_song_index(randi() % _music_streams.size())
3232

3333
func play_song_index(index: int) -> void:
34-
stop()
35-
stream = _music_streams[index]
36-
play()
34+
stop()
35+
stream = _music_streams[index]
36+
play()
3737

3838
# All the functions below are untested.
3939

4040
func add_song(file_name: String) -> void:
41-
_music_files.append(file_name)
42-
_music_streams.append(
43-
load("res://Assets/Audio/Music/Ambient/" + file_name))
41+
_music_files.append(file_name)
42+
_music_streams.append(
43+
load("res://Assets/Audio/Music/Ambient/" + file_name))
4444

4545
func remove_song(file_name: String) -> void:
46-
remove_song_index(_music_files.find(file_name))
46+
remove_song_index(_music_files.find(file_name))
4747

4848
func remove_song_index(index: int) -> void:
49-
_music_streams.remove_at(index)
50-
_music_files.remove_at(index)
49+
_music_streams.remove_at(index)
50+
_music_files.remove_at(index)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
uid://cykhkpihlirxs
1+
uid://dytw2nkh1je03

Assets/Player/CameraControls.gd

Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -28,88 +28,87 @@ var _drag_pos: Vector2
2828
var enabled: bool = true : set = set_enabled, get = get_enabled
2929

3030
func _ready() -> void:
31-
_viewport.size_changed.connect(_on_viewport_size_changed)
32-
_basis = _get_basis()
31+
_viewport.size_changed.connect(_on_viewport_size_changed)
32+
_basis = _get_basis()
3333

3434
func _process(delta: float) -> void:
35-
_move(delta)
36-
_move_drag()
35+
_move(delta)
36+
_move_drag()
3737

3838
func _input(event: InputEvent) -> void:
39-
if event.is_action_pressed("rotate_left"):
40-
_rotate(-PI/2)
39+
if event.is_action_pressed("rotate_left"):
40+
_rotate(-PI/2)
4141

42-
elif event.is_action_pressed("rotate_right"):
43-
_rotate(PI/2)
42+
elif event.is_action_pressed("rotate_right"):
43+
_rotate(PI/2)
4444

45-
elif event.is_action_pressed("zoom_in"):
46-
if _camera.size > ZOOM_IN_LIMIT:
47-
_zoom(-ZOOM_VALUE)
45+
elif event.is_action_pressed("zoom_in"):
46+
if _camera.size > ZOOM_IN_LIMIT:
47+
_zoom(-ZOOM_VALUE)
4848

49-
elif event.is_action_pressed("zoom_out"):
50-
if _camera.size < ZOOM_OUT_LIMIT:
51-
_zoom(ZOOM_VALUE)
49+
elif event.is_action_pressed("zoom_out"):
50+
if _camera.size < ZOOM_OUT_LIMIT:
51+
_zoom(ZOOM_VALUE)
5252

5353
func _move(delta: float) -> void:
54-
var movement_scale: float = delta * MOVE_SPEED * _camera.size
55-
if Input.is_action_pressed("move_faster"):
56-
movement_scale *= MOVE_FASTER_MULT
54+
var movement_scale: float = delta * MOVE_SPEED * _camera.size
55+
if Input.is_action_pressed("move_faster"):
56+
movement_scale *= MOVE_FASTER_MULT
5757

58-
var x := Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
59-
var y := Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
60-
var movement_velocity := Vector2(x, y * _viewport_aspect)
61-
_origin.translate(_basis * Utils.map_2_to_3(movement_velocity) * movement_scale)
58+
var x := Input.get_action_strength("move_right") - Input.get_action_strength("move_left")
59+
var y := Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
60+
var movement_velocity := Vector2(x, y * _viewport_aspect)
61+
_origin.translate(_basis * Utils.map_2_to_3(movement_velocity) * movement_scale)
6262

6363
func _move_drag() -> void:
64-
if Input.is_action_pressed("move_drag"):
65-
var new_drag_pos := _viewport.get_mouse_position()
66-
if Input.is_action_just_pressed("move_drag"):
67-
_drag_pos = new_drag_pos
68-
else:
69-
# DEBUG
70-
#if new_drag_pos != _drag_pos:
71-
# prints(_drag_pos, "=>", new_drag_pos)
72-
var drag_dir = (_drag_pos - new_drag_pos) * _camera.size / _viewport_size * 6
73-
var move_dir := _basis * Utils.map_2_to_3(drag_dir)
74-
_origin.translate(move_dir)
75-
_drag_pos = new_drag_pos
64+
if Input.is_action_pressed("move_drag"):
65+
var new_drag_pos := _viewport.get_mouse_position()
66+
if Input.is_action_just_pressed("move_drag"):
67+
_drag_pos = new_drag_pos
68+
else:
69+
# DEBUG
70+
#if new_drag_pos != _drag_pos:
71+
# prints(_drag_pos, "=>", new_drag_pos)
72+
var drag_dir = (_drag_pos - new_drag_pos) * _camera.size / _viewport_size * 6
73+
var move_dir := _basis * Utils.map_2_to_3(drag_dir)
74+
_origin.translate(move_dir)
75+
_drag_pos = new_drag_pos
7676

7777
func _rotate(rotation: float) -> void:
78-
_rotation_y.rotate_y(rotation)
79-
_basis = _get_basis()
78+
_rotation_y.rotate_y(rotation)
79+
_basis = _get_basis()
8080

8181
func _zoom(zoom_value: float) -> void:
82-
var m_pos := _viewport.get_mouse_position()
83-
var start_result := _raycast_from_mouse(m_pos, 1)
84-
_camera.size += zoom_value
85-
var end_result := _raycast_from_mouse(m_pos, 1)
86-
if not (start_result.is_empty() and end_result.is_empty()):
87-
var move_dir: Vector3i = start_result.position - end_result.position
88-
_origin.translate(move_dir)
82+
var m_pos := _viewport.get_mouse_position()
83+
var start_result := _raycast_from_mouse(m_pos, 1)
84+
_camera.size += zoom_value
85+
var end_result := _raycast_from_mouse(m_pos, 1)
86+
if not (start_result.is_empty() and end_result.is_empty()):
87+
var move_dir: Vector3i = start_result.position - end_result.position
88+
_origin.translate(move_dir)
8989

9090
func _raycast_from_mouse(m_pos: Vector2, collision_mask: int) -> Dictionary:
91-
var mouse_pos := get_viewport().get_mouse_position()
92-
var space_state := _origin.get_world_3d().direct_space_state
93-
var query := PhysicsRayQueryParameters3D.new()
94-
query.from = _camera.project_ray_origin(mouse_pos)
95-
query.to = query.from + _camera.project_ray_normal(mouse_pos) * RAY_LENGTH
96-
query.collision_mask = collision_mask
91+
var space_state := _origin.get_world_3d().direct_space_state
92+
var query := PhysicsRayQueryParameters3D.new()
93+
query.from = _camera.project_ray_origin(m_pos)
94+
query.to = query.from + _camera.project_ray_normal(m_pos) * RAY_LENGTH
95+
query.collision_mask = collision_mask
9796

98-
var result := space_state.intersect_ray(query)
99-
return result
97+
var result := space_state.intersect_ray(query)
98+
return result
10099

101100
func _get_basis() -> Basis:
102-
return _rotation_y.get_transform().basis
101+
return _rotation_y.get_transform().basis
103102

104103
func set_enabled(new_value: bool) -> void:
105-
enabled = new_value
104+
enabled = new_value
106105

107-
set_process(enabled)
108-
set_process_input(enabled)
106+
set_process(enabled)
107+
set_process_input(enabled)
109108

110109
func get_enabled() -> bool:
111-
return enabled
110+
return enabled
112111

113112
func _on_viewport_size_changed() -> void:
114-
_viewport_size = _viewport.size
115-
_viewport_aspect = _viewport_size.aspect()
113+
_viewport_size = _viewport.size
114+
_viewport_aspect = _viewport_size.aspect()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
uid://bnr4cxwapfe5w
1+
uid://cwirqstmh18ud

Assets/Player/GameSpeedLabel.tscn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[gd_scene load_steps=3 format=3 uid="uid://brlfwe0m2fujg"]
22

33
[ext_resource type="PackedScene" uid="uid://b25sornhxlynd" path="res://Assets/UI/BasicControls/LabelEx.tscn" id="2"]
4-
[ext_resource type="Script" uid="uid://dkn6dkvtme6dh" path="res://Assets/UI/TabWidgets/Buttons/MainButton/MainButtons/GameSpeedLabel.gd" id="2_fxq7v"]
4+
[ext_resource type="Script" uid="uid://dmdkwtdtkw7qs" path="res://Assets/UI/TabWidgets/Buttons/MainButton/MainButtons/GameSpeedLabel.gd" id="2_fxq7v"]
55

66
[node name="GameSpeedLabel" instance=ExtResource("2")]
77
script = ExtResource("2_fxq7v")

0 commit comments

Comments
 (0)