1
Fork 0
mirror of https://github.com/Steffo99/nanogolf.git synced 2024-11-21 23:54:21 +00:00

Make the game run on mobile devices

This commit is contained in:
Steffo 2024-02-18 18:15:59 +01:00
parent bf0578ddcc
commit c4176d0cef
Signed by: steffo
GPG key ID: 5ADA3868646C3FC0
19 changed files with 189 additions and 25 deletions

View file

@ -11,10 +11,23 @@ config_version=5
[application] [application]
config/name="Nanogolf" config/name="Nanogolf"
run/main_scene="res://scenes/main.tscn" run/main_scene="res://scenes/golf_level_2.tscn"
config/features=PackedStringArray("4.2", "Mobile") config/features=PackedStringArray("4.2", "Mobile")
config/icon="res://icon.svg" config/icon="res://icon.svg"
[display]
window/size/viewport_width=272
window/size/viewport_height=480
window/stretch/mode="canvas_items"
window/stretch/aspect="expand"
window/handheld/orientation=1
[physics]
common/physics_ticks_per_second=300
common/max_physics_steps_per_frame=15
[rendering] [rendering]
renderer/rendering_method="mobile" renderer/rendering_method="mobile"

10
scenes/follow_camera.gd Normal file
View file

@ -0,0 +1,10 @@
extends Camera2D
class_name FollowCamera
@export var target: Node2D
func _physics_process(_delta):
if target:
position = target.position

View file

@ -0,0 +1,5 @@
[gd_scene format=3 uid="uid://c5ck3dhekpwb8"]
[node name="FollowCamera" type="Camera2D"]
editor_draw_limits = true
editor_draw_drag_margin = true

View file

@ -14,10 +14,10 @@ _data = [Vector2(0, -20), 0.0, 20.0, 0, 1, Vector2(1, 0), 20.0, 0.0, 1, 0]
point_count = 2 point_count = 2
[sub_resource type="CircleShape2D" id="CircleShape2D_3vk3q"] [sub_resource type="CircleShape2D" id="CircleShape2D_3vk3q"]
radius = 8.0 radius = 4.0
[sub_resource type="CircleShape2D" id="CircleShape2D_aigrf"] [sub_resource type="CircleShape2D" id="CircleShape2D_aigrf"]
radius = 1.41421 radius = 1.0
[node name="GolfBall" type="CharacterBody2D"] [node name="GolfBall" type="CharacterBody2D"]
motion_mode = 1 motion_mode = 1
@ -31,6 +31,7 @@ collision_volume_db = SubResource("Curve_v81ms")
collision_volume_max_velocity = 150.0 collision_volume_max_velocity = 150.0
[node name="Sprite" type="Sprite2D" parent="."] [node name="Sprite" type="Sprite2D" parent="."]
scale = Vector2(0.063, 0.063)
texture = ExtResource("2_mqlag") texture = ExtResource("2_mqlag")
[node name="Shape" type="CollisionShape2D" parent="."] [node name="Shape" type="CollisionShape2D" parent="."]

View file

@ -12,6 +12,7 @@ script = ExtResource("1_7ng0k")
[node name="Circle" type="Sprite2D" parent="."] [node name="Circle" type="Sprite2D" parent="."]
modulate = Color(1, 1, 1, 0.25098) modulate = Color(1, 1, 1, 0.25098)
scale = Vector2(0.125, 0.125)
texture = ExtResource("1_dw1g4") texture = ExtResource("1_dw1g4")
[node name="Shape" type="CollisionShape2D" parent="."] [node name="Shape" type="CollisionShape2D" parent="."]

22
scenes/golf_level_1.tscn Normal file
View file

