diff --git a/game/levels/abstract_level.tscn b/game/levels/abstract_level.tscn index 51db29e..31f7f05 100644 --- a/game/levels/abstract_level.tscn +++ b/game/levels/abstract_level.tscn @@ -504,6 +504,8 @@ size = Vector2(32, 32) [node name="AbstractLevel" type="Node2D" unique_id=1364620575] script = ExtResource("1_o2mui") +[node name="Platforms" type="Node2D" parent="." unique_id=1140671629] + [node name="Doors" type="Node2D" parent="." unique_id=1468144392] [node name="Objects" type="Node2D" parent="." unique_id=1320033435] diff --git a/game/levels/test_level.tscn b/game/levels/test_level.tscn index 56bdd96..1dbb38c 100644 --- a/game/levels/test_level.tscn +++ b/game/levels/test_level.tscn @@ -3,6 +3,7 @@ [ext_resource type="PackedScene" uid="uid://mpsu4g2b5h3a" path="res://game/levels/abstract_level.tscn" id="1_15okj"] [ext_resource type="Script" uid="uid://bc114fx0hcb6s" path="res://game/levels/test_level.gd" id="2_a2sw7"] [ext_resource type="PackedScene" uid="uid://ct6n0u0iegynv" path="res://game/doors/lever_door.tscn" id="2_r01v2"] +[ext_resource type="PackedScene" uid="uid://guvijso3k6eq" path="res://game/platform/abstract_platform.tscn" id="3_pmn5w"] [ext_resource type="PackedScene" uid="uid://b3kyqvuxmfn8f" path="res://game/objects/decorative/fireplace.tscn" id="3_tuvkr"] [ext_resource type="PackedScene" uid="uid://g0n5npbt3hb2" path="res://game/doors/circle_door.tscn" id="4_yrqjd"] [ext_resource type="PackedScene" uid="uid://cojxqx5al7kyv" path="res://game/doors/locked_door.tscn" id="5_1skah"] @@ -26,6 +27,10 @@ [node name="TestLevel" unique_id=600627332 instance=ExtResource("1_15okj")] script = ExtResource("2_a2sw7") +[node name="AbstractPlatform" parent="Platforms" parent_id_path=PackedInt32Array(1140671629) index="0" unique_id=1226827206 instance=ExtResource("3_pmn5w")] +position = Vector2(144, -58) +platform_width = 256 + [node name="LeverDoor" parent="Doors" parent_id_path=PackedInt32Array(1468144392) index="0" unique_id=1575363350 instance=ExtResource("2_r01v2")] position = Vector2(416, -56) @@ -89,7 +94,7 @@ position = Vector2(936, -48) [node name="WhiteEnemy" parent="Enemies" parent_id_path=PackedInt32Array(857989772) index="2" unique_id=1447247338 instance=ExtResource("20_rt0xo")] position = Vector2(743, -48) -[node name="Player" parent="." index="4" unique_id=1058744997] +[node name="Player" parent="." index="5" unique_id=1058744997] position = Vector2(-13, 0) [node name="GrayWalls" parent="Tiles" parent_id_path=PackedInt32Array(1626037498) index="0" unique_id=557672309] @@ -104,7 +109,7 @@ tile_map_data = PackedByteArray("AAAwAP3/AAAAAAEAAAAwAPz/AAAAAAEAAAAwAPv/AAAAAAE [node name="Traps" parent="Tiles" parent_id_path=PackedInt32Array(1626037498) index="3" unique_id=635748436] tile_map_data = PackedByteArray("AAA9AAcAAAAAAAAAAAA9AAgAAAAAAAEAAAA9AAkAAAAAAAEAAAA=") -[node name="LevelEnd" parent="." index="8" unique_id=1018767708] +[node name="LevelEnd" parent="." index="9" unique_id=1018767708] position = Vector2(1334, 103) [node name="CollisionShape2D" parent="LevelEnd" index="0" unique_id=937956890] diff --git a/game/platform/abstract_platform.gd b/game/platform/abstract_platform.gd new file mode 100644 index 0000000..823c591 --- /dev/null +++ b/game/platform/abstract_platform.gd @@ -0,0 +1,41 @@ +@tool +class_name AbstractPlatform +extends Node2D + + +const TILE_SIZE = 8 +const MIN_WIDTH = TILE_SIZE * 2 +const MAX_WIDTH = TILE_SIZE * 32 + + +@export_range(MIN_WIDTH, MAX_WIDTH, TILE_SIZE) var platform_width: int = MIN_WIDTH: + set(value): + value = clampi(value, MIN_WIDTH, MAX_WIDTH) + platform_width = value - (value % TILE_SIZE) + if is_node_ready(): + rebuild_platform() + + +@onready var collision: CollisionShape2D = $AnimatableBody2D/CollisionShape2D +@onready var platform_sprite: Sprite2D = $PlatformSprite +@onready var icon_sprite: AnimatedSprite2D = $IconSprite + + +func _ready() -> void: + platform_sprite.material.set_shader_parameter("tile_size", TILE_SIZE) + rebuild_platform() + + +func rebuild_platform() -> void: + var shape := collision.shape as RectangleShape2D + if not shape: + shape = RectangleShape2D.new() + collision.shape = shape + shape.size = Vector2(platform_width, TILE_SIZE) + + platform_sprite.material.set_shader_parameter("platform_width", platform_width) + + +func _physics_process(_delta: float) -> void: + if Engine.is_editor_hint(): + return diff --git a/game/platform/abstract_platform.gd.uid b/game/platform/abstract_platform.gd.uid new file mode 100644 index 0000000..7bccee5 --- /dev/null +++ b/game/platform/abstract_platform.gd.uid @@ -0,0 +1 @@ +uid://kjy0t56tgpxs diff --git a/game/platform/abstract_platform.tscn b/game/platform/abstract_platform.tscn new file mode 100644 index 0000000..59a2551 --- /dev/null +++ b/game/platform/abstract_platform.tscn @@ -0,0 +1,23 @@ +[gd_scene format=3 uid="uid://guvijso3k6eq"] + +[ext_resource type="Script" uid="uid://kjy0t56tgpxs" path="res://game/platform/abstract_platform.gd" id="1_426vp"] +[ext_resource type="Texture2D" uid="uid://cpcuokqv8u2xa" path="res://images/level/platform.png" id="2_31xwx"] +[ext_resource type="Shader" uid="uid://d4hm3vjx1rhsf" path="res://game/shaders/platform.gdshader" id="2_jsq8n"] + +[sub_resource type="ShaderMaterial" id="ShaderMaterial_2ivtb"] +shader = ExtResource("2_jsq8n") +shader_parameter/tile_size = 16.0 +shader_parameter/platform_width = 16.0 + +[node name="AbstractPlatform" type="Node2D" unique_id=1226827206] +script = ExtResource("1_426vp") + +[node name="PlatformSprite" type="Sprite2D" parent="." unique_id=1901062470] +material = SubResource("ShaderMaterial_2ivtb") +texture = ExtResource("2_31xwx") + +[node name="IconSprite" type="AnimatedSprite2D" parent="." unique_id=287774650] + +[node name="AnimatableBody2D" type="AnimatableBody2D" parent="." unique_id=908936954] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="AnimatableBody2D" unique_id=175449124] diff --git a/game/shaders/platform.gdshader b/game/shaders/platform.gdshader new file mode 100644 index 0000000..3ca545b --- /dev/null +++ b/game/shaders/platform.gdshader @@ -0,0 +1,10 @@ +shader_type canvas_item; + + +uniform float tile_size = 8.0; +uniform float platform_width = 16.0; + + +void fragment() { + +} diff --git a/game/shaders/platform.gdshader.uid b/game/shaders/platform.gdshader.uid new file mode 100644 index 0000000..7a0e997 --- /dev/null +++ b/game/shaders/platform.gdshader.uid @@ -0,0 +1 @@ +uid://d4hm3vjx1rhsf diff --git a/images/level/platform-icons.png.import b/images/level/platform-icons.png.import new file mode 100644 index 0000000..062f367 --- /dev/null +++ b/images/level/platform-icons.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://bi2h4g71bro7v" +path="res://.godot/imported/platform-icons.png-9084948edfc829c7eff7f585b0af53a8.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://images/level/platform-icons.png" +dest_files=["res://.godot/imported/platform-icons.png-9084948edfc829c7eff7f585b0af53a8.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +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/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +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