diff --git a/Level.gd b/Level.gd
new file mode 100644
index 0000000..82923f7
--- /dev/null
+++ b/Level.gd
@@ -0,0 +1,5 @@
+extends Node2D
+
+func _ready() -> void:
+ if OS.has_feature("web_android") or OS.has_feature("web_ios"):
+ DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
diff --git a/Level.tscn b/Level.tscn
index 6ba0ee4..bfa0e79 100644
--- a/Level.tscn
+++ b/Level.tscn
@@ -1,7 +1,9 @@
-[gd_scene load_steps=9 format=4 uid="uid://bo7p216kiko7t"]
+[gd_scene load_steps=11 format=4 uid="uid://bo7p216kiko7t"]
[ext_resource type="Texture2D" uid="uid://b5gv12upluoes" path="res://tileset-2.png" id="1_2sdxq"]
-[ext_resource type="PackedScene" uid="uid://crht8e77338ew" path="res://Player.tscn" id="2_uldju"]
+[ext_resource type="Script" path="res://Level.gd" id="1_jd7hj"]
+[ext_resource type="PackedScene" uid="uid://crht8e77338ew" path="res://MyChar.tscn" id="2_uldju"]
+[ext_resource type="PackedScene" uid="uid://cynystnt5cwlg" path="res://PlayerController.tscn" id="3_tk158"]
[sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_oct0x"]
texture = ExtResource("1_2sdxq")
@@ -436,6 +438,7 @@ sources/0 = SubResource("TileSetAtlasSource_lpyyf")
[node name="World" type="Node2D"]
y_sort_enabled = true
+script = ExtResource("1_jd7hj")
[node name="water" type="TileMapLayer" parent="."]
texture_filter = 1
@@ -453,10 +456,10 @@ texture_filter = 1
tile_map_data = PackedByteArray("AAADAAUAAAAFAAcAAAADAA0AAAADAAcAAAAEAAgAAAAGAAgAAAAMABUAAAAGAAgAAAAOAAYAAAADAAcAAAAPABQAAAADAAcAAAAQAAsAAAAFAAcAAAAQAA4AAAAGAAgAAAASAA4AAAADAAcAAAAVAAcAAAADAAcAAAAWAAkAAAAGAAgAAAAWAA0AAAAGAAgAAAAXAAEAAAADAAcAAAAXABQAAAAFAAcAAAAZAA0AAAADAAcAAAAbAAAAAAADAAcAAAAbAAoAAAAGAAgAAAAbABkAAAADAAcAAAAcAAEAAAAFAAcAAAAjAAcAAAADAAcAAAAaABsAAAAGAAgAAAAoABYAAAAFAAgAAAAoABcAAAAGAAgAAAAoABgAAAAFAAgAAAAoABkAAAAFAAgAAAApABYAAAAFAAgAAAApABcAAAAFAAgAAAApABgAAAAFAAgAAAApABkAAAAFAAgAAAAqABYAAAAGAAgAAAAqABcAAAAFAAgAAAAqABgAAAAGAAgAAAAqABkAAAAFAAgAAAArABYAAAAFAAgAAAArABcAAAAFAAgAAAArABgAAAAFAAgAAAArABkAAAAFAAgAAAAnABgAAAAFAAgAAAAnABcAAAAFAAgAAAAnABUAAAAFAAgAAAAnABYAAAAFAAgAAAAmABcAAAAFAAgAAAAmABYAAAAFAAgAAAAmABUAAAAGAAgAAAAmABQAAAAFAAgAAAAlABYAAAAFAAgAAAAlABUAAAAFAAgAAAAlABQAAAAFAAgAAAAmABgAAAAGAAgAAAA=")
tile_set = SubResource("TileSet_e07et")
-[node name="Player" parent="." instance=ExtResource("2_uldju")]
+[node name="MyChar" parent="." instance=ExtResource("2_uldju")]
position = Vector2(314, 195)
-[node name="Camera2D" type="Camera2D" parent="Player"]
+[node name="Camera2D" type="Camera2D" parent="MyChar"]
limit_left = 0
limit_top = 0
limit_right = 800
@@ -467,3 +470,5 @@ drag_horizontal_enabled = true
drag_vertical_enabled = true
editor_draw_limits = true
editor_draw_drag_margin = true
+
+[node name="PlayerController" parent="MyChar" instance=ExtResource("3_tk158")]
diff --git a/MyChar.gd b/MyChar.gd
new file mode 100644
index 0000000..7b3bb53
--- /dev/null
+++ b/MyChar.gd
@@ -0,0 +1,19 @@
+extends CharacterBody2D
+
+@export var speed := 80.0 # px/s
+
+@onready var sprite: AnimatedSprite2D = $sprite
+var input_dir := Vector2.ZERO
+
+func _ready() -> void:
+ $sprite.play("idle")
+
+func _physics_process(_dt: float) -> void:
+ velocity = speed * input_dir.normalized()
+ move_and_slide()
+
+ if input_dir != Vector2.ZERO:
+ if sprite.animation != "walk":
+ sprite.play("walk")
+ elif sprite.animation != "idle":
+ sprite.play("idle")
diff --git a/Player.tscn b/MyChar.tscn
similarity index 89%
rename from Player.tscn
rename to MyChar.tscn
index a288ebe..f5472bd 100644
--- a/Player.tscn
+++ b/MyChar.tscn
@@ -1,6 +1,6 @@
[gd_scene load_steps=6 format=3 uid="uid://crht8e77338ew"]
-[ext_resource type="Script" path="res://Player.gd" id="1_nu61o"]
+[ext_resource type="Script" path="res://MyChar.gd" id="1_nu61o"]
[ext_resource type="Texture2D" uid="uid://dg8dggk5xu5ru" path="res://player1.png" id="2_hro3h"]
[ext_resource type="Texture2D" uid="uid://cgvpelj36koye" path="res://player2.png" id="3_q8tsx"]
@@ -44,6 +44,6 @@ sprite_frames = SubResource("SpriteFrames_oncqu")
animation = &"idle"
speed_scale = 0.5
-[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
+[node name="shape" type="CollisionShape2D" parent="."]
rotation = 1.5708
shape = SubResource("CapsuleShape2D_i3f4t")
diff --git a/Player.gd b/Player.gd
deleted file mode 100644
index b2f05b7..0000000
--- a/Player.gd
+++ /dev/null
@@ -1,28 +0,0 @@
-extends CharacterBody2D
-
-@export var speed := 80.0 # px/s
-
-func _ready() -> void:
- $sprite.play("idle")
-
-func _physics_process(_dt: float) -> void:
- if Input.is_action_pressed("ui_left"):
- velocity.x = -speed
- elif Input.is_action_pressed("ui_right"):
- velocity.x = speed
- else:
- velocity.x = 0.0
-
- if Input.is_action_pressed("ui_up"):
- velocity.y = -speed
- elif Input.is_action_pressed("ui_down"):
- velocity.y = speed
- else:
- velocity.y = 0.0
-
- if velocity.x != 0 or velocity.y != 0:
- $sprite.play("walk")
- else:
- $sprite.play("idle")
-
- move_and_slide()
diff --git a/PlayerController.gd b/PlayerController.gd
new file mode 100644
index 0000000..adecb8e
--- /dev/null
+++ b/PlayerController.gd
@@ -0,0 +1,43 @@
+extends Node
+
+@onready var is_mobile := (OS.has_feature("mobile") or OS.has_feature("web_android") or OS.has_feature("web_ios"))
+@onready var controller_overlay: CanvasLayer = $controller_overlay
+@onready var analog_stick_area: Control = $controller_overlay/analog_stick_area
+@onready var analog_stick: TextureRect = $controller_overlay/analog_stick_area/analog_stick
+@onready var analog_stick_p0 := analog_stick.position + .5 * analog_stick.size
+
+var input_node: Node : get = get_input_node
+var _analog_stick_pressed := false
+
+func _ready() -> void:
+ if is_mobile:
+ set_process_input(false)
+ analog_stick_area.connect("gui_input", self._on_analog_stick_area_gui_input)
+
+ controller_overlay.visible = is_mobile
+
+func get_input_node() -> Node:
+ var node := get_parent()
+ if not (node and "input_dir" in node):
+ return null
+ return node
+
+func _input(event: InputEvent) -> void:
+ if event.is_action_pressed("ui_right") or event.is_action_released("ui_left"):
+ input_node.input_dir.x += 1
+ elif event.is_action_pressed("ui_left") or event.is_action_released("ui_right"):
+ input_node.input_dir.x -= 1
+
+ if event.is_action_pressed("ui_down") or event.is_action_released("ui_up"):
+ input_node.input_dir.y += 1
+ elif event.is_action_pressed("ui_up") or event.is_action_released("ui_down"):
+ input_node.input_dir.y -= 1
+
+func _on_analog_stick_area_gui_input(event: InputEvent) -> void:
+ if event is InputEventMouse:
+ if event is InputEventMouseButton:
+ _analog_stick_pressed = event.pressed
+
+ var dp: Vector2 = (event.position - analog_stick_p0) if _analog_stick_pressed else Vector2.ZERO
+ analog_stick.position = analog_stick_p0 - .5 * analog_stick.size + dp.limit_length(10.0)
+ input_node.input_dir = dp.normalized()
diff --git a/PlayerController.tscn b/PlayerController.tscn
new file mode 100644
index 0000000..605207d
--- /dev/null
+++ b/PlayerController.tscn
@@ -0,0 +1,55 @@
+[gd_scene load_steps=4 format=3 uid="uid://cynystnt5cwlg"]
+
+[ext_resource type="Script" path="res://PlayerController.gd" id="1_1rp1b"]
+[ext_resource type="Texture2D" uid="uid://d2xwesqf3dwgn" path="res://analog_stick_back.png" id="2_c8ft0"]
+[ext_resource type="Texture2D" uid="uid://dvwlyke01vja6" path="res://analog_stick.png" id="3_y2opl"]
+
+[node name="PlayerController" type="Node"]
+script = ExtResource("1_1rp1b")
+
+[node name="controller_overlay" type="CanvasLayer" parent="."]
+
+[node name="analog_stick_area" type="Control" parent="controller_overlay"]
+modulate = Color(1, 1, 1, 0.784314)
+layout_mode = 3
+anchors_preset = 3
+anchor_left = 1.0
+anchor_top = 1.0
+anchor_right = 1.0
+anchor_bottom = 1.0
+offset_left = -188.0
+offset_top = -106.0
+grow_horizontal = 0
+grow_vertical = 0
+
+[node name="analog_stick_back" type="TextureRect" parent="controller_overlay/analog_stick_area"]
+layout_mode = 1
+anchors_preset = 8
+anchor_left = 0.5
+anchor_top = 0.5
+anchor_right = 0.5
+anchor_bottom = 0.5
+offset_left = -26.0
+offset_top = -26.0
+offset_right = 27.0
+offset_bottom = 29.0
+grow_horizontal = 2
+grow_vertical = 2
+pivot_offset = Vector2(26, 26)
+texture = ExtResource("2_c8ft0")
+
+[node name="analog_stick" type="TextureRect" parent="controller_overlay/analog_stick_area"]
+layout_mode = 1
+anchors_preset = 8
+anchor_left = 0.5
+anchor_top = 0.5
+anchor_right = 0.5
+anchor_bottom = 0.5
+offset_left = -17.0
+offset_top = -17.0
+offset_right = 19.0
+offset_bottom = 19.0
+grow_horizontal = 2
+grow_vertical = 2
+pivot_offset = Vector2(18, 18)
+texture = ExtResource("3_y2opl")
diff --git a/analog_stick.png b/analog_stick.png
new file mode 100644
index 0000000..f694ec3
Binary files /dev/null and b/analog_stick.png differ
diff --git a/analog_stick.png.import b/analog_stick.png.import
new file mode 100644
index 0000000..582193c
--- /dev/null
+++ b/analog_stick.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://dvwlyke01vja6"
+path="res://.godot/imported/analog_stick.png-5d2275d6ebe2919d5d387624cc7da419.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://analog_stick.png"
+dest_files=["res://.godot/imported/analog_stick.png-5d2275d6ebe2919d5d387624cc7da419.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1
diff --git a/analog_stick_back.png b/analog_stick_back.png
new file mode 100644
index 0000000..aaa0cca
Binary files /dev/null and b/analog_stick_back.png differ
diff --git a/analog_stick_back.png.import b/analog_stick_back.png.import
new file mode 100644
index 0000000..0434ffd
--- /dev/null
+++ b/analog_stick_back.png.import
@@ -0,0 +1,34 @@
+[remap]
+
+importer="texture"
+type="CompressedTexture2D"
+uid="uid://d2xwesqf3dwgn"
+path="res://.godot/imported/analog_stick_back.png-d375c6dee471c5611230040f9349da31.ctex"
+metadata={
+"vram_texture": false
+}
+
+[deps]
+
+source_file="res://analog_stick_back.png"
+dest_files=["res://.godot/imported/analog_stick_back.png-d375c6dee471c5611230040f9349da31.ctex"]
+
+[params]
+
+compress/mode=0
+compress/high_quality=false
+compress/lossy_quality=0.7
+compress/hdr_compression=1
+compress/normal_map=0
+compress/channel_pack=0
+mipmaps/generate=false
+mipmaps/limit=-1
+roughness/mode=0
+roughness/src_normal=""
+process/fix_alpha_border=true
+process/premult_alpha=false
+process/normal_map_invert_y=false
+process/hdr_as_srgb=false
+process/hdr_clamp_exposure=false
+process/size_limit=0
+detect_3d/compress_to=1
diff --git a/docs/index.html b/docs/index.html
index dceced4..f213a79 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -97,7 +97,7 @@ body {