@ -0,0 +1,22 @@
[gd_scene load_steps=4 format=3 uid="uid://coh35s53wjxoa"]
[ext_resource type="TileSet" uid="uid://17esn8g8xqik" path="res://tiles/hole_tile_set.tres" id="1_r070t"]
[ext_resource type="PackedScene" uid="uid://ca06elq8io5wu" path="res://scenes/golf_ball.tscn" id="2_ek6nk"]
[ext_resource type="PackedScene" uid="uid://df7t70153a3bb" path="res://scenes/golf_hole.tscn" id="3_mxcvd"]
[node name="GolfLevel1" type="Node2D"]
[node name="Camera" type="Camera2D" parent="."]
[node name="TileMap" type="TileMap" parent="."]
scale = Vector2(0.125, 0.125)
tile_set = ExtResource("1_r070t")
format = 2
layer_0/tile_data = PackedInt32Array(131067, 2, 0, 196603, 2, 0, 262139, 2, 0, 327675, 2, 0, 393211, 2, 0, 458747, 2, 0, -196612, 1, 0, -524291, 2, 0, -458755, 2, 0, -393219, 2, 0, -327683, 2, 0, -262147, 1, 0, -589822, 2, 0, -524286, 2, 0, 65540, 2, 0, 131076, 2, 0, 196612, 2, 0, 262148, 2, 0, 327684, 2, 0, 393220, 2, 0, -196613, 1, 805306368, -262148, 1, 805306368, -589827, 2, 0, -589826, 2, 0, 655358, 2, 0, -589825, 2, 0, 655359, 2, 0, -655360, 2, 0, 589824, 2, 0, -655359, 2, 0, 589825, 2, 0, -655358, 2, 0, 524284, 1, 536870912, 458755, 1, 805306368, 589821, 1, 536870912, 524283, 1, 268435456, 589820, 1, 268435456, 655357, 1, 268435456, 589826, 1, 0, 524291, 1, 0, 458756, 1, 0, 524290, 1, 805306368, -196604, 2, 0, -131068, 2, 0, -65532, 2, 0, 4, 2, 0, -262140, 1, 536870912, -327677, 1, 536870912, -327678, 1, 268435456, -393214, 2, 0, -262141, 1, 268435456, -458750, 2, 0, -5, 2, 0, 65531, 2, 0, -131077, 2, 0, -65541, 2, 0, 65535, 1, 805306368, 131071, 1, 268435456, 0, 1, 536870912, 65536, 1, 0)
metadata/_edit_lock_ = true
[node name="GolfBall" parent="." instance=ExtResource("2_ek6nk")]
position = Vector2(0, -112)
[node name="GolfHole" parent="." instance=ExtResource("3_mxcvd")]
position = Vector2(0, 100)

29
scenes/golf_level_2.tscn Normal file
View file

