diff --git a/edge.lua b/edge.lua index 9436599..68f0753 100644 --- a/edge.lua +++ b/edge.lua @@ -62,8 +62,8 @@ local mt = { end } -function edge:set(room, dir, dst) - local e = self:from{ +function edge.set(room, dir, dst) + local e = edge:from{ dir = dir, destination = dst, } diff --git a/main.lua b/main.lua index c8d0553..784951a 100644 --- a/main.lua +++ b/main.lua @@ -25,6 +25,7 @@ end function set_room(r) current_room = rooms[r] + assert(current_room) end screen = { diff --git a/obj/door.lua b/obj/door.lua index a37b723..d0c1d73 100644 --- a/obj/door.lua +++ b/obj/door.lua @@ -27,7 +27,7 @@ function m:draw() end end -m.mousepressed = window.mousepressed(function (self) +m.keyMode = window.mousepressed(function (self) if self.locked then local i = inventory.selected_item if i and i.code then @@ -49,4 +49,15 @@ m.mousepressed = window.mousepressed(function (self) end end) +m.keypadMode = window.mousepressed(function (self) + if self.locked then + log:log("It's locked.") + else + log:format("You enter %s", self.destination) + set_room(self.destination) + end +end) + +m.mousepressed = m.keyMode + return m diff --git a/obj/keypad.lua b/obj/keypad.lua index 84f01f4..08461a3 100644 --- a/obj/keypad.lua +++ b/obj/keypad.lua @@ -13,14 +13,13 @@ local install = m.install function m:install(room, x, y) self.keypad = keypad:from{ code = self.code, + oncorrect = self.oncorrect, room = room } install(self, room, x, y) end -m.mousepressed = window.mousepressed(function (self) - set_room_raw(self.keypad) -end) +m.mousepressed = window.portal("keypad") return m diff --git a/obj/note.lua b/obj/note.lua new file mode 100644 index 0000000..72450ce --- /dev/null +++ b/obj/note.lua @@ -0,0 +1,21 @@ +local entity = require("entity") +local window = require("window") +local note = require("room/note") + +local m = entity:from{ + text = "sample text", +} + +local install = m.install +function m:install(room, x, y) + self.note = note:from{ + text = self.text, + room = room + } + + install(self, room, x, y) +end + +m.mousepressed = window.portal('note') + +return m diff --git a/obj/sundial.lua b/obj/sundial.lua new file mode 100644 index 0000000..32e9b52 --- /dev/null +++ b/obj/sundial.lua @@ -0,0 +1,25 @@ +local entity = require("entity") +local window = require("window") +local sundial = require("room/sundial") + +local m = entity:from{ + width = 60, + height = 60, + lines = {'fill', {30, 30, 60, 40, 60, 50, 30, 60, 0, 50, 0, 40}}, +} + +local install = m.install +function m:install(room, x, y) + self.sundial = sundial:from{ + numbers = self.numbers, + room = room, + } + + install(self, room, x, y) +end + +m.mousepressed = window.mousepressed(function (self) + set_room_raw(self.sundial) +end) + +return m diff --git a/res/defaultbg.png b/res/defaultbg.png deleted file mode 100644 index 2628d1e..0000000 Binary files a/res/defaultbg.png and /dev/null differ diff --git a/room.lua b/room.lua index 686d75c..45717a2 100644 --- a/room.lua +++ b/room.lua @@ -8,11 +8,11 @@ local entity = require('entity') -- - edges local room = entity:from{ lines = { - {'line', 0, 0, 120, 80}, - {'line', 320, 0, 200, 80}, - {'line', 0, 240, 120, 160}, - {'line', 320, 240, 200, 160}, - {'fill', 120, 80, 200, 80, 200, 160, 200, 80}, + {'fill', {80, 60, 240, 60, 240, 180, 80, 180}}, + {'line', {0, 0, 80, 60}}, + {'line', {320, 0, 240, 60}}, + {'line', {0, 240, 80, 180}}, + {'line', {320, 240, 240, 180}}, }, } diff --git a/room/alley.lua b/room/alley.lua new file mode 100644 index 0000000..65bcae2 --- /dev/null +++ b/room/alley.lua @@ -0,0 +1,9 @@ +local room = require("room") +local edge = require("edge") + +local m = room:new() + +edge.set(m, 'down', "sundial_alley") +--edge.set(m, 'left', "alley2") + +return m diff --git a/room/default.lua b/room/default.lua index 3704955..8d76c50 100644 --- a/room/default.lua +++ b/room/default.lua @@ -5,9 +5,9 @@ local crowbar = require('item/crowbar') local r = room:new() crowbar:install(r, 100, 160) -edge:set(r, 'up', "default") -edge:set(r, 'down', "default") -edge:set(r, 'left', "default") -edge:set(r, 'right', "doortest") +edge.set(r, 'up', "default") +edge.set(r, 'down', "sundial_alley") +edge.set(r, 'left', "default") +edge.set(r, 'right', "doortest") return r diff --git a/room/keypad.lua b/room/keypad.lua index c9681ac..509998c 100644 --- a/room/keypad.lua +++ b/room/keypad.lua @@ -53,7 +53,7 @@ function m:from(t) function () kp:accept() end, sx + kd*2, br, ks, ks) - edge:set(kp, "down", kp.room) + edge.set(kp, "down", kp.room) register(kp) diff --git a/room/note.lua b/room/note.lua new file mode 100644 index 0000000..d098504 --- /dev/null +++ b/room/note.lua @@ -0,0 +1,22 @@ +local window = require("window") +local room = require("room") +local edge = require("edge") + +local m = room:new() + +local from = m.from +function m:from(t) + local n = from(self, t) + + edge.set(n, 'down', n.room) + + return n +end + +m.draw = window.draw(function (self) + love.graphics.printf(self.text, 80, 40, 160) + + self.edges[1]:draw() +end) + +return m diff --git a/room/sundial.lua b/room/sundial.lua new file mode 100644 index 0000000..aa87d3c --- /dev/null +++ b/room/sundial.lua @@ -0,0 +1,55 @@ +local window = require("window") +local room = require("room") +local edge = require("edge") + +local clock_size = 60 +local arm_size = 55 + +local m = room:new() + +local from = m.from +function m:from(t) + local sd = from(self, t) + + sd.tick = 0 + sd.ni = 1 + + edge.set(sd, 'down', sd.room) + + register(sd) + + return sd +end + +m.draw = window.draw(function (self) + love.graphics.circle('fill', 160, 120, clock_size, 12) + + local s = math.pi * self.numbers[self.ni] / 6 + local x = 160 + arm_size * math.sin(s) + local y = 120 - arm_size * math.cos(s) + local n = 120 - arm_size + + love.graphics.setColor(0, 0, 0) + love.graphics.polygon('fill', 160, n, 160, 120, x, y) + love.graphics.setColor(1, 1, 1) + love.graphics.polygon('fill', 160, n, 160, 120, 140, n) + love.graphics.setColor(0, 0, 0) + love.graphics.polygon('line', 160, n, 160, 120, 140, n) + love.graphics.setColor(1, 1, 1) + + self.edges[1]:draw() +end) + +function m:update(dt) + self.tick = self.tick + dt + + if self.tick > 2 then + self.tick = self.tick - 2 + self.ni = self.ni + 1 + if self.ni > #self.numbers then + self.ni = 1 + end + end +end + +return m diff --git a/room/sundial_alley.lua b/room/sundial_alley.lua new file mode 100644 index 0000000..8a3d506 --- /dev/null +++ b/room/sundial_alley.lua @@ -0,0 +1,29 @@ +local room = require("room") +local edge = require("edge") +local sundial = require("obj/sundial") +local keypad = require("obj/keypad") +local door = require("obj/door") + +local m = room:new() + +sundial:from{ + numbers = {3, 5, 8, 2, 7}, +}:install(m, 140, 160) + +local d = door:from{ + destination = 'vivarium', +} + +d:install(m, 80, 60) +d.mousepressed = d.keypadMode + +keypad:from{ + code = 35827, + oncorrect = function (self) + d.locked = false + end, +}:install(m, 180, 100) + +edge.set(m, 'up', "alley") + +return m diff --git a/rooms.lua b/rooms.lua index ecd9fa0..53199f0 100644 --- a/rooms.lua +++ b/rooms.lua @@ -1,6 +1,8 @@ local m = { ['default'] = require('room/default'), ['doortest'] = require('room/doortest'), + ['alley'] = require("room/alley"), + ['sundial_alley'] = require("room/sundial_alley"), } return m diff --git a/window.lua b/window.lua index abebc2a..ffdd9a3 100644 --- a/window.lua +++ b/window.lua @@ -39,6 +39,12 @@ function w.propagate(tnames) end end +function w.portal(room) + return w.mousepressed(function (self, x, y, button) + set_room_raw(self[room]) + end) +end + function w.draw_border(width, height) love.graphics.push('all') love.graphics.setLineWidth(5)