diff --git a/Actors/Objects/Door/Door.gd b/Actors/Objects/Door/Door.gd new file mode 100644 index 0000000..198bdd1 --- /dev/null +++ b/Actors/Objects/Door/Door.gd @@ -0,0 +1,26 @@ +extends StaticBody2D + +signal changed(open) + +func set_open(open: bool): + if open: + $Sprite.play("open") + else: + $Sprite.play("close") + +func _animation_finished(): + if $Sprite.animation == "open": + print("Door opened") + # Disable collider + collision_layer = 2 + collision_mask = 2 + else: + print("Door closed") + # Enable collider + collision_mask = 1 + collision_layer = 1 + +func _input_event(viewport, event, shape_idx): + if event is InputEventMouseButton and event.pressed: + set_open($Sprite.animation == "close") + diff --git a/Actors/Objects/Door/Door.tscn b/Actors/Objects/Door/Door.tscn new file mode 100644 index 0000000..e0fbb5b --- /dev/null +++ b/Actors/Objects/Door/Door.tscn @@ -0,0 +1,56 @@ +[gd_scene load_steps=10 format=2] + +[ext_resource path="res://Actors/Objects/Door/Door.gd" type="Script" id=1] +[ext_resource path="res://Graphics/tgstation/opening-sheet.png" type="Texture" id=2] + +[sub_resource type="AtlasTexture" id=5] +atlas = ExtResource( 2 ) +region = Rect2( 0, 64, 32, 32 ) + +[sub_resource type="AtlasTexture" id=4] +atlas = ExtResource( 2 ) +region = Rect2( 32, 32, 32, 32 ) + +[sub_resource type="AtlasTexture" id=3] +atlas = ExtResource( 2 ) +region = Rect2( 0, 32, 32, 32 ) + +[sub_resource type="AtlasTexture" id=2] +atlas = ExtResource( 2 ) +region = Rect2( 32, 0, 32, 32 ) + +[sub_resource type="AtlasTexture" id=1] +atlas = ExtResource( 2 ) +region = Rect2( 0, 0, 32, 32 ) + +[sub_resource type="SpriteFrames" id=6] +animations = [ { +"frames": [ SubResource( 5 ), SubResource( 4 ), SubResource( 3 ), SubResource( 2 ), SubResource( 1 ) ], +"loop": false, +"name": "close", +"speed": 20.0 +}, { +"frames": [ SubResource( 1 ), SubResource( 2 ), SubResource( 3 ), SubResource( 4 ), SubResource( 5 ) ], +"loop": false, +"name": "open", +"speed": 20.0 +} ] + +[sub_resource type="RectangleShape2D" id=7] +extents = Vector2( 16, 16 ) + +[node name="Node2D" type="StaticBody2D"] +input_pickable = true +script = ExtResource( 1 ) + +[node name="Sprite" type="AnimatedSprite" parent="."] +frames = SubResource( 6 ) +animation = "close" +frame = 4 +playing = true +centered = false + +[node name="CollisionShape2D" type="CollisionShape2D" parent="."] +position = Vector2( 16, 16 ) +shape = SubResource( 7 ) +[connection signal="animation_finished" from="Sprite" to="." method="_animation_finished"] diff --git a/Graphics/tgstation/objects.tres b/Graphics/tgstation/objects.tres new file mode 100644 index 0000000..4d53635 --- /dev/null +++ b/Graphics/tgstation/objects.tres @@ -0,0 +1,19 @@ +[gd_resource type="TileSet" load_steps=2 format=2] + +[ext_resource path="res://Graphics/tgstation/opening-sheet.png" type="Texture" id=3] + +[resource] +3/name = "Door" +3/texture = ExtResource( 3 ) +3/tex_offset = Vector2( 0, 0 ) +3/modulate = Color( 1, 1, 1, 1 ) +3/region = Rect2( 0, 0, 32, 32 ) +3/tile_mode = 0 +3/occluder_offset = Vector2( 0, 0 ) +3/navigation_offset = Vector2( 0, 0 ) +3/shape_offset = Vector2( 0, 0 ) +3/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 ) +3/shape_one_way = false +3/shape_one_way_margin = 0.0 +3/shapes = [ ] +3/z_index = 0 diff --git a/Graphics/tgstation/opening-sheet.png b/Graphics/tgstation/opening-sheet.png new file mode 100644 index 0000000..bc60b6d Binary files /dev/null and b/Graphics/tgstation/opening-sheet.png differ diff --git a/Graphics/tgstation/opening-sheet.png.import b/Graphics/tgstation/opening-sheet.png.import new file mode 100644 index 0000000..babd890 --- /dev/null +++ b/Graphics/tgstation/opening-sheet.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="StreamTexture" +path="res://.import/opening-sheet.png-d37578641f71c14e6c77bc47082bc07d.stex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Graphics/tgstation/opening-sheet.png" +dest_files=[ "res://.import/opening-sheet.png-d37578641f71c14e6c77bc47082bc07d.stex" ] + +[params] + +compress/mode=0 +compress/lossy_quality=0.7 +compress/hdr_mode=0 +compress/bptc_ldr=0 +compress/normal_map=0 +flags/repeat=0 +flags/filter=false +flags/mipmaps=false +flags/anisotropic=false +flags/srgb=2 +process/fix_alpha_border=true +process/premult_alpha=false +process/HDR_as_SRGB=false +process/invert_color=false +stream=false +size_limit=0 +detect_3d=true +svg/scale=1.0 diff --git a/Scenes/Maps/Objects.gd b/Scenes/Maps/Objects.gd new file mode 100644 index 0000000..7080026 --- /dev/null +++ b/Scenes/Maps/Objects.gd @@ -0,0 +1,17 @@ +extends TileMap + +const objects = { + "Door": preload("res://Actors/Objects/Door/Door.tscn") +} + +func _ready(): + for cell in get_used_cells(): + var id = get_cellv(cell) + var name = tile_set.tile_get_name(id) + if objects.has(name): + var obj = objects[name].instance() as Node2D + add_child(obj) + obj.transform.origin = map_to_world(cell) + else: + print("Placed object tile ", name, " at ", cell, " but has no object associated!") + set_cellv(cell, -1) diff --git a/Scenes/Maps/odyssey.tscn b/Scenes/Maps/odyssey.tscn index 4cba962..3f90a8d 100644 --- a/Scenes/Maps/odyssey.tscn +++ b/Scenes/Maps/odyssey.tscn @@ -1,9 +1,11 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=7 format=2] [ext_resource path="res://Graphics/tgstation/2x2.tres" type="TileSet" id=1] [ext_resource path="res://Graphics/tgstation/1x1.tres" type="TileSet" id=2] [ext_resource path="res://Scenes/Rendering/MapTiles.gd" type="Script" id=3] +[ext_resource path="res://Graphics/tgstation/objects.tres" type="TileSet" id=4] [ext_resource path="res://Scenes/Map.gd" type="Script" id=5] +[ext_resource path="res://Scenes/Maps/Objects.gd" type="Script" id=6] [node name="map" type="Node2D"] script = ExtResource( 5 ) @@ -19,6 +21,15 @@ tile_data = PoolIntArray( -393226, 1, 0, -393225, 1, 0, -393224, 1, 0, -393223, script = ExtResource( 3 ) extended_tilemap_node = NodePath("../1x1") +[node name="Objects" type="TileMap" parent="."] +tile_set = ExtResource( 4 ) +cell_size = Vector2( 32, 32 ) +cell_quadrant_size = 32 +occluder_light_mask = -2147483647 +format = 1 +tile_data = PoolIntArray( 458751, 3, 0, 393229, 3, 0, 655359, 3, 0, 589837, 3, 0 ) +script = ExtResource( 6 ) + [node name="1x1" type="TileMap" parent="."] light_mask = 2 tile_set = ExtResource( 2 )