@ -0,0 +1,29 @@
[gd_scene load_steps=6 format=3 uid="uid://dts4o84p3vj5c"]
[ext_resource type="PackedScene" uid="uid://c5ck3dhekpwb8" path="res://scenes/follow_camera.tscn" id="1_3a7ly"]
[ext_resource type="TileSet" uid="uid://17esn8g8xqik" path="res://tiles/hole_tile_set.tres" id="1_h4d2b"]
[ext_resource type="PackedScene" uid="uid://ca06elq8io5wu" path="res://scenes/golf_ball.tscn" id="2_244ns"]
[ext_resource type="Script" path="res://scenes/follow_camera.gd" id="2_l7nsy"]
[ext_resource type="PackedScene" uid="uid://df7t70153a3bb" path="res://scenes/golf_hole.tscn" id="3_kt60g"]
[node name="GolfLevel2" type="Node2D"]
[node name="FollowCamera" parent="." node_paths=PackedStringArray("target") instance=ExtResource("1_3a7ly")]
process_callback = 0
position_smoothing_enabled = true
drag_vertical_enabled = true
script = ExtResource("2_l7nsy")
target = NodePath("../GolfBall")
[node name="TileMap" type="TileMap" parent="."]
scale = Vector2(0.125, 0.125)
tile_set = ExtResource("1_h4d2b")
format = 2
layer_0/tile_data = PackedInt32Array(131067, 2, 0, 196603, 2, 0, 262139, 2, 0, 327675, 2, 0, 393211, 2, 0, 458747, 2, 0, -196612, 1, 0, -524291, 2, 0, -458755, 2, 0, -393219, 2, 0, -327683, 2, 0, -262147, 1, 0, -589822, 2, 0, -524286, 2, 0, 65540, 2, 0, 131076, 2, 0, 196612, 2, 0, 262148, 2, 0, 327684, 2, 0, 393220, 2, 0, -196613, 1, 805306368, -262148, 1, 805306368, -589827, 2, 0, -589826, 2, 0, -589825, 2, 0, -655360, 2, 0, -655359, 2, 0, -655358, 2, 0, 524284, 1, 536870912, 458755, 1, 805306368, 589821, 1, 536870912, 524283, 1, 268435456, 589820, 1, 268435456, 524291, 1, 0, 458756, 1, 0, 524290, 1, 805306368, -196604, 2, 0, -131068, 2, 0, -65532, 2, 0, 4, 2, 0, -262140, 1, 536870912, -327677, 1, 536870912, -327678, 1, 268435456, -393214, 2, 0, -262141, 1, 268435456, -458750, 2, 0, -5, 2, 0, 65531, 2, 0, -131077, 2, 0, -65541, 2, 0, 655357, 2, 0, 720893, 2, 0, 786429, 2, 0, 851965, 2, 0, 589826, 2, 0, 655362, 2, 0, 720898, 2, 0, 786434, 2, 0, 851970, 2, 0, 917506, 2, 0, 983042, 2, 0, 917501, 2, 0, 983037, 2, 0, 1048573, 2, 0, 1114109, 1, 0, 1179644, 1, 0, 1245179, 1, 0, 1048578, 1, 268435456, 1114115, 1, 268435456, 1179652, 1, 268435456, 1114116, 1, 536870912, 1179653, 1, 536870912, 1048579, 1, 536870912, 1114108, 1, 805306368, 1179643, 1, 805306368, 1245178, 1, 805306368, 1441783, 1, 805306368, 1376248, 1, 805306368, 1441784, 1, 0, 1310713, 1, 805306368, 1376249, 1, 0, 1310714, 1, 0, 1245189, 1, 268435456, 1245190, 1, 536870912, 1310726, 1, 268435456, 1310727, 1, 536870912, 1376263, 1, 268435456, 1376264, 1, 536870912, 1441800, 1, 268435456, 1441801, 1, 536870912, 1507337, 1, 268435456, 1507338, 1, 536870912, 1572874, 1, 268435456, 1572875, 1, 536870912, 1638411, 1, 268435456, 1638412, 1, 536870912, 1703948, 1, 268435456, 1703949, 1, 536870912, 1769485, 1, 268435456, 1769486, 1, 536870912, 1834993, 1, 805306368, 1769458, 1, 805306368, 1834994, 1, 0, 1703923, 1, 805306368, 1769459, 1, 0, 1638388, 1, 805306368, 1703924, 1, 0, 1572853, 1, 805306368, 1638389, 1, 0, 1507318, 1, 805306368, 1572854, 1, 0, 1507319, 1, 0, 1900529, 2, 0, 1966065, 2, 0, 2031601, 2, 0, 2097137, 2, 0, 2162673, 2, 0, 1835022, 2, 0, 1900558, 2, 0, 1966094, 2, 0, 2031630, 2, 0, 2097166, 2, 0, 2162702, 2, 0, 2162701, 2, 0, 2162700, 2, 0, 2162699, 2, 0, 2162698, 2, 0, 2162697, 2, 0, 2162696, 2, 0, 2162695, 2, 0, 2162694, 2, 0, 2162693, 2, 0, 2162692, 2, 0, 2162691, 2, 0, 2162690, 2, 0, 2162689, 2, 0, 2162688, 2, 0, 2228223, 2, 0, 2228222, 2, 0, 2228221, 2, 0, 2228220, 2, 0, 2228219, 2, 0, 2228218, 2, 0, 2228217, 2, 0, 2228216, 2, 0, 2228215, 2, 0, 2228214, 2, 0, 2228213, 2, 0, 2228212, 2, 0, 2228211, 2, 0, 2228210, 2, 0, 2228209, 2, 0, 1245184, 3, 805306368, 1441791, 3, 805306368, 1507328, 3, 805306368, 1703935, 3, 805306368, 1769472, 3, 805306368, 1835005, 3, 805306368, 1572861, 3, 805306368, 1376258, 3, 805306368, 1638402, 3, 805306368, 1703931, 3, 805306368, 1507332, 3, 805306368)
metadata/_edit_lock_ = true
[node name="GolfBall" parent="." instance=ExtResource("2_244ns")]
position = Vector2(0, -112)
[node name="GolfHole" parent="." instance=ExtResource("3_kt60g")]
position = Vector2(0, 488)

