Update
This commit is contained in:
parent
ada33393e5
commit
069d4a03f6
10 changed files with 76 additions and 53 deletions
1
item.lua
1
item.lua
|
@ -27,7 +27,6 @@ function m:itemMode()
|
|||
self.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||
log:info(self)
|
||||
inventory.selected_item = self
|
||||
log:format("selected idx : %s", inventory.selected_item.idx)
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
12
main.lua
12
main.lua
|
@ -17,15 +17,17 @@ end
|
|||
--load room list
|
||||
local rooms = require("rooms")
|
||||
|
||||
current_room = rooms['default']
|
||||
current_room = rooms['Alley']
|
||||
|
||||
function set_room_raw(r)
|
||||
current_room:onexit()
|
||||
current_room = r
|
||||
current_room:onenter()
|
||||
end
|
||||
|
||||
function set_room(r)
|
||||
current_room = rooms[r]
|
||||
assert(current_room)
|
||||
assert(rooms[r])
|
||||
set_room_raw(rooms[r])
|
||||
end
|
||||
|
||||
screen = {
|
||||
|
@ -64,7 +66,7 @@ end)
|
|||
|
||||
inventory.draw = window.draw(function (self)
|
||||
for i, item in pairs(self.items) do
|
||||
if self.selected_item and self.selected_item.idx == i then
|
||||
if self.selected_item and self.selected_item == item then
|
||||
love.graphics.circle('line', 60*i - 30, 30, 25)
|
||||
end
|
||||
|
||||
|
@ -83,7 +85,7 @@ end
|
|||
|
||||
function inventory:pickup(item)
|
||||
util.add_entity(self.items, item)
|
||||
self:set_pos(item.idx, item)
|
||||
self:set_pos(item.idx[self.items], item)
|
||||
end
|
||||
|
||||
function inventory:drop(item)
|
||||
|
|
14
obj/door.lua
14
obj/door.lua
|
@ -27,7 +27,8 @@ function m:draw()
|
|||
end
|
||||
end
|
||||
|
||||
m.keyMode = window.mousepressed(function (self)
|
||||
function m:keyMode()
|
||||
self.mousepressed = window.mousepressed(function (self)
|
||||
if self.locked then
|
||||
local i = inventory.selected_item
|
||||
if i and i.code then
|
||||
|
@ -47,17 +48,20 @@ m.keyMode = window.mousepressed(function (self)
|
|||
log:format("You enter %s", self.destination)
|
||||
set_room(self.destination)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
end
|
||||
|
||||
m.keypadMode = window.mousepressed(function (self)
|
||||
function m:keypadMode()
|
||||
self.mousepressed = 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)
|
||||
end)
|
||||
end
|
||||
|
||||
m.mousepressed = m.keyMode
|
||||
m:keyMode()
|
||||
|
||||
return m
|
||||
|
|
|
@ -3,9 +3,13 @@ local entity = require('entity')
|
|||
local keypad = require('room/keypad')
|
||||
|
||||
local m = entity:from{
|
||||
width = 50,
|
||||
height = 50,
|
||||
lines = {'fill', {0, 0, 0, 50, 50, 50, 50, 0}},
|
||||
width = 30,
|
||||
height = 40,
|
||||
lines = {
|
||||
{'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,
|
||||
}
|
||||
|
||||
|
|
29
room.lua
29
room.lua
|
@ -26,14 +26,6 @@ function room:from(t)
|
|||
return r
|
||||
end
|
||||
|
||||
function room:insert(obj)
|
||||
util.add_entity(self.objects, obj)
|
||||
end
|
||||
|
||||
function room:remove(obj)
|
||||
util.del_entity(self.objects, obj)
|
||||
end
|
||||
|
||||
room.mousepressed = window.propagate{'edges', 'objects'}
|
||||
|
||||
function room:draw()
|
||||
|
@ -48,6 +40,27 @@ function room:draw()
|
|||
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
|
||||
|
|
|
@ -3,7 +3,7 @@ local edge = require("edge")
|
|||
|
||||
local m = room:new()
|
||||
|
||||
edge.set(m, 'down', "sundial_alley")
|
||||
edge.set(m, 'down', "Sundial alley")
|
||||
--edge.set(m, 'left', "alley2")
|
||||
|
||||
return m
|
||||
|
|
|
@ -55,8 +55,6 @@ function m:from(t)
|
|||
|
||||
edge.set(kp, "down", kp.room)
|
||||
|
||||
register(kp)
|
||||
|
||||
return kp
|
||||
end
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ keypad:from{
|
|||
oncorrect = function (self)
|
||||
d.locked = false
|
||||
end,
|
||||
}:install(m, 180, 100)
|
||||
}:install(m, 160, 90)
|
||||
|
||||
edge.set(m, 'up', "alley")
|
||||
edge.set(m, 'up', "Alley")
|
||||
|
||||
return m
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
local m = {
|
||||
['default'] = require('room/default'),
|
||||
['doortest'] = require('room/doortest'),
|
||||
['alley'] = require("room/alley"),
|
||||
['sundial_alley'] = require("room/sundial_alley"),
|
||||
['Alley'] = require("room/alley"),
|
||||
['Sundial alley'] = require("room/sundial_alley"),
|
||||
}
|
||||
|
||||
return m
|
||||
|
|
9
util.lua
9
util.lua
|
@ -23,14 +23,17 @@ end
|
|||
|
||||
function m.add_entity(a, x)
|
||||
table.insert(a, x)
|
||||
x.idx = #a
|
||||
if not x.idx then
|
||||
x.idx = {}
|
||||
end
|
||||
x.idx[a] = #a
|
||||
end
|
||||
|
||||
function m.del_entity(a, x)
|
||||
table.remove(a, x.idx)
|
||||
table.remove(a, x.idx[a])
|
||||
|
||||
for i, v in ipairs(a) do
|
||||
v.idx = i
|
||||
v.idx[a] = i
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue