summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Scenes/Door.gd24
-rw-r--r--Scenes/Door.tscn18
-rw-r--r--Scenes/Dungeon.gd21
-rw-r--r--Scenes/Entity.gd3
-rw-r--r--Scenes/Plate.gd12
-rw-r--r--Scenes/PlateKey.gd15
-rw-r--r--Scenes/PlateKey.tscn18
-rw-r--r--Scenes/Player.gd8
-rw-r--r--project.godot14
9 files changed, 129 insertions, 4 deletions
diff --git a/Scenes/Door.gd b/Scenes/Door.gd
new file mode 100644
index 0000000..2918d8b
--- /dev/null
+++ b/Scenes/Door.gd
@@ -0,0 +1,24 @@
+extends Entity
+
+class_name Door
+
+export(bool) var is_open = false
+
+onready var mesh = $Mesh
+
+func cor_open(args : Array):
+ var duration = args[0]
+ var time = 0
+
+ while true:
+ time = min(time + get_process_delta_time(), duration)
+ var weight = time / duration
+
+ mesh.translation = Vector3(0, 0.5 - weight * 0.95, 0)
+
+ if time >= duration:
+ break
+
+ yield(get_tree(), "idle_frame")
+
+ is_open = true
diff --git a/Scenes/Door.tscn b/Scenes/Door.tscn
new file mode 100644
index 0000000..0b3e869
--- /dev/null
+++ b/Scenes/Door.tscn
@@ -0,0 +1,18 @@
+[gd_scene load_steps=4 format=2]
+
+[ext_resource path="res://Scenes/Door.gd" type="Script" id=1]
+
+[sub_resource type="CubeMesh" id=1]
+size = Vector3( 1, 1, 1 )
+
+[sub_resource type="SpatialMaterial" id=2]
+albedo_color = Color( 0.34902, 0.541176, 0.835294, 1 )
+
+[node name="Door" type="Spatial"]
+script = ExtResource( 1 )
+actionable = true
+
+[node name="Mesh" type="MeshInstance" parent="."]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0 )
+mesh = SubResource( 1 )
+material/0 = SubResource( 2 )
diff --git a/Scenes/Dungeon.gd b/Scenes/Dungeon.gd
index 2483032..7c923db 100644
--- a/Scenes/Dungeon.gd
+++ b/Scenes/Dungeon.gd
@@ -3,6 +3,8 @@ extends Spatial
const Player = preload("res://Scenes/Player.tscn")
const Obstacle = preload("res://Scenes/Obstacle.tscn")
const MonsterScene = preload("res://Scenes/MonsterRandCardinal.tscn")
+const PlateKey = preload("res://Scenes/PlateKey.tscn")
+const Door = preload("res://Scenes/Door.tscn")
onready var camera = $Pitch
onready var player : Entity = null
@@ -52,9 +54,24 @@ func build_floor():
set_tile(monster, rand_pos)
add_child(monster)
+ for i in range(2):
+ rand_pos = Vector2(randi()%6 - 3, randi()%6 - 3)
+ var door = Door.instance()
+ set_tile(door, rand_pos)
+ add_child(door)
+
+ rand_pos = Vector2(randi()%6 - 3, randi()%6 - 3)
+ var plate_key = PlateKey.instance()
+ plate_key.set_door(door)
+ tiles_floor[rand_pos] = plate_key
+ add_child(plate_key)
+
for key in tiles_entities:
tiles_entities[key].translation = tile_to_pos(key)
+ for key in tiles_floor:
+ tiles_floor[key].translation = tile_to_pos(key)
+
camera.follow(player)
func _process(delta):
@@ -150,6 +167,10 @@ func move_entity(entity : Entity, dir : Vector2):
entity.add_action("cor_move", [tile_to_pos(new_tile), 0.2])
+
+ if tiles_floor.has(new_tile):
+ tiles_floor[new_tile].step(entity.get_top())
+
return true
func tile_to_pos(tile : Vector2):
diff --git a/Scenes/Entity.gd b/Scenes/Entity.gd
index 26b5b3f..880f904 100644
--- a/Scenes/Entity.gd
+++ b/Scenes/Entity.gd
@@ -10,6 +10,9 @@ func _ready():
if actionable:
add_to_group("actionables")
+func get_top() -> String:
+ return ''
+
func add_action(name : String, args : Array):
actions_queue.append([name, args])
diff --git a/Scenes/Plate.gd b/Scenes/Plate.gd
new file mode 100644
index 0000000..c819cf1
--- /dev/null
+++ b/Scenes/Plate.gd
@@ -0,0 +1,12 @@
+extends Spatial
+
+class_name Plate
+
+export(Array, String) var valid_symbols
+
+func step(symbol : String):
+ if valid_symbols.empty() or valid_symbols.has(symbol):
+ activate()
+
+func activate():
+ pass
diff --git a/Scenes/PlateKey.gd b/Scenes/PlateKey.gd
new file mode 100644
index 0000000..33c563b
--- /dev/null
+++ b/Scenes/PlateKey.gd
@@ -0,0 +1,15 @@
+extends Plate
+
+export(NodePath) var door_path
+
+onready var door : Door = get_node(door_path) setget set_door
+
+func activate():
+ if door == null or door.is_open:
+ return
+
+ door.add_action("cor_open", [0.2])
+
+func set_door(value : Door):
+ door = value
+ door_path = value.get_path()
diff --git a/Scenes/PlateKey.tscn b/Scenes/PlateKey.tscn
new file mode 100644
index 0000000..0b21ead
--- /dev/null
+++ b/Scenes/PlateKey.tscn
@@ -0,0 +1,18 @@
+[gd_scene load_steps=4 format=2]
+
+[ext_resource path="res://Scenes/PlateKey.gd" type="Script" id=1]
+
+[sub_resource type="CubeMesh" id=1]
+size = Vector3( 0.9, 0.05, 1 )
+
+[sub_resource type="SpatialMaterial" id=2]
+albedo_color = Color( 0.34902, 0.541176, 0.835294, 1 )
+
+[node name="PlateKey" type="Spatial"]
+script = ExtResource( 1 )
+valid_symbols = [ "1", "2", "3" ]
+
+[node name="Mesh" type="MeshInstance" parent="."]
+transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.025, 0 )
+mesh = SubResource( 1 )
+material/0 = SubResource( 2 )
diff --git a/Scenes/Player.gd b/Scenes/Player.gd
index 145af4f..6cde567 100644
--- a/Scenes/Player.gd
+++ b/Scenes/Player.gd
@@ -37,7 +37,7 @@ var symbols = ['1', '3', '5', '2', '4', '6']
var side = 0
var spin = 0
-func get_top():
+func get_top() -> String:
return symbols[side]
func set_bottom(symbol : String):
@@ -49,7 +49,7 @@ func roll(direction : Vector2):
spin = chart_spin[side][cardinal] + spin
side = chart_side[side][cardinal]
-func get_cardinal(direction: Vector2):
+func get_cardinal(direction: Vector2) -> int:
if direction.y > 0:
return 0
@@ -62,7 +62,9 @@ func get_cardinal(direction: Vector2):
if direction.x > 0:
return 3
-func get_upper_face():
+ return -1
+
+func get_upper_face() -> String:
return get_top()
func cor_move(args : Array): # args = [Vector3, float]
diff --git a/project.godot b/project.godot
index 9bde0ff..153840b 100644
--- a/project.godot
+++ b/project.godot
@@ -9,6 +9,11 @@
config_version=4
_global_script_classes=[ {
+"base": "Entity",
+"class": "Door",
+"language": "GDScript",
+"path": "res://Scenes/Door.gd"
+}, {
"base": "Spatial",
"class": "Entity",
"language": "GDScript",
@@ -18,10 +23,17 @@ _global_script_classes=[ {
"class": "Monster",
"language": "GDScript",
"path": "res://Scenes/Monster.gd"
+}, {
+"base": "Spatial",
+"class": "Plate",
+"language": "GDScript",
+"path": "res://Scenes/Plate.gd"
} ]
_global_script_class_icons={
+"Door": "",
"Entity": "",
-"Monster": ""
+"Monster": "",
+"Plate": ""
}
[application]