49
scenes/interface.gd Normal file
View file

@ -0,0 +1,49 @@
extends MarginContainer
class_name Interface
@export var min_margin_left: int = 0
@export var min_margin_right: int = 0
@export var min_margin_top: int = 0
@export var min_margin_bottom: int = 0
var margin_left: int:
get:
return get_theme_constant("margin_left")
set(value):
add_theme_constant_override("margin_left", value)
var margin_right: int:
get:
return get_theme_constant("margin_right")
set(value):
add_theme_constant_override("margin_right", value)
var margin_top: int:
get:
return get_theme_constant("margin_top")
set(value):
add_theme_constant_override("margin_top", value)
var margin_bottom: int:
get:
return get_theme_constant("margin_bottom")
set(value):
add_theme_constant_override("margin_bottom", value)
func _ready():
# Cutouts are broken on desktop platforms...
if len(DisplayServer.get_display_cutouts()) == 0:
margin_left = min_margin_left
margin_right = min_margin_right
margin_top = min_margin_top
margin_bottom = min_margin_bottom
else:
var screen: Vector2i = DisplayServer.screen_get_size()
var rect: Rect2i = DisplayServer.get_display_safe_area()
margin_left = max(min_margin_left, rect.position.x)
margin_right = max(min_margin_right, screen.x - rect.end.x)
margin_top = max(min_margin_top, rect.position.y)
margin_bottom = max(min_margin_bottom, screen.y - rect.end.y)

15
scenes/interface.tscn Normal file
View file

@ -0,0 +1,15 @@
[gd_scene load_steps=2 format=3 uid="uid://dtwi2nyjbvr82"]
[ext_resource type="Script" path="res://scenes/interface.gd" id="1_e3sp8"]
[node name="Interface" type="MarginContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_e3sp8")
min_margin_left = 16
min_margin_right = 16
min_margin_top = 16
min_margin_bottom = 16

2
scenes/main.gd Normal file
View file

@ -0,0 +1,2 @@
extends Node
class_name Main

View file

