From 6776086c3ed740f17a26b24a2a0614520bb42353 Mon Sep 17 00:00:00 2001 From: Ruslan Ignatov Date: Mon, 9 Sep 2024 17:21:09 +0300 Subject: [PATCH] Added collision boxes to level --- .../data/images/{Fierd.png => Field.png} | Bin .../{Fierd.png.import => Field.png.import} | 6 +-- vegeconda/door.gd | 1 + vegeconda/level.gd | 15 +++++- vegeconda/level.tscn | 48 ++++++++++++++++-- 5 files changed, 63 insertions(+), 7 deletions(-) rename vegeconda/data/images/{Fierd.png => Field.png} (100%) rename vegeconda/data/images/{Fierd.png.import => Field.png.import} (73%) diff --git a/vegeconda/data/images/Fierd.png b/vegeconda/data/images/Field.png similarity index 100% rename from vegeconda/data/images/Fierd.png rename to vegeconda/data/images/Field.png diff --git a/vegeconda/data/images/Fierd.png.import b/vegeconda/data/images/Field.png.import similarity index 73% rename from vegeconda/data/images/Fierd.png.import rename to vegeconda/data/images/Field.png.import index c42b92a..fa44f75 100644 --- a/vegeconda/data/images/Fierd.png.import +++ b/vegeconda/data/images/Field.png.import @@ -3,15 +3,15 @@ importer="texture" type="CompressedTexture2D" uid="uid://cueeywtu6xdbv" -path="res://.godot/imported/Fierd.png-092c69452f524e8b881046eb1e338a4a.ctex" +path="res://.godot/imported/Field.png-859bbd1d5004670495fd6abbe4d47b71.ctex" metadata={ "vram_texture": false } [deps] -source_file="res://data/images/Fierd.png" -dest_files=["res://.godot/imported/Fierd.png-092c69452f524e8b881046eb1e338a4a.ctex"] +source_file="res://data/images/Field.png" +dest_files=["res://.godot/imported/Field.png-859bbd1d5004670495fd6abbe4d47b71.ctex"] [params] diff --git a/vegeconda/door.gd b/vegeconda/door.gd index bcd7908..0dd35e3 100644 --- a/vegeconda/door.gd +++ b/vegeconda/door.gd @@ -28,6 +28,7 @@ signal closed() func _ready() -> void: + $CollisionShape2D.disabled = state == DoorState.OPENED _play_animation() diff --git a/vegeconda/level.gd b/vegeconda/level.gd index acd3543..4767fb1 100644 --- a/vegeconda/level.gd +++ b/vegeconda/level.gd @@ -90,6 +90,12 @@ func _create_top_door(): top_door.state = Door.DoorState.CLOSED top_door.position = Vector2i(top_door_x,y)*16 add_child(top_door) + + $CollisionBoxTopLeft.shape.size.x = (top_door_x - 1) * 16 + $CollisionBoxTopLeft.position.x += $CollisionBoxTopLeft.shape.size.x/2 - 8 + + $CollisionBoxTopRight.shape.size.x = (20 - top_door_x - 2) * 16 + $CollisionBoxTopRight.position.x -= $CollisionBoxTopRight.shape.size.x/2 - 8 func _create_bottom_door(): @@ -100,6 +106,13 @@ func _create_bottom_door(): bottom_door = DOOR.instantiate() bottom_door.type = Door.DoorType.BOTTOM_DOOR - bottom_door.state = Door.DoorState.CLOSED + bottom_door.state = Door.DoorState.OPENED bottom_door.position = Vector2i(bottom_door_x,y)*16 add_child(bottom_door) + + + $CollisionBoxBottomLeft.shape.size.x = (bottom_door_x - 1) * 16 + $CollisionBoxBottomLeft.position.x += $CollisionBoxBottomLeft.shape.size.x/2 - 8 + + $CollisionBoxBottomRight.shape.size.x = (20 - bottom_door_x - 2) * 16 + $CollisionBoxBottomRight.position.x -= $CollisionBoxBottomRight.shape.size.x/2 - 8 diff --git a/vegeconda/level.tscn b/vegeconda/level.tscn index 9b73f91..4497005 100644 --- a/vegeconda/level.tscn +++ b/vegeconda/level.tscn @@ -1,8 +1,8 @@ -[gd_scene load_steps=7 format=3 uid="uid://c1h0h1viac0gy"] +[gd_scene load_steps=13 format=3 uid="uid://c1h0h1viac0gy"] [ext_resource type="Script" path="res://level.gd" id="1_t0agp"] [ext_resource type="Texture2D" uid="uid://b6wbb26dayco1" path="res://data/images/Forest.png" id="2_acuqw"] -[ext_resource type="Texture2D" uid="uid://cueeywtu6xdbv" path="res://data/images/Fierd.png" id="3_uas50"] +[ext_resource type="Texture2D" uid="uid://cueeywtu6xdbv" path="res://data/images/Field.png" id="3_uas50"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_ux773"] texture = ExtResource("2_acuqw") @@ -54,8 +54,50 @@ texture = ExtResource("3_uas50") sources/0 = SubResource("TileSetAtlasSource_ux773") sources/1 = SubResource("TileSetAtlasSource_yfk20") -[node name="Level" type="Node2D"] +[sub_resource type="RectangleShape2D" id="RectangleShape2D_5p18l"] +size = Vector2(16, 176) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_5hg31"] +size = Vector2(16, 176) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_j8f03"] +size = Vector2(16, 16) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_0blxn"] +size = Vector2(16, 16) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_tnbqo"] +size = Vector2(16, 16) + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_531kt"] +size = Vector2(16, 16) + +[node name="Level" type="StaticBody2D"] script = ExtResource("1_t0agp") [node name="TileMapLayer" type="TileMapLayer" parent="."] tile_set = SubResource("TileSet_e0bu0") + +[node name="CollisionBoxLeft" type="CollisionShape2D" parent="."] +position = Vector2(8, 88) +shape = SubResource("RectangleShape2D_5p18l") + +[node name="CollisionBoxRight" type="CollisionShape2D" parent="."] +position = Vector2(312, 88) +shape = SubResource("RectangleShape2D_5hg31") + +[node name="CollisionBoxTopLeft" type="CollisionShape2D" parent="."] +position = Vector2(24, 8) +shape = SubResource("RectangleShape2D_j8f03") + +[node name="CollisionBoxTopRight" type="CollisionShape2D" parent="."] +position = Vector2(296, 8) +shape = SubResource("RectangleShape2D_0blxn") + +[node name="CollisionBoxBottomLeft" type="CollisionShape2D" parent="."] +position = Vector2(24, 168) +shape = SubResource("RectangleShape2D_tnbqo") + +[node name="CollisionBoxBottomRight" type="CollisionShape2D" parent="."] +position = Vector2(296, 168) +shape = SubResource("RectangleShape2D_531kt")