Compare commits
No commits in common. "d7855c69c210c611783df1058819c98983a8b9d1" and "d2610ee690ec6ed06817af546eecdef2daaf9fe0" have entirely different histories.
d7855c69c2
...
d2610ee690
26 changed files with 112 additions and 820 deletions
2
conf.lua
2
conf.lua
|
@ -2,8 +2,6 @@ WIDTH = 528
|
||||||
HEIGHT = 300
|
HEIGHT = 300
|
||||||
MULTIPLIER = 1.2
|
MULTIPLIER = 1.2
|
||||||
|
|
||||||
Seed_colour = {0.4, 0.2, 0.4}
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
SCREEN_WIDTH = 320
|
SCREEN_WIDTH = 320
|
||||||
SCREEN_HEIGHT = 240
|
SCREEN_HEIGHT = 240
|
||||||
|
|
9
edge.lua
9
edge.lua
|
@ -52,11 +52,6 @@ local edge = entity:from{
|
||||||
end)
|
end)
|
||||||
}
|
}
|
||||||
|
|
||||||
edge.draw = window.draw(function (self)
|
|
||||||
love.graphics.setLineJoin('bevel')
|
|
||||||
self:draw_lines(self.lines)
|
|
||||||
end)
|
|
||||||
|
|
||||||
local mt = {
|
local mt = {
|
||||||
__index = function (t, k)
|
__index = function (t, k)
|
||||||
if edge_data[t.dir][k] then
|
if edge_data[t.dir][k] then
|
||||||
|
@ -67,8 +62,8 @@ local mt = {
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
function edge.set(room, dir, dst)
|
function edge:set(room, dir, dst)
|
||||||
local e = edge:from{
|
local e = self:from{
|
||||||
dir = dir,
|
dir = dir,
|
||||||
destination = dst,
|
destination = dst,
|
||||||
}
|
}
|
||||||
|
|
22
entity.lua
22
entity.lua
|
@ -11,13 +11,15 @@ local m = {
|
||||||
|
|
||||||
m.__index = m
|
m.__index = m
|
||||||
|
|
||||||
function m:from(t)
|
function m:new()
|
||||||
|
local t = {}
|
||||||
t.__index = t
|
t.__index = t
|
||||||
return setmetatable(t, self)
|
return setmetatable(t, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
function m:new()
|
function m:from(t)
|
||||||
return self:from({})
|
t.__index = t
|
||||||
|
return setmetatable(t, self)
|
||||||
end
|
end
|
||||||
|
|
||||||
function m:setpos(x, y)
|
function m:setpos(x, y)
|
||||||
|
@ -46,7 +48,9 @@ local function draw_line(l)
|
||||||
end
|
end
|
||||||
|
|
||||||
function m:draw_lines(lines)
|
function m:draw_lines(lines)
|
||||||
love.graphics.setLineWidth(2)
|
love.graphics.push('all')
|
||||||
|
love.graphics.translate(self.x, self.y)
|
||||||
|
love.graphics.setLineWidth(3)
|
||||||
|
|
||||||
if type(lines[1]) == 'string' then
|
if type(lines[1]) == 'string' then
|
||||||
draw_line(lines)
|
draw_line(lines)
|
||||||
|
@ -55,17 +59,15 @@ function m:draw_lines(lines)
|
||||||
draw_line(l)
|
draw_line(l)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
love.graphics.pop()
|
||||||
end
|
end
|
||||||
|
|
||||||
m.draw = window.draw(function (self)
|
function m:draw()
|
||||||
self:draw_lines(self.lines)
|
self:draw_lines(self.lines)
|
||||||
end)
|
end
|
||||||
|
|
||||||
m.mousepressed = window.mousepressed(function (self, x, y, button)
|
|
||||||
end)
|
|
||||||
|
|
||||||
function m:install(room, x, y)
|
function m:install(room, x, y)
|
||||||
self.room = room
|
|
||||||
self:setpos(x, y)
|
self:setpos(x, y)
|
||||||
room:insert(self)
|
room:insert(self)
|
||||||
end
|
end
|
||||||
|
|
13
item.lua
13
item.lua
|
@ -27,17 +27,16 @@ function m:itemMode()
|
||||||
self.mousepressed = window.mousepressed(function (self, x, y, button)
|
self.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||||
log:info(self)
|
log:info(self)
|
||||||
inventory.selected_item = self
|
inventory.selected_item = self
|
||||||
|
log:format("selected idx : %s", inventory.selected_item.idx)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
local install = m.install
|
|
||||||
function m:install(room, x, y)
|
function m:install(room, x, y)
|
||||||
self:pickupMode()
|
local i = self:new()
|
||||||
install(self, room, x, y)
|
i.room = room
|
||||||
end
|
i:pickupMode()
|
||||||
|
i:setpos(x, y)
|
||||||
function m:spawn(room, x, y)
|
room:insert(i)
|
||||||
self:new():install(room, x, y)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
local window = require('window')
|
|
||||||
local item = require('item')
|
|
||||||
|
|
||||||
local line = {
|
|
||||||
15, 0, 25, 0,
|
|
||||||
40, 40, 0, 40,
|
|
||||||
}
|
|
||||||
|
|
||||||
local m = item:from{
|
|
||||||
width = 40,
|
|
||||||
height = 40,
|
|
||||||
colour = {0, 0, 0},
|
|
||||||
name = "Flask",
|
|
||||||
description = "A glass container filled with liquid.",
|
|
||||||
}
|
|
||||||
|
|
||||||
m.draw = window.draw(function (self)
|
|
||||||
love.graphics.setColor(self.colour)
|
|
||||||
love.graphics.polygon('fill', line)
|
|
||||||
love.graphics.setColor(1, 1, 1)
|
|
||||||
love.graphics.polygon('line', line)
|
|
||||||
end)
|
|
||||||
|
|
||||||
return m
|
|
|
@ -1,11 +0,0 @@
|
||||||
local item = require("item")
|
|
||||||
|
|
||||||
local m = item:from{
|
|
||||||
name = "Seed",
|
|
||||||
description = "A reproductive capsule for plants.",
|
|
||||||
width = 20,
|
|
||||||
height = 20,
|
|
||||||
lines = {'fill', {0, 5, 5, 0, 20, 10, 20, 15, 15, 20, 10, 15}},
|
|
||||||
}
|
|
||||||
|
|
||||||
return m
|
|
131
main.lua
131
main.lua
|
@ -1,25 +1,8 @@
|
||||||
-- Imports
|
-- Imports
|
||||||
local util = require("util")
|
local util = require("util")
|
||||||
local window = require("window")
|
local window = require("window")
|
||||||
local entity = require("entity")
|
|
||||||
local button = require("button")
|
local button = require("button")
|
||||||
|
|
||||||
function min(a, b)
|
|
||||||
if a < b then
|
|
||||||
return a
|
|
||||||
else
|
|
||||||
return b
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function max(a, b)
|
|
||||||
if a > b then
|
|
||||||
return a
|
|
||||||
else
|
|
||||||
return b
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- entities that has update method
|
-- entities that has update method
|
||||||
active_entities = {}
|
active_entities = {}
|
||||||
|
|
||||||
|
@ -34,18 +17,14 @@ end
|
||||||
--load room list
|
--load room list
|
||||||
local rooms = require("rooms")
|
local rooms = require("rooms")
|
||||||
|
|
||||||
current_room = rooms['Alley']
|
current_room = rooms['default']
|
||||||
--current_room = rooms['Vivarium']
|
|
||||||
|
|
||||||
function set_room_raw(r)
|
function set_room_raw(r)
|
||||||
current_room:onexit()
|
|
||||||
current_room = r
|
current_room = r
|
||||||
current_room:onenter()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function set_room(r)
|
function set_room(r)
|
||||||
assert(rooms[r])
|
current_room = rooms[r]
|
||||||
set_room_raw(rooms[r])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
screen = {
|
screen = {
|
||||||
|
@ -55,6 +34,7 @@ screen = {
|
||||||
}
|
}
|
||||||
|
|
||||||
screen.mousepressed = window.mousepressed(function (self, x, y, button)
|
screen.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||||
|
log:log(string.format("%d, %d", x, y))
|
||||||
current_room:mousepressed(x, y, button)
|
current_room:mousepressed(x, y, button)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -69,102 +49,14 @@ inventory = {
|
||||||
height = 60,
|
height = 60,
|
||||||
selected_item = nil,
|
selected_item = nil,
|
||||||
items = {},
|
items = {},
|
||||||
item_idx = 1,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local cells = math.floor((inventory.width - 60) / 60)
|
inventory.mousepressed = window.propagate{'items'}
|
||||||
|
|
||||||
function inventory:setpos(idx, item)
|
|
||||||
local x = 30 + (idx - 1) * 60 + (60 - item.width) / 2
|
|
||||||
local y = (60 - item.height) / 2
|
|
||||||
|
|
||||||
item:setpos(x, y)
|
|
||||||
end
|
|
||||||
|
|
||||||
function inventory:move(d)
|
|
||||||
self.item_idx = self.item_idx + d
|
|
||||||
|
|
||||||
if self.item_idx < 1 then
|
|
||||||
self.item_idx = 1
|
|
||||||
elseif self.item_idx + cells - 1 > #self.items then
|
|
||||||
self.item_idx = max(1, #self.items - cells + 1)
|
|
||||||
end
|
|
||||||
|
|
||||||
for i = 1, min(#self.items, cells) do
|
|
||||||
local idx = self.item_idx + i - 1
|
|
||||||
self:setpos(i, self.items[idx])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function inventory:pickup(item)
|
|
||||||
util.add_entity(self.items, item)
|
|
||||||
self:move(#self.items)
|
|
||||||
end
|
|
||||||
|
|
||||||
function inventory:drop(item)
|
|
||||||
util.del_entity(self.items, item)
|
|
||||||
self:move(0)
|
|
||||||
end
|
|
||||||
|
|
||||||
function inventory:use()
|
|
||||||
self:drop(self.selected_item)
|
|
||||||
self.selected_item = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local move_left = entity:from{
|
|
||||||
x = 0, y = 0,
|
|
||||||
width = 20,
|
|
||||||
height = 60,
|
|
||||||
}
|
|
||||||
|
|
||||||
move_left.draw = window.draw(function (self)
|
|
||||||
love.graphics.polygon('line', 15, 5, 5, 30, 15, 55)
|
|
||||||
end)
|
|
||||||
|
|
||||||
move_left.mousepressed = window.mousepressed(function (self, x, y, button)
|
|
||||||
inventory:move(-1)
|
|
||||||
end)
|
|
||||||
|
|
||||||
local move_right = entity:from{
|
|
||||||
x = inventory.width - 20,
|
|
||||||
y = 0,
|
|
||||||
width = 20,
|
|
||||||
height = 60,
|
|
||||||
}
|
|
||||||
|
|
||||||
move_right.draw = window.draw(function (self)
|
|
||||||
love.graphics.polygon('line', 5, 5, 15, 30, 5, 55)
|
|
||||||
end)
|
|
||||||
|
|
||||||
move_right.mousepressed = window.mousepressed(function (self, x, y, button)
|
|
||||||
inventory:move(1)
|
|
||||||
end)
|
|
||||||
|
|
||||||
inventory.mousepressed = window.mousepressed(function (self, x, y, button)
|
|
||||||
move_left:mousepressed(x, y, button)
|
|
||||||
move_right:mousepressed(x, y, button)
|
|
||||||
|
|
||||||
for i = 1, min(cells, #self.items) do
|
|
||||||
local item = self.items[self.item_idx + i - 1]
|
|
||||||
|
|
||||||
if item:mousepressed(x, y, button) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
inventory.selected_item = nil
|
|
||||||
end)
|
|
||||||
|
|
||||||
inventory.draw = window.draw(function (self)
|
inventory.draw = window.draw(function (self)
|
||||||
move_left:draw()
|
for i, item in pairs(self.items) do
|
||||||
move_right:draw()
|
if self.selected_item and self.selected_item.idx == i then
|
||||||
|
love.graphics.circle('line', 60*i - 30, 30, 25)
|
||||||
for i = 1, min(#self.items, cells) do
|
|
||||||
local idx = i + self.item_idx - 1
|
|
||||||
local item = self.items[idx]
|
|
||||||
|
|
||||||
if self.selected_item and self.selected_item == item then
|
|
||||||
love.graphics.circle('line', 60*i, 30, 25)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
item:draw()
|
item:draw()
|
||||||
|
@ -173,6 +65,15 @@ inventory.draw = window.draw(function (self)
|
||||||
window.draw_border(self.width, self.height)
|
window.draw_border(self.width, self.height)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
function inventory:pickup(item)
|
||||||
|
util.add_entity(self.items, item)
|
||||||
|
|
||||||
|
local x = (#self.items - 1) * 60 + (60 - item.width) / 2
|
||||||
|
local y = (60 - item.height) / 2
|
||||||
|
|
||||||
|
item:setpos(x, y)
|
||||||
|
end
|
||||||
|
|
||||||
log = {
|
log = {
|
||||||
x = inventory.width , y = 0,
|
x = inventory.width , y = 0,
|
||||||
width = WIDTH - screen.width,
|
width = WIDTH - screen.width,
|
||||||
|
|
49
obj/door.lua
49
obj/door.lua
|
@ -19,49 +19,32 @@ local m = entity:from{
|
||||||
code = 0,
|
code = 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
m.draw = window.draw(function (self)
|
function m:draw()
|
||||||
if self.locked then
|
if self.locked then
|
||||||
self:draw_lines(locked_door)
|
self:draw_lines(locked_door)
|
||||||
else
|
else
|
||||||
self:draw_lines(open_door)
|
self:draw_lines(open_door)
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
|
|
||||||
function m:keyMode()
|
m.mousepressed = window.mousepressed(function (self)
|
||||||
self.mousepressed = window.mousepressed(function (self)
|
if self.locked then
|
||||||
if self.locked then
|
local i = inventory.selected_item
|
||||||
local i = inventory.selected_item
|
if i and i.code then
|
||||||
if i and i.code then
|
if i.code == self.code then
|
||||||
if i.code == self.code then
|
self.locked = false
|
||||||
self.locked = false
|
log:log("Door opened.")
|
||||||
inventory:use()
|
|
||||||
|
|
||||||
log:log("Door opened.")
|
|
||||||
else
|
|
||||||
log:log("This seems not a matching key.")
|
|
||||||
inventory.selected_item = nil
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
log:log("It's locked.")
|
log:log("This seems not a matching key.")
|
||||||
|
inventory.selected_item = nil
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
log:format("You enter %s", self.destination)
|
|
||||||
set_room(self.destination)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function m:keypadMode()
|
|
||||||
self.mousepressed = window.mousepressed(function (self)
|
|
||||||
if self.locked then
|
|
||||||
log:log("It's locked.")
|
log:log("It's locked.")
|
||||||
else
|
|
||||||
log:format("You enter %s", self.destination)
|
|
||||||
set_room(self.destination)
|
|
||||||
end
|
end
|
||||||
end)
|
else
|
||||||
end
|
log:format("You enter %s", self.destination)
|
||||||
|
set_room(self.destination)
|
||||||
m:keyMode()
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
|
|
@ -3,13 +3,9 @@ local entity = require('entity')
|
||||||
local keypad = require('room/keypad')
|
local keypad = require('room/keypad')
|
||||||
|
|
||||||
local m = entity:from{
|
local m = entity:from{
|
||||||
width = 30,
|
width = 50,
|
||||||
height = 40,
|
height = 50,
|
||||||
lines = {
|
lines = {'fill', {0, 0, 0, 50, 50, 50, 50, 0}},
|
||||||
{'fill', {0, 0, 0, 40, 30, 40, 30, 0}},
|
|
||||||
{'fill', {5, 5, 25, 5, 25, 10, 5, 10}},
|
|
||||||
{'fill', {5, 15, 25, 15, 25, 35, 5, 35}},
|
|
||||||
},
|
|
||||||
code = 45100,
|
code = 45100,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,13 +13,14 @@ local install = m.install
|
||||||
function m:install(room, x, y)
|
function m:install(room, x, y)
|
||||||
self.keypad = keypad:from{
|
self.keypad = keypad:from{
|
||||||
code = self.code,
|
code = self.code,
|
||||||
oncorrect = self.oncorrect,
|
|
||||||
room = room
|
room = room
|
||||||
}
|
}
|
||||||
|
|
||||||
install(self, room, x, y)
|
install(self, room, x, y)
|
||||||
end
|
end
|
||||||
|
|
||||||
m.mousepressed = window.portal("keypad")
|
m.mousepressed = window.mousepressed(function (self)
|
||||||
|
set_room_raw(self.keypad)
|
||||||
|
end)
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
|
|
@ -1,45 +0,0 @@
|
||||||
local entity = require("entity")
|
|
||||||
local window = require("window")
|
|
||||||
local seed = require("item/seed")
|
|
||||||
|
|
||||||
local pot = {
|
|
||||||
{'fill', {60, 80, 100, 80, 100, 90, 60, 90}},
|
|
||||||
{'fill', {65, 90, 95, 90, 90, 120, 70, 120}},
|
|
||||||
{'line', {80, 80, 70, 60, 60, 50}},
|
|
||||||
{'line', {70, 60, 80, 50}},
|
|
||||||
}
|
|
||||||
|
|
||||||
local m = entity:from{
|
|
||||||
width = 120,
|
|
||||||
height = 120,
|
|
||||||
grown = false,
|
|
||||||
}
|
|
||||||
|
|
||||||
function m:update()
|
|
||||||
end
|
|
||||||
|
|
||||||
m.draw = window.draw(function (self)
|
|
||||||
self:draw_lines(pot)
|
|
||||||
|
|
||||||
if grown then
|
|
||||||
love.graphics.circle('fill', 80, 50, 5)
|
|
||||||
for i = 0, 7 do
|
|
||||||
local x = 80 + 7 * math.sin(math.pi * i)
|
|
||||||
local y = 50 + 7 * math.cos(math.pi * i)
|
|
||||||
love.graphics.line(80, 50, x, y)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
m.mousepressed = window.mousepressed(function (self, x, y, button)
|
|
||||||
local i = inventory.selected_item
|
|
||||||
|
|
||||||
if i and i.name == "Flask" then
|
|
||||||
inventory:use()
|
|
||||||
local seed = seed:from{ colour = i.colour }
|
|
||||||
self.grown = true
|
|
||||||
seed:install(self.room, self.width + 80, self.height + 50)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
return m
|
|
23
obj/sign.lua
23
obj/sign.lua
|
@ -1,23 +0,0 @@
|
||||||
local entity = require("entity")
|
|
||||||
local window = require("window")
|
|
||||||
|
|
||||||
local m = entity:from{
|
|
||||||
width = 40,
|
|
||||||
height = 20,
|
|
||||||
text = "sample text",
|
|
||||||
}
|
|
||||||
|
|
||||||
m.draw = window.draw(function (self)
|
|
||||||
love.graphics.rectangle('fill', 0, 0, self.width, self.height)
|
|
||||||
|
|
||||||
love.graphics.setColor(0, 0, 0)
|
|
||||||
for i = 1, self.height/5 - 1 do
|
|
||||||
love.graphics.line(5, 5*i, self.width - 5, 5*i)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
m.mousepressed = window.mousepressed(function (self, x, y, button)
|
|
||||||
log:log("It reads: " .. self.text)
|
|
||||||
end)
|
|
||||||
|
|
||||||
return m
|
|
|
@ -1,31 +0,0 @@
|
||||||
local entity = require("entity")
|
|
||||||
local window = require("window")
|
|
||||||
local sundial = require("room/sundial")
|
|
||||||
|
|
||||||
local m = entity:from{
|
|
||||||
width = 60,
|
|
||||||
height = 60,
|
|
||||||
}
|
|
||||||
|
|
||||||
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.draw = window.draw(function (self)
|
|
||||||
love.graphics.ellipse('fill', 30, 45, 30, 15, 12)
|
|
||||||
love.graphics.polygon('fill', 30, 45, 55, 45, 30, 15)
|
|
||||||
love.graphics.setColor(0, 0, 0)
|
|
||||||
love.graphics.polygon('fill', 30, 45, 55, 45, 40, 55)
|
|
||||||
end)
|
|
||||||
|
|
||||||
m.mousepressed = window.mousepressed(function (self)
|
|
||||||
set_room_raw(self.sundial)
|
|
||||||
end)
|
|
||||||
|
|
||||||
return m
|
|
|
@ -1,24 +0,0 @@
|
||||||
local util = require("util")
|
|
||||||
local window = require("window")
|
|
||||||
local entity = require("entity")
|
|
||||||
|
|
||||||
local m = entity:from{
|
|
||||||
width = 50,
|
|
||||||
height = 50,
|
|
||||||
lines = {'fill', {0, 0, 50, 0, 40, 50, 10, 50}},
|
|
||||||
items = {},
|
|
||||||
}
|
|
||||||
|
|
||||||
m.mousepressed = window.mousepressed(function (self, x, y, button)
|
|
||||||
local i = inventory.selected_item
|
|
||||||
if i then
|
|
||||||
util.add_entity(self.items, i)
|
|
||||||
inventory:use()
|
|
||||||
elseif #self.items > 0 then
|
|
||||||
local last = self.items[#self.items]
|
|
||||||
util.del_entity(self.items, last)
|
|
||||||
inventory:pickup(last)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
return m
|
|
BIN
res/defaultbg.png
Normal file
BIN
res/defaultbg.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
62
room.lua
62
room.lua
|
@ -1,4 +1,3 @@
|
||||||
local util = require('util')
|
|
||||||
local window = require('window')
|
local window = require('window')
|
||||||
local entity = require('entity')
|
local entity = require('entity')
|
||||||
|
|
||||||
|
@ -7,29 +6,37 @@ local entity = require('entity')
|
||||||
-- - objects
|
-- - objects
|
||||||
-- - edges
|
-- - edges
|
||||||
local room = entity:from{
|
local room = entity:from{
|
||||||
lines = {
|
background = love.graphics.newImage("res/defaultbg.png"),
|
||||||
{'fill', {80, 60, 240, 60, 240, 180, 80, 180}},
|
edges = {},
|
||||||
{'line', {0, 0, 80, 60}},
|
objects = {},
|
||||||
{'line', {320, 0, 240, 60}},
|
|
||||||
{'line', {0, 240, 80, 180}},
|
|
||||||
{'line', {320, 240, 240, 180}},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local from = room.from
|
local oldnew = room.new
|
||||||
function room:from(t)
|
function room:new()
|
||||||
local r = from(self, t)
|
local r = oldnew(room)
|
||||||
|
|
||||||
r.edges = {}
|
r.edges = {}
|
||||||
r.objects = {}
|
r.objects = {}
|
||||||
|
|
||||||
return r
|
return r
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function room:insert(obj)
|
||||||
|
table.insert(self.objects, obj)
|
||||||
|
obj.idx = #self.objects
|
||||||
|
end
|
||||||
|
|
||||||
|
function room:remove(obj)
|
||||||
|
table.remove(self.objects, obj.idx)
|
||||||
|
|
||||||
|
for i, v in ipairs(self.objects) do
|
||||||
|
v.idx = i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
room.mousepressed = window.propagate{'edges', 'objects'}
|
room.mousepressed = window.propagate{'edges', 'objects'}
|
||||||
|
|
||||||
room.draw = window.draw(function (self)
|
function room:draw()
|
||||||
self:draw_lines(self.lines)
|
love.graphics.draw(self.background, 0, 0)
|
||||||
|
|
||||||
for i, v in ipairs(self.objects) do
|
for i, v in ipairs(self.objects) do
|
||||||
v:draw()
|
v:draw()
|
||||||
|
@ -38,33 +45,6 @@ room.draw = window.draw(function (self)
|
||||||
for i, v in ipairs(self.edges) do
|
for i, v in ipairs(self.edges) do
|
||||||
v:draw()
|
v:draw()
|
||||||
end
|
end
|
||||||
end)
|
|
||||||
|
|
||||||
function room:insert(obj)
|
|
||||||
util.add_entity(self.objects, obj)
|
|
||||||
end
|
|
||||||
|
|
||||||
function room:remove(obj)
|
|
||||||
util.del_entity(self.objects, obj)
|
|
||||||
end
|
|
||||||
|
|
||||||
function room:onenter()
|
|
||||||
if self.update then
|
|
||||||
register(self)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function room:onexit()
|
|
||||||
if self.update then
|
|
||||||
unregister(self)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function room.calc_align(width, height)
|
|
||||||
local sx = (320 - width)/2
|
|
||||||
local sy = (240 - height)/2
|
|
||||||
|
|
||||||
return sx, sy
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return room
|
return room
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
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
|
|
|
@ -5,9 +5,9 @@ local crowbar = require('item/crowbar')
|
||||||
local r = room:new()
|
local r = room:new()
|
||||||
|
|
||||||
crowbar:install(r, 100, 160)
|
crowbar:install(r, 100, 160)
|
||||||
edge.set(r, 'up', "default")
|
edge:set(r, 'up', "default")
|
||||||
edge.set(r, 'down', "sundial_alley")
|
edge:set(r, 'down', "default")
|
||||||
edge.set(r, 'left', "default")
|
edge:set(r, 'left', "default")
|
||||||
edge.set(r, 'right', "doortest")
|
edge:set(r, 'right', "doortest")
|
||||||
|
|
||||||
return r
|
return r
|
||||||
|
|
|
@ -11,22 +11,22 @@ local m = room:from{
|
||||||
|
|
||||||
local oldfrom = m.from
|
local oldfrom = m.from
|
||||||
function m:from(t)
|
function m:from(t)
|
||||||
local kp = oldfrom(self, t)
|
local kp = oldfrom(m, t)
|
||||||
|
|
||||||
local ks = kp.key_size
|
local ks = self.key_size
|
||||||
local kg = kp.key_gap
|
local kg = self.key_gap
|
||||||
|
|
||||||
local kd = ks + kg
|
local kd = ks + kg
|
||||||
local kw = kd*3 - kg
|
local kw = kd*3 - kg
|
||||||
local kh = kd*5 - kg
|
local kh = kd*5 - kg
|
||||||
local sx, sy = room.calc_align(kw, kh)
|
local sx = (320 - kw)/2
|
||||||
|
local sy = (240 - kh)/2
|
||||||
|
|
||||||
kp.number = 0
|
kp.number = 0
|
||||||
kp.keys = {}
|
kp.keys = {}
|
||||||
kp.pad_width = kw
|
kp.padx = sx
|
||||||
kp.pad_height = kh
|
kp.pady = sy
|
||||||
kp.pad_x = sx
|
kp.indicator_width = kw
|
||||||
kp.pad_y = sy
|
|
||||||
kp.state = 'normal'
|
kp.state = 'normal'
|
||||||
kp.timer = 0
|
kp.timer = 0
|
||||||
|
|
||||||
|
@ -47,13 +47,15 @@ function m:from(t)
|
||||||
|
|
||||||
kp.keys[0] = button.new('0',
|
kp.keys[0] = button.new('0',
|
||||||
function () kp:input(0) end,
|
function () kp:input(0) end,
|
||||||
sx + kd, br, ks, ks)
|
sx+kd, br, ks, ks)
|
||||||
|
|
||||||
kp.keys['A'] = button.new('A',
|
kp.keys['A'] = button.new('A',
|
||||||
function () kp:accept() end,
|
function () kp:accept() end,
|
||||||
sx + kd*2, br, ks, ks)
|
sx+kd*2, br, ks, ks)
|
||||||
|
|
||||||
edge.set(kp, "down", kp.room)
|
edge:set(m, "down", kp.room)
|
||||||
|
|
||||||
|
register(kp)
|
||||||
|
|
||||||
return kp
|
return kp
|
||||||
end
|
end
|
||||||
|
@ -68,21 +70,12 @@ function m:input(n)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function m:oncorrect()
|
|
||||||
log:log("Correct!")
|
|
||||||
end
|
|
||||||
|
|
||||||
function m:onwrong()
|
|
||||||
log:log("it seeems that the number does not match.")
|
|
||||||
end
|
|
||||||
|
|
||||||
function m:accept()
|
function m:accept()
|
||||||
if self.number == self.code then
|
if self.number == self.code then
|
||||||
self.state = 'correct'
|
log:log("correct!")
|
||||||
self:oncorrect()
|
|
||||||
else
|
else
|
||||||
self.state = 'wrong'
|
self.state = 'wrong'
|
||||||
self:onwrong()
|
log:log("it seeems that the number does not match.")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -101,21 +94,13 @@ end
|
||||||
m.draw = window.draw(function (self)
|
m.draw = window.draw(function (self)
|
||||||
love.graphics.setLineWidth(3)
|
love.graphics.setLineWidth(3)
|
||||||
|
|
||||||
-- start drawing keypad
|
|
||||||
|
|
||||||
-- draw indicator box
|
-- draw indicator box
|
||||||
love.graphics.rectangle('line', self.pad_x, self.pad_y, self.pad_width, self.key_size)
|
love.graphics.rectangle('line', self.padx, self.pady, self.indicator_width, self.key_size)
|
||||||
|
|
||||||
local function display(str)
|
|
||||||
love.graphics.printf(str, self.pad_x + 5, self.pad_y + 5, self.pad_width - 8, 'right')
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.state == 'normal' then
|
if self.state == 'normal' then
|
||||||
display(tostring(self.number))
|
love.graphics.printf(tostring(self.number), self.padx + 5, self.pady + 5, self.indicator_width - 8, 'right')
|
||||||
elseif self.state == 'correct' then
|
|
||||||
display("correct")
|
|
||||||
elseif self.state == 'wrong' then
|
elseif self.state == 'wrong' then
|
||||||
display("wrong")
|
love.graphics.printf("wrong", self.padx + 5, self.pady + 5, self.indicator_width - 8, 'right')
|
||||||
else
|
else
|
||||||
error("keypad is not in a defined state")
|
error("keypad is not in a defined state")
|
||||||
end
|
end
|
||||||
|
@ -130,11 +115,9 @@ end)
|
||||||
m.mousepressed = function (self, x, y, button)
|
m.mousepressed = function (self, x, y, button)
|
||||||
local x, y = x - self.x, y - self.y
|
local x, y = x - self.x, y - self.y
|
||||||
|
|
||||||
if self.state == 'normal' then
|
for i, v in pairs(self.keys) do
|
||||||
for i, v in pairs(self.keys) do
|
if v:mousepressed(x, y, button) then
|
||||||
if v:mousepressed(x, y, button) then
|
return
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
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
|
|
|
@ -1,34 +0,0 @@
|
||||||
local room = require("room")
|
|
||||||
local edge = require("edge")
|
|
||||||
local sundial = require("obj/sundial")
|
|
||||||
local keypad = require("obj/keypad")
|
|
||||||
local door = require("obj/door")
|
|
||||||
local sign = require("obj/sign")
|
|
||||||
|
|
||||||
local m = room:new()
|
|
||||||
|
|
||||||
sundial:from{
|
|
||||||
numbers = {3, 5, 8, 2, 7},
|
|
||||||
}:install(m, 135, 155)
|
|
||||||
|
|
||||||
local d = door:from{
|
|
||||||
destination = 'Vivarium',
|
|
||||||
}
|
|
||||||
|
|
||||||
d.mousepressed = d.keypadMode
|
|
||||||
d:install(m, 80, 60)
|
|
||||||
|
|
||||||
keypad:from{
|
|
||||||
code = 35827,
|
|
||||||
oncorrect = function (self)
|
|
||||||
d.locked = false
|
|
||||||
end,
|
|
||||||
}:install(m, 165, 110)
|
|
||||||
|
|
||||||
sign:from{
|
|
||||||
text = "If you desire to enter, you should follow the shadow"
|
|
||||||
}:install(m, 160, 80)
|
|
||||||
|
|
||||||
edge.set(m, 'down', "Alley")
|
|
||||||
|
|
||||||
return m
|
|
|
@ -1,23 +0,0 @@
|
||||||
local window = require("window")
|
|
||||||
local room = require("room")
|
|
||||||
local edge = require("edge")
|
|
||||||
local plant = require("obj/plant")
|
|
||||||
local trashcan = require("obj/trashcan")
|
|
||||||
|
|
||||||
local m = room:from{
|
|
||||||
}
|
|
||||||
|
|
||||||
local p = plant:from{
|
|
||||||
colour = Seed_colour,
|
|
||||||
room = m,
|
|
||||||
}
|
|
||||||
|
|
||||||
p:install(m, 40, 80)
|
|
||||||
|
|
||||||
trashcan:new():install(m, 180, 140)
|
|
||||||
|
|
||||||
edge.set(m, 'left', "vivarium_table")
|
|
||||||
edge.set(m, 'right', "vivarium_lock")
|
|
||||||
edge.set(m, 'down', "Sundial alley")
|
|
||||||
|
|
||||||
return m
|
|
|
@ -1,87 +0,0 @@
|
||||||
local window = require("window")
|
|
||||||
local entity = require("entity")
|
|
||||||
local room = require("room")
|
|
||||||
local edge = require("edge")
|
|
||||||
local button = require("button")
|
|
||||||
local seed = require("item/seed")
|
|
||||||
|
|
||||||
local shelf = entity:from{
|
|
||||||
width = 60,
|
|
||||||
height = 60,
|
|
||||||
item = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
shelf.draw = window.draw(function (self)
|
|
||||||
love.graphics.setLineWidth(3)
|
|
||||||
|
|
||||||
love.graphics.setColor(0, 0, 0)
|
|
||||||
love.graphics.rectangle('fill', 0, 0, self.width, self.height)
|
|
||||||
|
|
||||||
love.graphics.setColor(1, 1, 1)
|
|
||||||
love.graphics.rectangle('line', 0, 0, self.width, self.height)
|
|
||||||
|
|
||||||
if self.item then
|
|
||||||
self.item:draw()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
shelf.mousepressed = window.mousepressed(function (self, x, y, button)
|
|
||||||
if self.item then
|
|
||||||
inventory:pickup(self.item)
|
|
||||||
self.item = nil
|
|
||||||
self.item:setpos(20, 20)
|
|
||||||
else
|
|
||||||
local i = inventory.selected_item
|
|
||||||
if i and i.name == "Seed" then
|
|
||||||
self.item = i
|
|
||||||
inventory:use()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
local indicator = entity:from{
|
|
||||||
width = 100,
|
|
||||||
height = 20,
|
|
||||||
text = "",
|
|
||||||
}
|
|
||||||
|
|
||||||
indicator.draw = window.draw(function (self)
|
|
||||||
love.graphics.rectangle('line', 0, 0, self.width, self.height)
|
|
||||||
love.graphics.printf(self.text, 5, 5, self.width - 10)
|
|
||||||
end)
|
|
||||||
|
|
||||||
local m = room:from{
|
|
||||||
state = 'normal',
|
|
||||||
timer = 0,
|
|
||||||
lines = {},
|
|
||||||
}
|
|
||||||
|
|
||||||
local btn = button.new("Check", function ()
|
|
||||||
indicator.text = "Checking..."
|
|
||||||
m.state = 'checking'
|
|
||||||
end,
|
|
||||||
200, 120, 60, 30)
|
|
||||||
|
|
||||||
function m:update(dt)
|
|
||||||
if self.state == 'checking' then
|
|
||||||
self.timer = self.timer + dt
|
|
||||||
|
|
||||||
if self.timer > 5 then
|
|
||||||
indicator.text = "done"
|
|
||||||
self.state = 'normal'
|
|
||||||
self.timer = 0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
m:insert(btn)
|
|
||||||
|
|
||||||
indicator:install(m, 200, 90)
|
|
||||||
|
|
||||||
seed:new():install(m, 150, 120)
|
|
||||||
|
|
||||||
shelf:install(m, 60, 90)
|
|
||||||
|
|
||||||
edge.set(m, 'down', "Vivarium")
|
|
||||||
|
|
||||||
return m
|
|
|
@ -1,162 +0,0 @@
|
||||||
local util = require("util")
|
|
||||||
local window = require("window")
|
|
||||||
local entity = require("entity")
|
|
||||||
local room = require("room")
|
|
||||||
local edge = require("edge")
|
|
||||||
local button = require("button")
|
|
||||||
local flask = require("item/flask")
|
|
||||||
|
|
||||||
local function getColor(c)
|
|
||||||
local t = {
|
|
||||||
Red = { 1, 0, 0 },
|
|
||||||
Green = { 0, 1, 0 },
|
|
||||||
Blue = { 0, 0, 1 },
|
|
||||||
}
|
|
||||||
|
|
||||||
if type(c) == "string" then
|
|
||||||
return t[c]
|
|
||||||
else
|
|
||||||
return c
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local mixer = entity:from{
|
|
||||||
width = 130,
|
|
||||||
height = 110,
|
|
||||||
con_width = 60,
|
|
||||||
con_height = 100,
|
|
||||||
colours = {},
|
|
||||||
timer = 0,
|
|
||||||
anim = 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
function mixer:empty()
|
|
||||||
self.colours = {}
|
|
||||||
self.anim = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
local mempty = button.new("Empty", function ()
|
|
||||||
mixer:empty()
|
|
||||||
end,
|
|
||||||
75, 5, 50, 45)
|
|
||||||
|
|
||||||
local mmix = button.new("Mix", function ()
|
|
||||||
local len = #mixer.colours
|
|
||||||
local c = {0, 0, 0}
|
|
||||||
|
|
||||||
for k, v in ipairs(mixer.colours) do
|
|
||||||
local v = getColor(v)
|
|
||||||
for i = 1, 3 do
|
|
||||||
c[i] = c[i] + v[i]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
for i = 1, 3 do
|
|
||||||
c[i] = c[i] / len
|
|
||||||
end
|
|
||||||
|
|
||||||
mixer.colours = {}
|
|
||||||
for i = 1, len do
|
|
||||||
mixer.colours[i] = c
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
75, 60, 50, 45)
|
|
||||||
|
|
||||||
mixer.draw = window.draw(function (self)
|
|
||||||
local y = self.con_height + 5
|
|
||||||
for i, v in ipairs(self.colours) do
|
|
||||||
love.graphics.setColor(getColor(v))
|
|
||||||
local h = 5
|
|
||||||
if i == #self.colours then
|
|
||||||
h = h * self.anim
|
|
||||||
end
|
|
||||||
y = y - h
|
|
||||||
|
|
||||||
love.graphics.rectangle('fill', 5, y, self.con_width, h)
|
|
||||||
end
|
|
||||||
love.graphics.setColor(1, 1, 1)
|
|
||||||
|
|
||||||
mempty:draw()
|
|
||||||
mmix:draw()
|
|
||||||
|
|
||||||
love.graphics.rectangle('line', 5, 5, self.con_width, self.con_height)
|
|
||||||
|
|
||||||
love.graphics.rectangle('line', 0, 0, self.width, self.height)
|
|
||||||
end)
|
|
||||||
|
|
||||||
mixer.mousepressed = window.mousepressed(function (self, x, y, button)
|
|
||||||
if util.inside(x, y, 5, 5, self.con_width, self.con_height) and #self.colours > 0 then
|
|
||||||
local f = flask:from{ colour = getColor(self.colours[1]) }
|
|
||||||
f:itemMode()
|
|
||||||
inventory:pickup(f)
|
|
||||||
self:empty()
|
|
||||||
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
window.iterate({mempty, mmix}, x, y, button)
|
|
||||||
end)
|
|
||||||
|
|
||||||
mixer.update = function (self, dt)
|
|
||||||
self.timer = self.timer + dt
|
|
||||||
if self.timer > 1/20 then
|
|
||||||
self.timer = self.timer - 1/20
|
|
||||||
self.anim = self.anim + 1/20
|
|
||||||
if self.anim > 1 then
|
|
||||||
self.anim = 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function mixer:add(colour)
|
|
||||||
table.insert(self.colours, colour)
|
|
||||||
self.anim = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
local vial = entity:from {
|
|
||||||
width = 20,
|
|
||||||
height = 60,
|
|
||||||
colour = ""
|
|
||||||
}
|
|
||||||
|
|
||||||
vial.draw = window.draw(function (self)
|
|
||||||
love.graphics.setColor(getColor(self.colour))
|
|
||||||
love.graphics.rectangle('fill', 0, 0, 20, 50)
|
|
||||||
love.graphics.arc('fill', 'open', 10, 50, 10, 0, math.pi)
|
|
||||||
|
|
||||||
love.graphics.setColor(1, 1, 1)
|
|
||||||
love.graphics.line(0, 50, 0, 0, 20, 0, 20, 50)
|
|
||||||
love.graphics.arc('line', 'open', 10, 50, 10, 0, math.pi)
|
|
||||||
end)
|
|
||||||
|
|
||||||
vial.mousepressed = window.mousepressed(function (self, x, y, button)
|
|
||||||
mixer:add(self.colour)
|
|
||||||
end)
|
|
||||||
|
|
||||||
local m = room:new()
|
|
||||||
|
|
||||||
mixer:install(m, 160, 40)
|
|
||||||
vial:from{ colour = "Red" }:install(m, 20, 40)
|
|
||||||
vial:from{ colour = "Green" }:install(m, 60, 40)
|
|
||||||
vial:from{ colour = "Blue" }:install(m, 100, 40)
|
|
||||||
|
|
||||||
edge.set(m, 'down', "Vivarium")
|
|
||||||
|
|
||||||
m.draw = window.draw(function (self)
|
|
||||||
love.graphics.setLineWidth(3)
|
|
||||||
love.graphics.line(0, 200, 320, 200)
|
|
||||||
love.graphics.rectangle('line', 10, 200, 20, 40)
|
|
||||||
love.graphics.rectangle('line', 290, 200, 20, 40)
|
|
||||||
|
|
||||||
for i, v in ipairs(self.objects) do
|
|
||||||
v:draw()
|
|
||||||
end
|
|
||||||
|
|
||||||
self.edges[1]:draw()
|
|
||||||
end)
|
|
||||||
|
|
||||||
m.update = function (self, dt)
|
|
||||||
mixer:update(dt)
|
|
||||||
end
|
|
||||||
|
|
||||||
return m
|
|
|
@ -1,11 +1,6 @@
|
||||||
local m = {
|
local m = {
|
||||||
['default'] = require('room/default'),
|
['default'] = require('room/default'),
|
||||||
['doortest'] = require('room/doortest'),
|
['doortest'] = require('room/doortest'),
|
||||||
['Alley'] = require("room/alley"),
|
|
||||||
['Sundial alley'] = require("room/sundial_alley"),
|
|
||||||
['Vivarium'] = require("room/vivarium"),
|
|
||||||
['vivarium_table'] = require("room/vivarium_table"),
|
|
||||||
['vivarium_lock'] = require("room/vivarium_lock"),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
|
9
util.lua
9
util.lua
|
@ -23,17 +23,14 @@ end
|
||||||
|
|
||||||
function m.add_entity(a, x)
|
function m.add_entity(a, x)
|
||||||
table.insert(a, x)
|
table.insert(a, x)
|
||||||
if not x.idx then
|
x.idx = #a
|
||||||
x.idx = {}
|
|
||||||
end
|
|
||||||
x.idx[a] = #a
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function m.del_entity(a, x)
|
function m.del_entity(a, x)
|
||||||
table.remove(a, x.idx[a])
|
table.remove(a, x.idx)
|
||||||
|
|
||||||
for i, v in ipairs(a) do
|
for i, v in ipairs(a) do
|
||||||
v.idx[a] = i
|
v.idx = i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
20
window.lua
20
window.lua
|
@ -25,30 +25,20 @@ function w.mousepressed(f)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function w.iterate(t, x, y, button)
|
|
||||||
for i, v in util.ipairs_rev(t) do
|
|
||||||
if v:mousepressed(x, y, button) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function w.propagate(tnames)
|
function w.propagate(tnames)
|
||||||
return function (self, x, y, button)
|
return function (self, x, y, button)
|
||||||
local x, y = x - self.x, y - self.y
|
local x, y = x - self.x, y - self.y
|
||||||
|
|
||||||
for _, tname in ipairs(tnames) do
|
for _, tname in ipairs(tnames) do
|
||||||
w.iterate(self[tname], x, y, button)
|
for i, v in util.ipairs_rev(self[tname]) do
|
||||||
|
if v:mousepressed(x, y, button) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
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)
|
function w.draw_border(width, height)
|
||||||
love.graphics.push('all')
|
love.graphics.push('all')
|
||||||
love.graphics.setLineWidth(5)
|
love.graphics.setLineWidth(5)
|
||||||
|
|
Loading…
Add table
Reference in a new issue