@ -1,19 +1,7 @@
[gd_scene load_steps=4 format=3 uid="uid://b8f5t76nfdu5h"] [gd_scene load_steps=2 format=3 uid="uid://b8f5t76nfdu5h"]
[ext_resource type="PackedScene" uid="uid://ca06elq8io5wu" path="res://scenes/golf_ball.tscn" id="1_5j6ud"] [ext_resource type="PackedScene" uid="uid://dtwi2nyjbvr82" path="res://scenes/interface.tscn" id="1_bd856"]
[ext_resource type="TileSet" uid="uid://17esn8g8xqik" path="res://tiles/hole_tile_set.tres" id="1_rm16w"]
[ext_resource type="PackedScene" uid="uid://df7t70153a3bb" path="res://scenes/golf_hole.tscn" id="3_dn06g"]
[node name="Main" type="Node"] [node name="Main" type="Node"]
[node name="TileMap" type="TileMap" parent="."] [node name="Interface" parent="." instance=ExtResource("1_bd856")]
tile_set = ExtResource("1_rm16w")
format = 2
layer_0/tile_data = PackedInt32Array(720914, 2, 0, 786450, 2, 0, 851986, 2, 0, 917522, 2, 0, 983058, 2, 0, 1048594, 2, 0, 1114130, 2, 0, 1114131, 2, 0, 1114132, 2, 0, 1114133, 2, 0, 1114134, 2, 0, 1114135, 2, 0, 1114136, 2, 0, 720915, 2, 0, 720916, 2, 0, 720917, 2, 0, 720918, 2, 0, 720919, 2, 0, 720920, 2, 0, 720921, 2, 0, 720922, 2, 0, 720923, 2, 0, 720924, 2, 0, 720925, 2, 0, 720926, 2, 0, 786462, 2, 0, 851998, 2, 0, 917534, 2, 0, 983070, 2, 0, 1048606, 2, 0, 1114142, 2, 0, 1179672, 2, 0, 1245208, 2, 0, 1310744, 2, 0, 1376280, 2, 0, 1441816, 2, 0, 1507352, 2, 0, 1507353, 2, 0, 1507354, 2, 0, 1507355, 2, 0, 1507356, 2, 0, 1507357, 2, 0, 1507358, 2, 0, 1507359, 2, 0, 1114143, 2, 0, 1114144, 2, 0, 1114145, 2, 0, 1114146, 2, 0, 1114147, 2, 0, 1114148, 2, 0, 1179684, 2, 0, 1245220, 2, 0, 1310756, 2, 0, 1376292, 2, 0, 1441828, 2, 0, 1507364, 2, 0, 1507363, 2, 0, 1507362, 2, 0, 1507361, 2, 0, 1507360, 2, 0, 983069, 1, 268435456, 917532, 1, 268435456, 851995, 1, 268435456, 786458, 1, 268435456, 1245209, 1, 536870912, 1310746, 1, 536870912, 1376283, 1, 536870912, 1441820, 1, 536870912, 1441819, 2, 0, 1441818, 2, 0, 1376282, 2, 0, 1376281, 2, 0, 1441817, 2, 0, 1310745, 2, 0, 917533, 2, 0, 851997, 2, 0, 786461, 2, 0, 786460, 2, 0, 851996, 2, 0, 786459, 2, 0)
metadata/_edit_lock_ = true
[node name="GolfBall" parent="." instance=ExtResource("1_5j6ud")]
position = Vector2(340, 229)
[node name="GolfHole" parent="." instance=ExtResource("3_dn06g")]
position = Vector2(544, 333)

View file

@ -0,0 +1,17 @@
extends Node
class_name NetworkController
@export var port = 12345
func start_server() -> ENetMultiplayerPeer:
var peer = ENetMultiplayerPeer.new()
peer.create_server(port, 32)
return peer
func start_client() -> ENetMultiplayerPeer:
var peer = ENetMultiplayerPeer.new()
peer.create_client("127.0.0.1", port)
return peer

View file

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://ddmiruki5mjn2"]
[ext_resource type="Script" path="res://scenes/network_controller.gd" id="1_2jxjv"]
[node name="NetworkController" type="Node"]
script = ExtResource("1_2jxjv")

View file

@ -20,6 +20,7 @@ putt_ghost_scale = 0.3
putt_volume = SubResource("Curve_pq63d") putt_volume = SubResource("Curve_pq63d")
[node name="Sprite" type="Sprite2D" parent="."] [node name="Sprite" type="Sprite2D" parent="."]
scale = Vector2(0.063, 0.063)
texture = ExtResource("2_eblkx") texture = ExtResource("2_eblkx")
[node name="Sound" type="AudioStreamPlayer2D" parent="."] [node name="Sound" type="AudioStreamPlayer2D" parent="."]

