From c7453c5467278881c64c284f7060a1c48de38f52 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Thu, 21 Dec 2023 17:10:19 +0900 Subject: [PATCH] Add capability for touch controls --- PlayerCharacterBody2D.gd | 9 ++++++- export_presets.cfg | 4 +-- player.tscn | 56 ++++++++++++++++++++++++++++++++++++---- project.godot | 7 ++++- 4 files changed, 67 insertions(+), 9 deletions(-) diff --git a/PlayerCharacterBody2D.gd b/PlayerCharacterBody2D.gd index 5cb9324..2eeed1b 100644 --- a/PlayerCharacterBody2D.gd +++ b/PlayerCharacterBody2D.gd @@ -35,11 +35,15 @@ var particle = preload("res://circleParticle.tscn") @onready var title_text = $GameTitleText var title_timer = 5.0 +@onready var touch_jump = $JumpTouchButton +@onready var touch_left = $LeftTouchButton +@onready var touch_right = $RightTouchButton + func _ready(): self_sprite.self_modulate = DEFAULT_COLOR health_label.add_text(health_text_format % health) title_text.add_theme_font_size_override("normal_font_size", 40) - title_text.add_text("LD54 - Box Survival\nBy: BurnedKirby\nMade in Godot") + title_text.add_text("LD54 - Box Survival\nBy: BurnedKirby\nMade in Godot\nWAD or Touch to move") func _physics_process(delta): if title_timer > 0.0: @@ -110,3 +114,6 @@ func damaged(projectile): for i in range(100): spawn_particle(Color(1, 1, 1)) get_parent().on_player_death() + touch_jump.hide() + touch_left.hide() + touch_right.hide() diff --git a/export_presets.cfg b/export_presets.cfg index dfee8a3..0c37f96 100644 --- a/export_presets.cfg +++ b/export_presets.cfg @@ -8,7 +8,7 @@ custom_features="" export_filter="all_resources" include_filter="" exclude_filter="" -export_path="html_export/LD54.html" +export_path="html_export/ld54.html" encryption_include_filters="" encryption_exclude_filters="" encrypt_pck=false @@ -20,7 +20,7 @@ custom_template/debug="" custom_template/release="" variant/extensions_support=false vram_texture_compression/for_desktop=true -vram_texture_compression/for_mobile=false +vram_texture_compression/for_mobile=true html/export_icon=true html/custom_html_shell="" html/head_include="" diff --git a/player.tscn b/player.tscn index 40b6ef6..f757bc6 100644 --- a/player.tscn +++ b/player.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=6 format=3 uid="uid://dv8hwks0xe3c0"] +[gd_scene load_steps=8 format=3 uid="uid://dv8hwks0xe3c0"] [ext_resource type="Script" path="res://PlayerCharacterBody2D.gd" id="1_8l13s"] [ext_resource type="AudioStream" uid="uid://b88dh38cr8v6o" path="res://res/jump.ogg" id="2_ix2ut"] @@ -9,6 +9,15 @@ size = Vector2(40, 40) [sub_resource type="CanvasTexture" id="CanvasTexture_ruce8"] +[sub_resource type="Gradient" id="Gradient_v7mm3"] +colors = PackedColorArray(1, 1, 1, 0.454902, 1, 1, 1, 0) + +[sub_resource type="GradientTexture2D" id="GradientTexture2D_iin72"] +gradient = SubResource("Gradient_v7mm3") +fill = 1 +fill_from = Vector2(0.5, 0.5) +fill_to = Vector2(1, 0.5) + [node name="CharacterBody2D" type="CharacterBody2D"] position = Vector2(590, 561) collision_layer = 3 @@ -22,6 +31,42 @@ debug_color = Color(0, 0.6, 0.701961, 0.419608) scale = Vector2(40, 40) texture = SubResource("CanvasTexture_ruce8") +[node name="JumpTouchButton" type="TouchScreenButton" parent="."] +position = Vector2(-32.9999, -95) +texture_normal = SubResource("GradientTexture2D_iin72") +action = "jump" + +[node name="Label" type="Label" parent="JumpTouchButton"] +offset_left = 12.0 +offset_top = 19.0 +offset_right = 53.0 +offset_bottom = 42.0 +text = "Jump" + +[node name="RightTouchButton" type="TouchScreenButton" parent="."] +position = Vector2(40, -30) +texture_normal = SubResource("GradientTexture2D_iin72") +action = "right" + +[node name="Label" type="Label" parent="RightTouchButton"] +offset_left = 12.0 +offset_top = 19.0 +offset_right = 53.0 +offset_bottom = 42.0 +text = "Right" + +[node name="LeftTouchButton" type="TouchScreenButton" parent="."] +position = Vector2(-103, -30) +texture_normal = SubResource("GradientTexture2D_iin72") +action = "left" + +[node name="Label" type="Label" parent="LeftTouchButton"] +offset_left = 18.0 +offset_top = 20.0 +offset_right = 59.0 +offset_bottom = 43.0 +text = "Left" + [node name="Camera2D" type="Camera2D" parent="."] [node name="RichTextLabel" type="RichTextLabel" parent="."] @@ -43,7 +88,8 @@ stream = ExtResource("2_ix2ut") stream = ExtResource("3_gq63f") [node name="GameTitleText" type="RichTextLabel" parent="."] -offset_left = -137.0 -offset_top = 74.0 -offset_right = 336.0 -offset_bottom = 293.0 +offset_left = -138.0 +offset_top = 46.0 +offset_right = 335.0 +offset_bottom = 286.0 +scroll_active = false diff --git a/project.godot b/project.godot index e48d8d5..91241cf 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="LD54 - Box Survival" run/main_scene="res://boxedSpace.tscn" -config/features=PackedStringArray("4.1", "GL Compatibility") +config/features=PackedStringArray("4.2", "GL Compatibility") config/icon="res://icon.svg" [input] @@ -37,7 +37,12 @@ right={ ] } +[input_devices] + +pointing/emulate_touch_from_mouse=true + [rendering] renderer/rendering_method="gl_compatibility" renderer/rendering_method.mobile="gl_compatibility" +textures/vram_compression/import_etc2_astc=true