This commit is contained in:
2025-02-06 23:39:13 +01:00
parent a41cbaedad
commit 5d80182781
17 changed files with 209 additions and 38 deletions

5
Level.gd Normal file
View File

@@ -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)

View File

@@ -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")]

19
MyChar.gd Normal file
View File

@@ -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")

View File

@@ -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")

View File

@@ -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()

43
PlayerController.gd Normal file
View File

@@ -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()

55
PlayerController.tscn Normal file
View File

@@ -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")

BIN
analog_stick.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

34
analog_stick.png.import Normal file
View File

@@ -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

BIN
analog_stick_back.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@@ -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

View File

@@ -97,7 +97,7 @@ body {
<script src="index.js"></script>
<script>
const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"ensureCrossOriginIsolationHeaders":true,"executable":"index","experimentalVK":false,"fileSizes":{"index.pck":65360,"index.wasm":35376909},"focusCanvas":true,"gdextensionLibs":[]};
const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"ensureCrossOriginIsolationHeaders":true,"executable":"index","experimentalVK":false,"fileSizes":{"index.pck":72208,"index.wasm":43016933},"focusCanvas":true,"gdextensionLibs":[]};
const GODOT_THREADS_ENABLED = false;
const engine = new Engine(GODOT_CONFIG);

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

View File

@@ -63,7 +63,7 @@ custom_template/release=""
variant/extensions_support=false
variant/thread_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=""
@@ -74,7 +74,7 @@ progressive_web_app/enabled=false
progressive_web_app/ensure_cross_origin_isolation_headers=true
progressive_web_app/offline_page=""
progressive_web_app/display=1
progressive_web_app/orientation=0
progressive_web_app/orientation=1
progressive_web_app/icon_144x144=""
progressive_web_app/icon_180x180=""
progressive_web_app/icon_512x512=""

View File

@@ -26,3 +26,7 @@ window/stretch/mode="viewport"
2d_navigation/layer_1="Terrain"
2d_navigation/layer_2="Water"
[rendering]
textures/vram_compression/import_etc2_astc=true