View file

@ -32,6 +32,6 @@ process/hdr_as_srgb=false
process/hdr_clamp_exposure=false process/hdr_clamp_exposure=false
process/size_limit=0 process/size_limit=0
detect_3d/compress_to=1 detect_3d/compress_to=1
svg/scale=1.0 svg/scale=8.0
editor/scale_with_editor_scale=false editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false editor/convert_colors_with_editor_theme=false

View file

@ -32,6 +32,6 @@ process/hdr_as_srgb=false
process/hdr_clamp_exposure=false process/hdr_clamp_exposure=false
process/size_limit=0 process/size_limit=0
detect_3d/compress_to=1 detect_3d/compress_to=1
svg/scale=1.0 svg/scale=8.0
editor/scale_with_editor_scale=false editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false editor/convert_colors_with_editor_theme=false

View file

@ -32,6 +32,6 @@ process/hdr_as_srgb=false
process/hdr_clamp_exposure=false process/hdr_clamp_exposure=false
process/size_limit=0 process/size_limit=0
detect_3d/compress_to=1 detect_3d/compress_to=1
svg/scale=1.0 svg/scale=8.0
editor/scale_with_editor_scale=false editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false editor/convert_colors_with_editor_theme=false

View file

@ -32,6 +32,6 @@ process/hdr_as_srgb=false
process/hdr_clamp_exposure=false process/hdr_clamp_exposure=false
process/size_limit=0 process/size_limit=0
detect_3d/compress_to=1 detect_3d/compress_to=1
svg/scale=1.0 svg/scale=8.0
editor/scale_with_editor_scale=false editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false editor/convert_colors_with_editor_theme=false

View file

@ -6,26 +6,31 @@
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_174yq"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_174yq"]
texture = ExtResource("2_dv6qu") texture = ExtResource("2_dv6qu")
texture_region_size = Vector2i(128, 128)
0:0/0 = 0 0:0/0 = 0
0:0/0/physics_layer_0/linear_velocity = Vector2(0, 0) 0:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
0:0/0/physics_layer_0/angular_velocity = 0.0 0:0/0/physics_layer_0/angular_velocity = 0.0
0:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, -8, 8) 0:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-64, -64, 64, -64, -64, 64)
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_2md10"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_2md10"]
texture = ExtResource("3_3cg8j") texture = ExtResource("3_3cg8j")
texture_region_size = Vector2i(128, 128)
0:0/0 = 0 0:0/0 = 0
0:0/0/physics_layer_0/linear_velocity = Vector2(0, 0) 0:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
0:0/0/physics_layer_0/angular_velocity = 0.0 0:0/0/physics_layer_0/angular_velocity = 0.0
0:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8) 0:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-64, -64, 64, -64, 64, 64, -64, 64)
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_mbu12"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_mbu12"]
texture = ExtResource("4_0vvt5") texture = ExtResource("4_0vvt5")
texture_region_size = Vector2i(128, 128)
use_texture_padding = false
0:0/0 = 0 0:0/0 = 0
0:0/0/physics_layer_0/linear_velocity = Vector2(0, 0) 0:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
0:0/0/physics_layer_0/angular_velocity = 0.0 0:0/0/physics_layer_0/angular_velocity = 0.0
0:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 0, 8) 0:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-64, -64, 64, -64, 0, 64)
[resource] [resource]
tile_size = Vector2i(128, 128)
physics_layer_0/collision_layer = 1 physics_layer_0/collision_layer = 1
sources/1 = SubResource("TileSetAtlasSource_174yq") sources/1 = SubResource("TileSetAtlasSource_174yq")
sources/2 = SubResource("TileSetAtlasSource_2md10") sources/2 = SubResource("TileSetAtlasSource_2md10")