diff --git a/assets/textures/ice/ice.png b/assets/textures/ice/ice.png new file mode 100644 index 0000000..8073131 Binary files /dev/null and b/assets/textures/ice/ice.png differ diff --git a/assets/textures/ice/ice.png.import b/assets/textures/ice/ice.png.import new file mode 100644 index 0000000..f1ec8e8 --- /dev/null +++ b/assets/textures/ice/ice.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://d0e475k64fbja" +path="res://.godot/imported/ice.png-d75f02434fc47d5fed2ae33e954ca6d2.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/textures/ice/ice.png" +dest_files=["res://.godot/imported/ice.png-d75f02434fc47d5fed2ae33e954ca6d2.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/assets/textures/jelly/jelly.png b/assets/textures/jelly/jelly.png new file mode 100644 index 0000000..75311af Binary files /dev/null and b/assets/textures/jelly/jelly.png differ diff --git a/assets/textures/jelly/jelly.png.import b/assets/textures/jelly/jelly.png.import new file mode 100644 index 0000000..26a367e --- /dev/null +++ b/assets/textures/jelly/jelly.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://d3x8vjgistyb8" +path="res://.godot/imported/jelly.png-1bbbb6a8c7911962c52c884e3494c788.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/textures/jelly/jelly.png" +dest_files=["res://.godot/imported/jelly.png-1bbbb6a8c7911962c52c884e3494c788.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/maps/level1.tscn b/maps/level1.tscn index 0eaf43e..49ef243 100644 --- a/maps/level1.tscn +++ b/maps/level1.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=5 format=3 uid="uid://bbnq7ptk8hhxa"] +[gd_scene load_steps=6 format=3 uid="uid://bbnq7ptk8hhxa"] [ext_resource type="Texture2D" uid="uid://b6a7l24y30iht" path="res://assets/textures/backgrounds/chocomint.png" id="1_gk4ur"] [ext_resource type="PackedScene" uid="uid://mh2gfm7iqqsm" path="res://objects/player/player.tscn" id="2_kip56"] [ext_resource type="TileSet" uid="uid://xwfn24if3pxk" path="res://assets/tilesets/chocomint.tres" id="3_4td23"] [ext_resource type="PackedScene" uid="uid://68lav5rke5ag" path="res://objects/spring/spring.tscn" id="4_a3xei"] +[ext_resource type="PackedScene" uid="uid://b5eso40mjhlmv" path="res://objects/ice/ice.tscn" id="5_88a5a"] [node name="Level1" type="Node2D"] @@ -18,21 +19,36 @@ position = Vector2(31, 139) [node name="TileMap" type="TileMap" parent="."] tile_set = ExtResource("3_4td23") format = 2 -layer_0/tile_data = PackedInt32Array(720896, 0, 0, 720897, 0, 0, 720898, 0, 0, 720899, 0, 0, 720900, 0, 0, 720901, 0, 0, 720902, 0, 0, 720903, 0, 0, 720904, 0, 0, 720905, 0, 0, 720906, 0, 0, 720907, 0, 0, 720908, 0, 0, 720909, 0, 0, 720910, 0, 0, 720911, 0, 0, 720912, 0, 0, 720913, 0, 0) +layer_0/tile_data = PackedInt32Array(720896, 0, 0, 720897, 0, 0, 720898, 0, 0, 720903, 0, 0, 720904, 0, 0, 720905, 0, 0, 720906, 0, 0, 720907, 0, 0, 720909, 0, 0, 720910, 0, 0, 720911, 0, 0, 720912, 0, 0, 720913, 0, 0) [node name="Spring" parent="." instance=ExtResource("4_a3xei")] -position = Vector2(88, 176) +position = Vector2(96, 80) [node name="Spring2" parent="." instance=ExtResource("4_a3xei")] -position = Vector2(120, 176) +position = Vector2(128, 80) [node name="Spring3" parent="." instance=ExtResource("4_a3xei")] -position = Vector2(152, 176) +position = Vector2(160, 80) [node name="Spring4" parent="." instance=ExtResource("4_a3xei")] -position = Vector2(104, 120) +position = Vector2(112, 24) rotation = 3.14159 [node name="Spring5" parent="." instance=ExtResource("4_a3xei")] -position = Vector2(136, 120) +position = Vector2(144, 24) rotation = 3.14159 + +[node name="Ice" parent="." instance=ExtResource("5_88a5a")] +position = Vector2(200, 184) + +[node name="Ice2" parent="." instance=ExtResource("5_88a5a")] +position = Vector2(56, 184) + +[node name="Ice3" parent="." instance=ExtResource("5_88a5a")] +position = Vector2(72, 184) + +[node name="Ice4" parent="." instance=ExtResource("5_88a5a")] +position = Vector2(88, 184) + +[node name="Ice5" parent="." instance=ExtResource("5_88a5a")] +position = Vector2(104, 184) diff --git a/objects/ice/ice.gd b/objects/ice/ice.gd new file mode 100644 index 0000000..c061843 --- /dev/null +++ b/objects/ice/ice.gd @@ -0,0 +1,20 @@ +extends Node2D + + +# Called when the node enters the scene tree for the first time. +func _ready() -> void: + pass # Replace with function body. + + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta: float) -> void: + pass + + +func _on_area_2d_body_entered(body: Node2D) -> void: + if body is Player: + body.ices_touched += 1 + + +func _on_area_2d_body_exited(body: Node2D) -> void: + body.ices_touched -= 1 diff --git a/objects/ice/ice.tscn b/objects/ice/ice.tscn new file mode 100644 index 0000000..3d47a3f --- /dev/null +++ b/objects/ice/ice.tscn @@ -0,0 +1,34 @@ +[gd_scene load_steps=5 format=3 uid="uid://b5eso40mjhlmv"] + +[ext_resource type="Texture2D" uid="uid://d0e475k64fbja" path="res://assets/textures/ice/ice.png" id="1_0p7ug"] +[ext_resource type="Script" path="res://objects/ice/ice.gd" id="1_hgdc3"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_sv4q1"] +size = Vector2(16, 17) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_xodyg"] +size = Vector2(16, 16) + +[node name="Ice" type="Node2D"] +script = ExtResource("1_hgdc3") + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture = ExtResource("1_0p7ug") + +[node name="Area2D" type="Area2D" parent="."] +collision_layer = 0 +collision_mask = 16 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] +position = Vector2(0, -0.5) +shape = SubResource("RectangleShape2D_sv4q1") + +[node name="StaticBody2D" type="StaticBody2D" parent="."] +collision_layer = 2 +collision_mask = 16 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"] +shape = SubResource("RectangleShape2D_xodyg") + +[connection signal="body_entered" from="Area2D" to="." method="_on_area_2d_body_entered"] +[connection signal="body_exited" from="Area2D" to="." method="_on_area_2d_body_exited"] diff --git a/objects/player/player.gd b/objects/player/player.gd index 33fc1db..9d3bd2d 100644 --- a/objects/player/player.gd +++ b/objects/player/player.gd @@ -10,6 +10,14 @@ extends CharacterBody2D @export var state_chart: StateChart @export var graphics: Node2D +var ices_touched:int = 0: + set(value): + ices_touched = value + if ices_touched <= 0: + ices_touched = 0 + state_chart.send_event(&"ground_touched") + else: + state_chart.send_event(&"ice_touched") #region Notifications func _ready() -> void: diff --git a/objects/player/player.tscn b/objects/player/player.tscn index 957bfa8..b73e2e4 100644 --- a/objects/player/player.tscn +++ b/objects/player/player.tscn @@ -47,6 +47,8 @@ script = ExtResource("9_ht8un") expression = "player.velocity.y >= 0.0" [node name="Player" type="CharacterBody2D" node_paths=PackedStringArray("state_chart", "graphics")] +collision_layer = 16 +collision_mask = 3 floor_snap_length = 3.0 script = ExtResource("1_jgave") gravity = 400.0 @@ -120,6 +122,12 @@ to = NodePath("../../Airborne") guard = SubResource("Resource_4mj4w") delay_in_seconds = "0.0" +[node name="On ice_touched" type="Node" parent="StateChart/Root/Grounded"] +script = ExtResource("8_pgje5") +to = NodePath("../Sliding") +event = &"ice_touched" +delay_in_seconds = "0.0" + [node name="On jump_pressed" type="Node" parent="StateChart/Root/Grounded"] script = ExtResource("8_pgje5") to = NodePath("../../Airborne/Jumping") @@ -135,6 +143,15 @@ to = NodePath("../../Running") guard = SubResource("Resource_kdmd2") delay_in_seconds = "0.0" +[node name="Sliding" type="Node" parent="StateChart/Root/Grounded"] +script = ExtResource("7_56odx") + +[node name="On ground_touched" type="Node" parent="StateChart/Root/Grounded/Sliding"] +script = ExtResource("8_pgje5") +to = NodePath("../../Standing") +event = &"ground_touched" +delay_in_seconds = "0.0" + [node name="Running" type="Node" parent="StateChart/Root/Grounded"] script = ExtResource("7_56odx") @@ -176,6 +193,7 @@ delay_in_seconds = "0.0" [connection signal="state_entered" from="StateChart/Root/Grounded/Standing" to="." method="_stop_moving"] [connection signal="state_entered" from="StateChart/Root/Grounded/Standing" to="Graphics/Sprite/Idle" method="play"] +[connection signal="state_entered" from="StateChart/Root/Grounded/Sliding" to="Graphics/Sprite/Idle" method="play"] [connection signal="state_entered" from="StateChart/Root/Grounded/Running" to="Graphics/Sprite/Run" method="play"] [connection signal="state_physics_processing" from="StateChart/Root/Grounded/Running" to="." method="_process_run"] [connection signal="state_entered" from="StateChart/Root/Grounded/Barking" to="Graphics/Sprite/Bark" method="play"] diff --git a/project.godot b/project.godot index 13f685c..7b43b40 100644 --- a/project.godot +++ b/project.godot @@ -11,6 +11,7 @@ config_version=5 [application] config/name="Capri" +run/main_scene="res://maps/level1.tscn" config/features=PackedStringArray("4.3", "GL Compatibility") config/icon="res://icon.svg" @@ -35,6 +36,12 @@ folder_colors={ "res://scripts/": "teal" } +[layer_names] + +2d_physics/layer_1="solid" +2d_physics/layer_2="slippery" +2d_physics/layer_5="player" + [rendering] textures/canvas_textures/default_texture_filter=0