Add doors!

This commit is contained in:
Hamcha 2020-07-06 18:41:30 +02:00
parent a0a9752d04
commit f65ef4b8f9
Signed by: hamcha
GPG Key ID: 41467804B19A3315
7 changed files with 164 additions and 1 deletions

View File

@ -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")

View File

@ -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"]

View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -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

17
Scenes/Maps/Objects.gd Normal file
View File

@ -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)

View File

@ -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 )