From 0f6f75e8c574a940c972338527d01876a0b7107d Mon Sep 17 00:00:00 2001 From: Lucas Peter Date: Thu, 25 Jul 2024 12:02:35 +0200 Subject: [PATCH 1/5] Sticker init --- core/Sticker.gd | 23 +++++++++++++++++++++++ core/Sticker.tscn | 3 +++ 2 files changed, 26 insertions(+) create mode 100644 core/Sticker.gd create mode 100644 core/Sticker.tscn diff --git a/core/Sticker.gd b/core/Sticker.gd new file mode 100644 index 0000000..28be263 --- /dev/null +++ b/core/Sticker.gd @@ -0,0 +1,23 @@ +extends Node + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass + + +func _on_area_2d_mouse_entered(): + pass # Replace with function body. + + +func _on_area_2d_mouse_exited(): + pass # Replace with function body. + + +func _on_tree_entered(): + pass # Replace with function body. diff --git a/core/Sticker.tscn b/core/Sticker.tscn new file mode 100644 index 0000000..d84669e --- /dev/null +++ b/core/Sticker.tscn @@ -0,0 +1,3 @@ +[gd_scene format=3 uid="uid://kbso0l2uk2n7"] + +[node name="Sticker" type="Node"] From 7064af0707262ce0876bd54ccc01d84c7d42dd62 Mon Sep 17 00:00:00 2001 From: Lucas Peter Date: Thu, 25 Jul 2024 14:08:44 +0200 Subject: [PATCH 2/5] cursor code --- core/Cursor.tscn | 36 +++++++++++++++++++ core/sceneInstance.gd | 5 ++- project.godot | 20 +++++++++++ .../atlas}/SPRT_Hand.png | 0 .../atlas}/SPRT_Hand.png.import | 6 ++-- 5 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 core/Cursor.tscn rename {extracted/Texture2D => textures/atlas}/SPRT_Hand.png (100%) rename {extracted/Texture2D => textures/atlas}/SPRT_Hand.png.import (71%) diff --git a/core/Cursor.tscn b/core/Cursor.tscn new file mode 100644 index 0000000..205833f --- /dev/null +++ b/core/Cursor.tscn @@ -0,0 +1,36 @@ +[gd_scene load_steps=4 format=3 uid="uid://524sv8spw6go"] + +[ext_resource type="Texture2D" uid="uid://docoki1q4vvfh" path="res://textures/atlas/SPRT_Hand.png" id="1_va1hk"] + +[sub_resource type="GDScript" id="GDScript_h2l04"] +script/source = "extends Node2D + +const Speed:float = 900 + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + var mouse = get_viewport().get_mouse_position() + var old_pos + if (mouse != old_pos): + position = mouse + old_pos = position +" + +[sub_resource type="AtlasTexture" id="AtlasTexture_n2i6f"] +atlas = ExtResource("1_va1hk") +region = Rect2(0, 0, 256, 256) + +[node name="Cursor" type="Node2D"] +top_level = true +script = SubResource("GDScript_h2l04") + +[node name="Sprite2D" type="Sprite2D" parent="."] +scale = Vector2(0.5, 0.5) +texture = SubResource("AtlasTexture_n2i6f") +centered = false +offset = Vector2(-23.615, -235.42) diff --git a/core/sceneInstance.gd b/core/sceneInstance.gd index e61b1ff..4e3cbf1 100644 --- a/core/sceneInstance.gd +++ b/core/sceneInstance.gd @@ -1,5 +1,7 @@ extends Node2D + + @export var InitialPlayer :PackedScene @export var InitialMap :PackedScene @@ -20,7 +22,7 @@ func transition_to_scene(new_scene: PackedScene, spawn_location = Vector2(0,0), player = $CurrentScene.find_child("player",true) if (player): player.teleport(spawn_location, spawn_direction) - else: + else: #Spawn the player if there is none if (InitialPlayer): player = InitialPlayer.instantiate() player.set_name("player") @@ -31,3 +33,4 @@ func transition_to_scene(new_scene: PackedScene, spawn_location = Vector2(0,0), func _on_ready(): transition_to_scene(InitialMap,Vector2(0,0),1) + Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) diff --git a/project.godot b/project.godot index 8745515..ff9f02f 100644 --- a/project.godot +++ b/project.godot @@ -76,6 +76,26 @@ menu={ , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"echo":false,"script":null) ] } +mouse_up={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":-1.0,"script":null) +] +} +mouse_down={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null) +] +} +mouse_left={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":-1.0,"script":null) +] +} +mouse_right={ +"deadzone": 0.5, +"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":1.0,"script":null) +] +} [layer_names] diff --git a/extracted/Texture2D/SPRT_Hand.png b/textures/atlas/SPRT_Hand.png similarity index 100% rename from extracted/Texture2D/SPRT_Hand.png rename to textures/atlas/SPRT_Hand.png diff --git a/extracted/Texture2D/SPRT_Hand.png.import b/textures/atlas/SPRT_Hand.png.import similarity index 71% rename from extracted/Texture2D/SPRT_Hand.png.import rename to textures/atlas/SPRT_Hand.png.import index 8930e26..b106d00 100644 --- a/extracted/Texture2D/SPRT_Hand.png.import +++ b/textures/atlas/SPRT_Hand.png.import @@ -3,15 +3,15 @@ importer="texture" type="CompressedTexture2D" uid="uid://docoki1q4vvfh" -path="res://.godot/imported/SPRT_Hand.png-10f10cc13ae4b0331523734719309ebe.ctex" +path="res://.godot/imported/SPRT_Hand.png-f682339cd646a6350ee80c8d3fc09b3b.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://extracted/Texture2D/SPRT_Hand.png" -dest_files=["res://.godot/imported/SPRT_Hand.png-10f10cc13ae4b0331523734719309ebe.ctex"] +source_file="res://textures/atlas/SPRT_Hand.png" +dest_files=["res://.godot/imported/SPRT_Hand.png-f682339cd646a6350ee80c8d3fc09b3b.ctex"] [params] From 2d87d3beab14c12b8d7e4d417dad9d1691cc66ea Mon Sep 17 00:00:00 2001 From: Lucas Peter Date: Thu, 25 Jul 2024 16:36:40 +0200 Subject: [PATCH 3/5] Cursor work --- core/Cursor.tscn | 103 ++++++++++++++++++++++++++++++----- core/Sticker.tscn | 31 ++++++++++- core/sceneInstance.gd | 2 +- export_presets.cfg | 63 +++++++++++++++++++++ maps/mapManager.tscn | 5 +- textures/cursor_default.tres | 7 +++ textures/cursor_grab.tres | 21 +++++++ textures/cursor_grab_01.tres | 7 +++ textures/cursor_grab_02.tres | 7 +++ textures/cursor_grab_03.tres | 7 +++ 10 files changed, 234 insertions(+), 19 deletions(-) create mode 100644 export_presets.cfg create mode 100644 textures/cursor_default.tres create mode 100644 textures/cursor_grab.tres create mode 100644 textures/cursor_grab_01.tres create mode 100644 textures/cursor_grab_02.tres create mode 100644 textures/cursor_grab_03.tres diff --git a/core/Cursor.tscn b/core/Cursor.tscn index 205833f..4634b2a 100644 --- a/core/Cursor.tscn +++ b/core/Cursor.tscn @@ -1,36 +1,109 @@ -[gd_scene load_steps=4 format=3 uid="uid://524sv8spw6go"] +[gd_scene load_steps=7 format=3 uid="uid://524sv8spw6go"] -[ext_resource type="Texture2D" uid="uid://docoki1q4vvfh" path="res://textures/atlas/SPRT_Hand.png" id="1_va1hk"] +[ext_resource type="Texture2D" uid="uid://q1rdbr8uh78r" path="res://textures/cursor_default.tres" id="1_50ts1"] +[ext_resource type="Texture2D" uid="uid://buxws7r3kn0d7" path="res://textures/cursor_grab_01.tres" id="3_fj3w4"] +[ext_resource type="Texture2D" uid="uid://pbahcjllgjjq" path="res://textures/cursor_grab_02.tres" id="4_153q8"] +[ext_resource type="Texture2D" uid="uid://6fajq480n7se" path="res://textures/cursor_grab_03.tres" id="5_tsejy"] [sub_resource type="GDScript" id="GDScript_h2l04"] script/source = "extends Node2D const Speed:float = 900 +var spaceState +var query +var CastResult +var old_result +var selectedSticker + + # Called when the node enters the scene tree for the first time. func _ready(): - pass # Replace with function body. - + if not OS.is_debug_build(): + Input.set_mouse_mode(Input.MOUSE_MODE_CONFINED_HIDDEN) + query = PhysicsPointQueryParameters2D.new() + spaceState = get_world_2d() # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): - var mouse = get_viewport().get_mouse_position() + + #region Mouse Position var old_pos - if (mouse != old_pos): - position = mouse - old_pos = position + #if (get_global_mouse_position() != old_pos): + position = get_global_mouse_position() + old_pos = position + #endregion + + pointcast() + cursor_look() + + +func pointcast(): + query.collide_with_areas = true + query.position = get_global_mouse_position() + CastResult = spaceState.direct_space_state.intersect_point(query) + if ( (CastResult.size() > 0) and (old_result != CastResult) ): + old_result = CastResult + for _result in CastResult: + if (_result.collider.input_pickable == true): + selectedSticker = _result.collider.get_parent() + print(\"selected sticker %\",selectedSticker) + + + if (CastResult.size() == 0): + CastResult.clear() + old_result = null + selectedSticker = null + +func cursor_look(): + if (selectedSticker): + $AnimatedSprite2D.play(\"grab_intro\") + + else: + $AnimatedSprite2D.play(\"default\") " -[sub_resource type="AtlasTexture" id="AtlasTexture_n2i6f"] -atlas = ExtResource("1_va1hk") -region = Rect2(0, 0, 256, 256) +[sub_resource type="SpriteFrames" id="SpriteFrames_u3xkr"] +resource_local_to_scene = true +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": ExtResource("1_50ts1") +}], +"loop": true, +"name": &"default", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": ExtResource("3_fj3w4") +}, { +"duration": 1.0, +"texture": ExtResource("4_153q8") +}, { +"duration": 1.0, +"texture": ExtResource("5_tsejy") +}], +"loop": false, +"name": &"grab", +"speed": 7.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": ExtResource("3_fj3w4") +}], +"loop": true, +"name": &"grab_intro", +"speed": 5.0 +}] [node name="Cursor" type="Node2D"] top_level = true script = SubResource("GDScript_h2l04") -[node name="Sprite2D" type="Sprite2D" parent="."] -scale = Vector2(0.5, 0.5) -texture = SubResource("AtlasTexture_n2i6f") +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] +scale = Vector2(1.5, 1.5) +sprite_frames = SubResource("SpriteFrames_u3xkr") +autoplay = "default" centered = false -offset = Vector2(-23.615, -235.42) +offset = Vector2(-80, -190) diff --git a/core/Sticker.tscn b/core/Sticker.tscn index d84669e..659b22d 100644 --- a/core/Sticker.tscn +++ b/core/Sticker.tscn @@ -1,3 +1,30 @@ -[gd_scene format=3 uid="uid://kbso0l2uk2n7"] +[gd_scene load_steps=2 format=3 uid="uid://kbso0l2uk2n7"] -[node name="Sticker" type="Node"] +[sub_resource type="GDScript" id="GDScript_4kxk0"] +script/source = "extends Area2D + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass + + +func _on_mouse_entered(): + pass # Replace with function body. + + +func _on_mouse_exited(): + pass # Replace with function body. +" + +[node name="StickerDetection" type="Area2D"] +monitoring = false +script = SubResource("GDScript_4kxk0") + +[connection signal="mouse_entered" from="." to="." method="_on_mouse_entered"] +[connection signal="mouse_exited" from="." to="." method="_on_mouse_exited"] diff --git a/core/sceneInstance.gd b/core/sceneInstance.gd index 4e3cbf1..1453f69 100644 --- a/core/sceneInstance.gd +++ b/core/sceneInstance.gd @@ -33,4 +33,4 @@ func transition_to_scene(new_scene: PackedScene, spawn_location = Vector2(0,0), func _on_ready(): transition_to_scene(InitialMap,Vector2(0,0),1) - Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED) + diff --git a/export_presets.cfg b/export_presets.cfg new file mode 100644 index 0000000..dd4e57c --- /dev/null +++ b/export_presets.cfg @@ -0,0 +1,63 @@ +[preset.0] + +name="StickerCole" +platform="Windows Desktop" +runnable=true +dedicated_server=false +custom_features="" +export_filter="scenes" +export_files=PackedStringArray("res://maps/mainMenu.tscn", "res://maps/map1.tscn", "res://maps/mapManager.tscn") +include_filter="" +exclude_filter="" +export_path="builds/stickerClone.exe" +encryption_include_filters="" +encryption_exclude_filters="" +encrypt_pck=false +encrypt_directory=false + +[preset.0.options] + +custom_template/debug="" +custom_template/release="" +debug/export_console_wrapper=1 +binary_format/embed_pck=false +texture_format/bptc=true +texture_format/s3tc=true +texture_format/etc=false +texture_format/etc2=false +binary_format/architecture="x86_64" +codesign/enable=false +codesign/timestamp=true +codesign/timestamp_server_url="" +codesign/digest_algorithm=1 +codesign/description="" +codesign/custom_options=PackedStringArray() +application/modify_resources=true +application/icon="" +application/console_wrapper_icon="" +application/icon_interpolation=4 +application/file_version="" +application/product_version="" +application/company_name="" +application/product_name="" +application/file_description="" +application/copyright="" +application/trademarks="" +application/export_angle=0 +ssh_remote_deploy/enabled=false +ssh_remote_deploy/host="user@host_ip" +ssh_remote_deploy/port="22" +ssh_remote_deploy/extra_args_ssh="" +ssh_remote_deploy/extra_args_scp="" +ssh_remote_deploy/run_script="Expand-Archive -LiteralPath '{temp_dir}\\{archive_name}' -DestinationPath '{temp_dir}' +$action = New-ScheduledTaskAction -Execute '{temp_dir}\\{exe_name}' -Argument '{cmd_args}' +$trigger = New-ScheduledTaskTrigger -Once -At 00:00 +$settings = New-ScheduledTaskSettingsSet +$task = New-ScheduledTask -Action $action -Trigger $trigger -Settings $settings +Register-ScheduledTask godot_remote_debug -InputObject $task -Force:$true +Start-ScheduledTask -TaskName godot_remote_debug +while (Get-ScheduledTask -TaskName godot_remote_debug | ? State -eq running) { Start-Sleep -Milliseconds 100 } +Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue" +ssh_remote_deploy/cleanup_script="Stop-ScheduledTask -TaskName godot_remote_debug -ErrorAction:SilentlyContinue +Unregister-ScheduledTask -TaskName godot_remote_debug -Confirm:$false -ErrorAction:SilentlyContinue +Remove-Item -Recurse -Force '{temp_dir}'" diff --git a/maps/mapManager.tscn b/maps/mapManager.tscn index 95d1b6f..1b3d656 100644 --- a/maps/mapManager.tscn +++ b/maps/mapManager.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=4 format=3 uid="uid://d382cexpr4075"] +[gd_scene load_steps=5 format=3 uid="uid://d382cexpr4075"] [ext_resource type="Script" path="res://core/sceneInstance.gd" id="1_p0vo1"] [ext_resource type="PackedScene" uid="uid://0m1hk2nu4bps" path="res://core/player.tscn" id="2_fyjh8"] [ext_resource type="PackedScene" uid="uid://wlqsvbqpcbh" path="res://maps/map1.tscn" id="2_qgqfi"] +[ext_resource type="PackedScene" uid="uid://524sv8spw6go" path="res://core/Cursor.tscn" id="4_uwedi"] [node name="MapManager" type="Node2D"] script = ExtResource("1_p0vo1") @@ -11,4 +12,6 @@ InitialMap = ExtResource("2_qgqfi") [node name="CurrentScene" type="Node2D" parent="."] +[node name="Cursor" parent="." instance=ExtResource("4_uwedi")] + [connection signal="ready" from="." to="." method="_on_ready"] diff --git a/textures/cursor_default.tres b/textures/cursor_default.tres new file mode 100644 index 0000000..b489317 --- /dev/null +++ b/textures/cursor_default.tres @@ -0,0 +1,7 @@ +[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://q1rdbr8uh78r"] + +[ext_resource type="Texture2D" uid="uid://docoki1q4vvfh" path="res://textures/atlas/SPRT_Hand.png" id="1_n6y0a"] + +[resource] +atlas = ExtResource("1_n6y0a") +region = Rect2(0, 0, 256, 256) diff --git a/textures/cursor_grab.tres b/textures/cursor_grab.tres new file mode 100644 index 0000000..697a4c4 --- /dev/null +++ b/textures/cursor_grab.tres @@ -0,0 +1,21 @@ +[gd_resource type="AnimatedTexture" load_steps=5 format=3 uid="uid://sgwck5ca17s1"] + +[ext_resource type="Texture2D" uid="uid://q1rdbr8uh78r" path="res://textures/cursor_default.tres" id="1_k7xih"] +[ext_resource type="Texture2D" uid="uid://docoki1q4vvfh" path="res://textures/atlas/SPRT_Hand.png" id="1_ltia2"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_gpt2k"] +atlas = ExtResource("1_ltia2") +region = Rect2(0, 256, 256, 256) + +[sub_resource type="AtlasTexture" id="AtlasTexture_hq7jx"] +atlas = ExtResource("1_ltia2") +region = Rect2(256, 256, 256, 256) + +[resource] +frames = 3 +frame_0/texture = ExtResource("1_k7xih") +frame_0/duration = 0.5 +frame_1/texture = SubResource("AtlasTexture_gpt2k") +frame_1/duration = 0.5 +frame_2/texture = SubResource("AtlasTexture_hq7jx") +frame_2/duration = 0.5 diff --git a/textures/cursor_grab_01.tres b/textures/cursor_grab_01.tres new file mode 100644 index 0000000..1652569 --- /dev/null +++ b/textures/cursor_grab_01.tres @@ -0,0 +1,7 @@ +[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://buxws7r3kn0d7"] + +[ext_resource type="Texture2D" uid="uid://docoki1q4vvfh" path="res://textures/atlas/SPRT_Hand.png" id="1_xhy8h"] + +[resource] +atlas = ExtResource("1_xhy8h") +region = Rect2(256, 0, 256, 256) diff --git a/textures/cursor_grab_02.tres b/textures/cursor_grab_02.tres new file mode 100644 index 0000000..6f465f0 --- /dev/null +++ b/textures/cursor_grab_02.tres @@ -0,0 +1,7 @@ +[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://pbahcjllgjjq"] + +[ext_resource type="Texture2D" uid="uid://docoki1q4vvfh" path="res://textures/atlas/SPRT_Hand.png" id="1_it2wc"] + +[resource] +atlas = ExtResource("1_it2wc") +region = Rect2(0, 256, 256, 256) diff --git a/textures/cursor_grab_03.tres b/textures/cursor_grab_03.tres new file mode 100644 index 0000000..6fd4d71 --- /dev/null +++ b/textures/cursor_grab_03.tres @@ -0,0 +1,7 @@ +[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://6fajq480n7se"] + +[ext_resource type="Texture2D" uid="uid://docoki1q4vvfh" path="res://textures/atlas/SPRT_Hand.png" id="1_r8woc"] + +[resource] +atlas = ExtResource("1_r8woc") +region = Rect2(256, 256, 256, 256) From f60105d56aa3c06afc5dfb0c3f9e5bcdfc247d76 Mon Sep 17 00:00:00 2001 From: Lucas Peter Date: Thu, 25 Jul 2024 18:26:18 +0200 Subject: [PATCH 4/5] cursor state machine --- core/Cur6C3A.tmp | 121 +++++++++++++++++++++++++++++++++++++ core/Cur9BFD.tmp | 121 +++++++++++++++++++++++++++++++++++++ core/Cursor.tscn | 49 ++++++++++++--- textures/cursor_click.tres | 9 +++ 4 files changed, 290 insertions(+), 10 deletions(-) create mode 100644 core/Cur6C3A.tmp create mode 100644 core/Cur9BFD.tmp create mode 100644 textures/cursor_click.tres diff --git a/core/Cur6C3A.tmp b/core/Cur6C3A.tmp new file mode 100644 index 0000000..c7d29a3 --- /dev/null +++ b/core/Cur6C3A.tmp @@ -0,0 +1,121 @@ +[gd_scene load_steps=8 format=3 uid="uid://524sv8spw6go"] + +[ext_resource type="Texture2D" uid="uid://q1rdbr8uh78r" path="res://textures/cursor_default.tres" id="1_50ts1"] +[ext_resource type="Texture2D" uid="uid://bdstohvc7pvot" path="res://textures/cursor_click.tres" id="1_h0do2"] +[ext_resource type="Texture2D" uid="uid://buxws7r3kn0d7" path="res://textures/cursor_grab_01.tres" id="3_fj3w4"] +[ext_resource type="Texture2D" uid="uid://pbahcjllgjjq" path="res://textures/cursor_grab_02.tres" id="4_153q8"] +[ext_resource type="Texture2D" uid="uid://6fajq480n7se" path="res://textures/cursor_grab_03.tres" id="5_tsejy"] + +[sub_resource type="GDScript" id="GDScript_h2l04"] +script/source = "extends Node2D + +const Speed:float = 900 + +var spaceState +var query +var CastResult +var old_result +var selectedSticker + + +# Called when the node enters the scene tree for the first time. +func _ready(): + if not OS.is_debug_build(): + Input.set_mouse_mode(Input.MOUSE_MODE_CONFINED_HIDDEN) + query = PhysicsPointQueryParameters2D.new() + spaceState = get_world_2d() + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + + #region Mouse Position + position = get_global_mouse_position() + #endregion + + pointcast() + cursor_look() + + +func pointcast(): + query.collide_with_areas = true + query.position = get_global_mouse_position() + CastResult = spaceState.direct_space_state.intersect_point(query) + if ( (CastResult.size() > 0) and (old_result != CastResult) ): + old_result = CastResult + for _result in CastResult: + if (_result.collider.input_pickable == true): + selectedSticker = _result.collider.get_parent() + print(\"selected sticker %\",selectedSticker) + + + if (CastResult.size() == 0): + CastResult.clear() + old_result = null + selectedSticker = null + +func cursor_look(): + $AnimatedSprite2D.play(\"default\") + if (Input.is_action_pressed(\"select\")): + if (selectedSticker): + $AnimatedSprite2D.play(\"grab\") + else: + $AnimatedSprite2D.play(\"click\") + else: + if (selectedSticker): + $AnimatedSprite2D.play(\"grab_intro\") + + +" + +[sub_resource type="SpriteFrames" id="SpriteFrames_u3xkr"] +resource_local_to_scene = true +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": ExtResource("1_h0do2") +}], +"loop": true, +"name": &"click", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": ExtResource("1_50ts1") +}], +"loop": true, +"name": &"default", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": ExtResource("3_fj3w4") +}, { +"duration": 1.0, +"texture": ExtResource("4_153q8") +}, { +"duration": 1.0, +"texture": ExtResource("5_tsejy") +}], +"loop": true, +"name": &"grab", +"speed": 7.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": ExtResource("3_fj3w4") +}], +"loop": true, +"name": &"grab_intro", +"speed": 5.0 +}] + +[node name="Cursor" type="Node2D"] +top_level = true +script = SubResource("GDScript_h2l04") + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] +scale = Vector2(1.5, 1.5) +sprite_frames = SubResource("SpriteFrames_u3xkr") +animation = &"grab" +centered = false +offset = Vector2(-80, -190) diff --git a/core/Cur9BFD.tmp b/core/Cur9BFD.tmp new file mode 100644 index 0000000..6e61b2c --- /dev/null +++ b/core/Cur9BFD.tmp @@ -0,0 +1,121 @@ +[gd_scene load_steps=8 format=3 uid="uid://524sv8spw6go"] + +[ext_resource type="Texture2D" uid="uid://q1rdbr8uh78r" path="res://textures/cursor_default.tres" id="1_50ts1"] +[ext_resource type="Texture2D" uid="uid://bdstohvc7pvot" path="res://textures/cursor_click.tres" id="1_h0do2"] +[ext_resource type="Texture2D" uid="uid://buxws7r3kn0d7" path="res://textures/cursor_grab_01.tres" id="3_fj3w4"] +[ext_resource type="Texture2D" uid="uid://pbahcjllgjjq" path="res://textures/cursor_grab_02.tres" id="4_153q8"] +[ext_resource type="Texture2D" uid="uid://6fajq480n7se" path="res://textures/cursor_grab_03.tres" id="5_tsejy"] + +[sub_resource type="GDScript" id="GDScript_h2l04"] +script/source = "extends Node2D + +const Speed:float = 900 + +var spaceState +var query +var CastResult +var old_result +var selectedSticker + + +# Called when the node enters the scene tree for the first time. +func _ready(): + if not OS.is_debug_build(): + Input.set_mouse_mode(Input.MOUSE_MODE_CONFINED_HIDDEN) + query = PhysicsPointQueryParameters2D.new() + spaceState = get_world_2d() + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + + #region Mouse Position + position = get_global_mouse_position() + #endregion + + pointcast() + cursor_look() + + +func pointcast(): + query.collide_with_areas = true + query.position = get_global_mouse_position() + CastResult = spaceState.direct_space_state.intersect_point(query) + if ( (CastResult.size() > 0) and (old_result != CastResult) ): + old_result = CastResult + for _result in CastResult: + if (_result.collider.input_pickable == true): + selectedSticker = _result.collider.get_parent() + print(\"selected sticker %\",selectedSticker) + + + if (CastResult.size() == 0): + CastResult.clear() + old_result = null + selectedSticker = null + +func cursor_look(): + $AnimatedSprite2D.play(\"default\") + if (Input.is_action_pressed(\"select\")): + if (selectedSticker): + $AnimatedSprite2D.play(\"grab\") + else: + $AnimatedSprite2D.play(\"click\") + if (selectedSticker): + $AnimatedSprite2D.play(\"grab_intro\") + + +" + +[sub_resource type="SpriteFrames" id="SpriteFrames_u3xkr"] +resource_local_to_scene = true +animations = [{ +"frames": [{ +"duration": 1.0, +"texture": ExtResource("1_h0do2") +}], +"loop": true, +"name": &"click", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": ExtResource("1_50ts1") +}], +"loop": true, +"name": &"default", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": ExtResource("3_fj3w4") +}, { +"duration": 1.0, +"texture": ExtResource("4_153q8") +}, { +"duration": 1.0, +"texture": ExtResource("5_tsejy") +}], +"loop": true, +"name": &"grab", +"speed": 7.0 +}, { +"frames": [{ +"duration": 1.0, +"texture": ExtResource("3_fj3w4") +}], +"loop": true, +"name": &"grab_intro", +"speed": 5.0 +}] + +[node name="Cursor" type="Node2D"] +top_level = true +script = SubResource("GDScript_h2l04") + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] +scale = Vector2(1.5, 1.5) +sprite_frames = SubResource("SpriteFrames_u3xkr") +animation = &"grab" +autoplay = "grab" +centered = false +offset = Vector2(-80, -190) diff --git a/core/Cursor.tscn b/core/Cursor.tscn index 4634b2a..19f7181 100644 --- a/core/Cursor.tscn +++ b/core/Cursor.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=7 format=3 uid="uid://524sv8spw6go"] +[gd_scene load_steps=8 format=3 uid="uid://524sv8spw6go"] [ext_resource type="Texture2D" uid="uid://q1rdbr8uh78r" path="res://textures/cursor_default.tres" id="1_50ts1"] +[ext_resource type="Texture2D" uid="uid://bdstohvc7pvot" path="res://textures/cursor_click.tres" id="1_h0do2"] [ext_resource type="Texture2D" uid="uid://buxws7r3kn0d7" path="res://textures/cursor_grab_01.tres" id="3_fj3w4"] [ext_resource type="Texture2D" uid="uid://pbahcjllgjjq" path="res://textures/cursor_grab_02.tres" id="4_153q8"] [ext_resource type="Texture2D" uid="uid://6fajq480n7se" path="res://textures/cursor_grab_03.tres" id="5_tsejy"] @@ -15,7 +16,9 @@ var query var CastResult var old_result var selectedSticker - +enum CURSOR_STATE {DEFAULT, CLICK, GRAB, GRABBED} +var currentCursorState:CURSOR_STATE +var oldCursorState:CURSOR_STATE # Called when the node enters the scene tree for the first time. func _ready(): @@ -28,10 +31,7 @@ func _ready(): func _process(delta): #region Mouse Position - var old_pos - #if (get_global_mouse_position() != old_pos): position = get_global_mouse_position() - old_pos = position #endregion pointcast() @@ -56,11 +56,29 @@ func pointcast(): selectedSticker = null func cursor_look(): - if (selectedSticker): - $AnimatedSprite2D.play(\"grab_intro\") - + + if (Input.is_action_pressed(\"select\")): + if (selectedSticker): + currentCursorState = CURSOR_STATE.GRABBED + else: + currentCursorState = CURSOR_STATE.CLICK else: - $AnimatedSprite2D.play(\"default\") + if (selectedSticker): + currentCursorState = CURSOR_STATE.GRAB + else: + currentCursorState = CURSOR_STATE.DEFAULT + + if (currentCursorState != oldCursorState): + oldCursorState = currentCursorState + match oldCursorState: + CURSOR_STATE.DEFAULT: + $AnimatedSprite2D.play(\"default\") + CURSOR_STATE.CLICK: + $AnimatedSprite2D.play(\"click\") + CURSOR_STATE.GRAB: + $AnimatedSprite2D.play(\"grab_intro\") + CURSOR_STATE.GRABBED: + $AnimatedSprite2D.play(\"grab\") " [sub_resource type="SpriteFrames" id="SpriteFrames_u3xkr"] @@ -68,6 +86,14 @@ resource_local_to_scene = true animations = [{ "frames": [{ "duration": 1.0, +"texture": ExtResource("1_h0do2") +}], +"loop": true, +"name": &"click", +"speed": 5.0 +}, { +"frames": [{ +"duration": 1.0, "texture": ExtResource("1_50ts1") }], "loop": true, @@ -104,6 +130,9 @@ script = SubResource("GDScript_h2l04") [node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."] scale = Vector2(1.5, 1.5) sprite_frames = SubResource("SpriteFrames_u3xkr") -autoplay = "default" +animation = &"grab" +autoplay = "grab" +frame = 2 +frame_progress = 1.0 centered = false offset = Vector2(-80, -190) diff --git a/textures/cursor_click.tres b/textures/cursor_click.tres new file mode 100644 index 0000000..411754c --- /dev/null +++ b/textures/cursor_click.tres @@ -0,0 +1,9 @@ +[gd_resource type="AtlasTexture" load_steps=2 format=3 uid="uid://bdstohvc7pvot"] + +[ext_resource type="Texture2D" uid="uid://docoki1q4vvfh" path="res://textures/atlas/SPRT_Hand.png" id="1_2ch11"] + +[resource] +atlas = ExtResource("1_2ch11") +region = Rect2(0, 0, 256, 256) +margin = Rect2(-5, 5, 5, 5) +filter_clip = true From cf08e821bcf52c3db7d06763edc426d819317a6b Mon Sep 17 00:00:00 2001 From: Lucas Peter Date: Fri, 26 Jul 2024 11:50:52 +0200 Subject: [PATCH 5/5] sticker system preparation --- core/Cursor.tscn | 30 ++++++++++++++--- core/player.gd | 6 +++- maps/map1.tscn | 57 ++++++++++++++++++++++++++++++- prefab/prefab_bush1.tscn | 60 +++++++++++++++++++++++++++++++++ prefab/prefab_woddenbridge.tscn | 1 + 5 files changed, 148 insertions(+), 6 deletions(-) create mode 100644 prefab/prefab_bush1.tscn diff --git a/core/Cursor.tscn b/core/Cursor.tscn index 19f7181..f515579 100644 --- a/core/Cursor.tscn +++ b/core/Cursor.tscn @@ -38,19 +38,41 @@ func _process(delta): cursor_look() +func isSticker(selectedObject:Node): + var _isSticker:bool = false + var _tags = getTags(selectedObject) + if (_tags.size() > 0): + if (_tags.find(\"sticker\") != -1): + _isSticker = true + + return _isSticker + +func getTags(selectedObject:Node): + var _tags: Array + if (selectedObject.has_meta(\"tags\")): + _tags = selectedObject.get_meta(\"tags\") + return _tags + else: + printerr(\"no tags inside %\",selectedObject) + return _tags + + func pointcast(): query.collide_with_areas = true query.position = get_global_mouse_position() CastResult = spaceState.direct_space_state.intersect_point(query) if ( (CastResult.size() > 0) and (old_result != CastResult) ): old_result = CastResult + if (CastResult.size()> 2): + breakpoint # should not detect multiple areas for _result in CastResult: if (_result.collider.input_pickable == true): selectedSticker = _result.collider.get_parent() - print(\"selected sticker %\",selectedSticker) - - - if (CastResult.size() == 0): + if (isSticker(selectedSticker)): + print(\"selected sticker %\",selectedSticker) + else: + selectedSticker = null + if (CastResult.size() == 0 ): CastResult.clear() old_result = null selectedSticker = null diff --git a/core/player.gd b/core/player.gd index b054690..e70a4f1 100644 --- a/core/player.gd +++ b/core/player.gd @@ -5,7 +5,7 @@ extends CharacterBody2D @export var CurrentHat: CanvasTexture const SPEED = 1000.0 - +const MOUSESPEED = 10.0 func teleport(location:Transform2D , direction:float = 1): transform = location scale = Vector2(direction,1) @@ -25,6 +25,8 @@ func changeSkin(NewSkin:CanvasTexture,_NewHat:CanvasTexture = null): func get_input(): var directionX = Input.get_axis("move_left", "move_right") var directionY = Input.get_axis("move_up", "move_down") + var mouseDirectionX = Input.get_axis("mouse_left", "mouse_right") + var mouseDirectionY = Input.get_axis("mouse_up", "mouse_down") #region Movement ## Get the input direction and handle the movement/deceleration. if directionX : @@ -36,6 +38,8 @@ func get_input(): else: velocity.y = move_toward(velocity.y, 0, SPEED) #endregion + var wantedMousePosition = get_viewport().get_mouse_position()+(Vector2(mouseDirectionX,mouseDirectionY)*MOUSESPEED) + get_viewport().warp_mouse(wantedMousePosition) #region Animation if (directionX < 0): $Skeleton2D/root/Hips.set_scale(Vector2(1, 1)) diff --git a/maps/map1.tscn b/maps/map1.tscn index 48fdc71..415bea4 100644 --- a/maps/map1.tscn +++ b/maps/map1.tscn @@ -1,10 +1,12 @@ -[gd_scene load_steps=9 format=3 uid="uid://wlqsvbqpcbh"] +[gd_scene load_steps=14 format=3 uid="uid://wlqsvbqpcbh"] [ext_resource type="Texture2D" uid="uid://cacwy4tka88k1" path="res://maps/map1.tres" id="1_pt5vq"] [ext_resource type="Texture2D" uid="uid://cxharyv0ajr37" path="res://textures/atlas/DioramaEntrance_All_01_SPRT.png" id="2_n7y5f"] [ext_resource type="Texture2D" uid="uid://c5bd2ta3esnib" path="res://extracted/4010-A Tiny Sticker Tale review pic 1.jpg" id="3_yh2wy"] [ext_resource type="PackedScene" uid="uid://bddcriwo55x8k" path="res://prefab/prefab_woddenbridge.tscn" id="4_okpsn"] [ext_resource type="Texture2D" uid="uid://dx8jpmxtm2cdx" path="res://textures/pattern/Pattern_Forest.png" id="5_i137q"] +[ext_resource type="Texture2D" uid="uid://cun14l52f477p" path="res://textures/atlas/Bushes_All_01_SPRT.png" id="5_xmosd"] +[ext_resource type="PackedScene" uid="uid://domcpxdf6lqpb" path="res://prefab/prefab_bush1.tscn" id="6_3fkbm"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_js06g"] @@ -16,7 +18,21 @@ region = Rect2(252, 16, 108, 256) atlas = ExtResource("2_n7y5f") region = Rect2(12, 96, 216, 112) +[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_lfx7b"] +radius = 80.0 +height = 254.0 + +[sub_resource type="AtlasTexture" id="AtlasTexture_rn40i"] +atlas = ExtResource("5_xmosd") +region = Rect2(736, 96, 224, 160) + +[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_b3366"] +radius = 50.0 +height = 160.0 + [node name="Map1" type="Node2D"] +z_as_relative = false +y_sort_enabled = true material = SubResource("ShaderMaterial_js06g") [node name="Container" type="Control" parent="."] @@ -56,6 +72,8 @@ texture = ExtResource("5_i137q") stretch_mode = 1 [node name="Floors05Sprt" type="Sprite2D" parent="."] +z_index = -1 +z_as_relative = false scale = Vector2(6, 6) texture = ExtResource("1_pt5vq") region_rect = Rect2(0, 0, 1024, 992) @@ -96,3 +114,40 @@ top_level = true position = Vector2(78, -148) scale = Vector2(6.15, 6.15) texture = ExtResource("3_yh2wy") + +[node name="Bush1" parent="." instance=ExtResource("6_3fkbm")] +position = Vector2(-2161, 1140) +Shape = SubResource("CapsuleShape2D_lfx7b") + +[node name="Bush6" parent="." instance=ExtResource("6_3fkbm")] +position = Vector2(-1556, 293) +Shape = SubResource("CapsuleShape2D_lfx7b") + +[node name="Bush7" parent="." instance=ExtResource("6_3fkbm")] +position = Vector2(712, 293) +Shape = SubResource("CapsuleShape2D_lfx7b") + +[node name="Bush9" parent="." instance=ExtResource("6_3fkbm")] +position = Vector2(1004, -2257) +Shape = SubResource("CapsuleShape2D_lfx7b") + +[node name="Bush8" parent="." instance=ExtResource("6_3fkbm")] +position = Vector2(-1616, -1651) +offset = Vector2(-137.285, -179.785) +flip_h = true +Shape = SubResource("CapsuleShape2D_lfx7b") + +[node name="Bush10" parent="." instance=ExtResource("6_3fkbm")] +position = Vector2(-2063, -2116) +texture = SubResource("AtlasTexture_rn40i") +offset = Vector2(-108.615, -141.38) +flip_h = true +Shape = SubResource("CapsuleShape2D_b3366") +Position = Vector2(0, -48.95) + +[node name="Bush11" parent="." instance=ExtResource("6_3fkbm")] +position = Vector2(2208, 2337) +texture = SubResource("AtlasTexture_rn40i") +offset = Vector2(-108.615, -141.38) +Shape = SubResource("CapsuleShape2D_b3366") +Position = Vector2(0, -48.95) diff --git a/prefab/prefab_bush1.tscn b/prefab/prefab_bush1.tscn new file mode 100644 index 0000000..7dcc58e --- /dev/null +++ b/prefab/prefab_bush1.tscn @@ -0,0 +1,60 @@ +[gd_scene load_steps=4 format=3 uid="uid://domcpxdf6lqpb"] + +[ext_resource type="Texture2D" uid="uid://cun14l52f477p" path="res://textures/atlas/Bushes_All_01_SPRT.png" id="1_1wk1p"] + +[sub_resource type="AtlasTexture" id="AtlasTexture_2wdar"] +atlas = ExtResource("1_1wk1p") +region = Rect2(384, 64, 288, 224) + +[sub_resource type="GDScript" id="GDScript_uqtu8"] +script/source = "@tool +extends Sprite2D + +@export_group(\"Collision Shape\") +@export var Shape :Shape2D: + set(new_shape): + Shape = new_shape + $Area2D/CollisionShape2D.shape = Shape + $Area2D/CollisionShape2D.queue_redraw() +@export var Position :Vector2: + set(new_position): + Position = new_position + $Area2D/CollisionShape2D.position = Position + $Area2D/CollisionShape2D.queue_redraw() +@export var Rotation :Vector2: + set(new_rotation): + Rotation = new_rotation + $Area2D/CollisionShape2D.rotation = Rotation + $Area2D/CollisionShape2D.queue_redraw() + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass + + + + +" + +[node name="Bush1" type="Sprite2D"] +scale = Vector2(3.80334, 3.95089) +texture = SubResource("AtlasTexture_2wdar") +centered = false +offset = Vector2(-161.055, -179.785) +script = SubResource("GDScript_uqtu8") +metadata/tags = ["sticker"] + +[node name="Area2D" type="Area2D" parent="."] +collision_layer = 3 +monitoring = false + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] +position = Vector2(-4.46976, -71.6294) +rotation = 1.5708 + +[connection signal="property_list_changed" from="." to="." method="_on_property_list_changed"] diff --git a/prefab/prefab_woddenbridge.tscn b/prefab/prefab_woddenbridge.tscn index 0f5786b..17d6d7d 100644 --- a/prefab/prefab_woddenbridge.tscn +++ b/prefab/prefab_woddenbridge.tscn @@ -10,6 +10,7 @@ region = Rect2(72, 1392, 216, 272) [node name="WoodenBridge" type="Sprite2D"] scale = Vector2(5.71296, 5.71296) texture = SubResource("AtlasTexture_nkyhf") +metadata/tags = ["sticker"] [node name="BridgeNode" parent="." instance=ExtResource("2_te8ug")] position = Vector2(1788, 788)