diff options
Diffstat (limited to 'game/src')
-rw-r--r-- | game/src/GameSession/GameSession.tscn | 11 | ||||
-rw-r--r-- | game/src/GameSession/MapControlPanel.tscn | 9 | ||||
-rw-r--r-- | game/src/GameSession/MapViewport.gd | 59 | ||||
-rw-r--r-- | game/src/GameSession/MapViewport.tscn | 31 | ||||
-rw-r--r-- | game/src/GameSession/TerrainMap.gdshader | 10 |
5 files changed, 118 insertions, 2 deletions
diff --git a/game/src/GameSession/GameSession.tscn b/game/src/GameSession/GameSession.tscn index f984daf..a707b04 100644 --- a/game/src/GameSession/GameSession.tscn +++ b/game/src/GameSession/GameSession.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=4 format=3 uid="uid://bgnupcshe1m7r"] +[gd_scene load_steps=5 format=3 uid="uid://bgnupcshe1m7r"] [ext_resource type="Script" path="res://src/GameSession/GameSession.gd" id="1_eklvp"] [ext_resource type="PackedScene" uid="uid://g524p8lr574w" path="res://src/GameSession/MapControlPanel.tscn" id="3_afh6d"] [ext_resource type="PackedScene" uid="uid://dvdynl6eir40o" path="res://src/GameSession/GameSessionMenu.tscn" id="3_bvmqh"] +[ext_resource type="PackedScene" uid="uid://dkehmdnuxih2r" path="res://src/GameSession/MapViewport.tscn" id="4_xkg5j"] [node name="GameSession" type="Control" node_paths=PackedStringArray("_game_session_menu")] editor_description = "SS-102" @@ -15,6 +16,14 @@ grow_vertical = 2 script = ExtResource("1_eklvp") _game_session_menu = NodePath("GameSessionMenu") +[node name="MapViewport" parent="." instance=ExtResource("4_xkg5j")] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + [node name="GameSessionMenu" parent="." instance=ExtResource("3_bvmqh")] visible = false layout_mode = 1 diff --git a/game/src/GameSession/MapControlPanel.tscn b/game/src/GameSession/MapControlPanel.tscn index 71d43e7..2a0c971 100644 --- a/game/src/GameSession/MapControlPanel.tscn +++ b/game/src/GameSession/MapControlPanel.tscn @@ -1,7 +1,13 @@ -[gd_scene load_steps=2 format=3 uid="uid://g524p8lr574w"] +[gd_scene load_steps=4 format=3 uid="uid://g524p8lr574w"] [ext_resource type="Script" path="res://src/GameSession/MapControlPanel.gd" id="1_ign64"] +[sub_resource type="InputEventAction" id="InputEventAction_5nck3"] +action = &"ui_cancel" + +[sub_resource type="Shortcut" id="Shortcut_fc1tk"] +events = [SubResource("InputEventAction_5nck3")] + [node name="PanelContainer" type="PanelContainer"] editor_description = "SS-103" script = ExtResource("1_ign64") @@ -27,6 +33,7 @@ layout_mode = 2 [node name="GameSessionMenuButton" type="Button" parent="HBoxContainer/AuxiliaryPanel"] editor_description = "UI-9" layout_mode = 2 +shortcut = SubResource("Shortcut_fc1tk") text = "ESC" [connection signal="pressed" from="HBoxContainer/AuxiliaryPanel/GameSessionMenuButton" to="." method="_on_game_session_menu_button_pressed"] diff --git a/game/src/GameSession/MapViewport.gd b/game/src/GameSession/MapViewport.gd new file mode 100644 index 0000000..fa57163 --- /dev/null +++ b/game/src/GameSession/MapViewport.gd @@ -0,0 +1,59 @@ +extends SubViewportContainer + +const _action_north : StringName = &"map_north" +const _action_east : StringName = &"map_east" +const _action_south : StringName = &"map_south" +const _action_west : StringName = &"map_west" +const _action_zoomin : StringName = &"map_zoomin" +const _action_zoomout : StringName = &"map_zoomout" + +const _move_speed : float = 1.0 + +const _zoom_target_min : float = 0.2 +const _zoom_target_max : float = 5.0 +const _zoom_target_step : float = 0.1 +const _zoom_epsilon : float = _zoom_target_step * 0.1 +const _zoom_speed : float = 5.0 +var _zoom_target : float = 1.0: + get: return _zoom_target + set(v): _zoom_target = clamp(v, _zoom_target_min, _zoom_target_max) + +@export var _camera : Camera3D +@export var _map_mesh : MeshInstance3D + +func _input(event : InputEvent): + if event.is_action_pressed(_action_zoomin, true): + _zoom_target -= _zoom_target_step + elif event.is_action_pressed(_action_zoomout, true): + _zoom_target += _zoom_target_step + +func _physics_process(delta): + # Process movement + var height : float = _camera.transform.origin.y + var move := Vector3( + float(Input.is_action_pressed(_action_east)) - float(Input.is_action_pressed(_action_west)), + 0.0, + float(Input.is_action_pressed(_action_south)) - float(Input.is_action_pressed(_action_north)), + ) + move *= _move_speed * height * delta + _camera.global_translate(move) + + # Keep within map bounds + var bounds := _map_mesh.get_aabb() * _map_mesh.transform + var width := bounds.end.x - bounds.position.x + var left := bounds.position.x + 0.25 * width + var longitude := fposmod(_camera.transform.origin.x - left, width * 0.5) + _camera.transform.origin.x = left + longitude + _camera.transform.origin.z = clamp(_camera.transform.origin.z, bounds.position.z, bounds.end.z) + + # Process zooming + var zoom : float = _zoom_target - height + height += zoom * _zoom_speed * delta + var new_zoom : float = _zoom_target - height + if abs(new_zoom) < _zoom_epsilon or sign(zoom) != sign(new_zoom): + height = _zoom_target + _camera.transform.origin.y = height + + # Orient based on height + var dir := Vector3(0, -1, -exp(-height * 2.0 + 0.5)) + _camera.look_at(_camera.transform.origin + dir) diff --git a/game/src/GameSession/MapViewport.tscn b/game/src/GameSession/MapViewport.tscn new file mode 100644 index 0000000..8a34b54 --- /dev/null +++ b/game/src/GameSession/MapViewport.tscn @@ -0,0 +1,31 @@ +[gd_scene load_steps=6 format=3 uid="uid://dkehmdnuxih2r"] + +[ext_resource type="Script" path="res://src/GameSession/MapViewport.gd" id="1_exccw"] +[ext_resource type="Shader" path="res://src/GameSession/TerrainMap.gdshader" id="1_upocn"] +[ext_resource type="Texture2D" uid="uid://cmw0pvjthnn8c" path="res://common/map/terrain/terrain.png" id="3_l8pnf"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_tayeg"] +render_priority = 0 +shader = ExtResource("1_upocn") +shader_parameter/tex = ExtResource("3_l8pnf") + +[sub_resource type="PlaneMesh" id="PlaneMesh_skc48"] +size = Vector2(10.8, 2) + +[node name="MapViewportContainer" type="SubViewportContainer" node_paths=PackedStringArray("_camera", "_map_mesh")] +stretch = true +script = ExtResource("1_exccw") +_camera = NodePath("MapViewport/Camera3D") +_map_mesh = NodePath("MapViewport/MeshInstance3D") + +[node name="MapViewport" type="SubViewport" parent="."] +handle_input_locally = false +render_target_update_mode = 4 + +[node name="MeshInstance3D" type="MeshInstance3D" parent="MapViewport"] +transform = Transform3D(5, 0, 0, 0, 5, 0, 0, 0, 5, 0, 0, 0) +material_override = SubResource("ShaderMaterial_tayeg") +mesh = SubResource("PlaneMesh_skc48") + +[node name="Camera3D" type="Camera3D" parent="MapViewport"] +transform = Transform3D(1, 0, 0, 0, 0.707107, 0.707107, 0, -0.707107, 0.707107, 0, 1, 1) diff --git a/game/src/GameSession/TerrainMap.gdshader b/game/src/GameSession/TerrainMap.gdshader new file mode 100644 index 0000000..522e0f3 --- /dev/null +++ b/game/src/GameSession/TerrainMap.gdshader @@ -0,0 +1,10 @@ +shader_type spatial; + +render_mode unshaded; + +uniform sampler2D tex: source_color, repeat_enable; + +void fragment() { + vec2 new_uv = vec2(UV.x * 2.0 - 0.5, UV.y); + ALBEDO = texture(tex, new_uv).rgb; +} |