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)
 | 
					    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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										12
									
								
								main.lua
									
										
									
									
									
								
							
							
						
						
									
										12
									
								
								main.lua
									
										
									
									
									
								
							| 
						 | 
					@ -17,15 +17,17 @@ end
 | 
				
			||||||
--load room list
 | 
					--load room list
 | 
				
			||||||
local rooms = require("rooms")
 | 
					local rooms = require("rooms")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
current_room = rooms['default']
 | 
					current_room = rooms['Alley']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
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)
 | 
				
			||||||
    current_room = rooms[r]
 | 
					    assert(rooms[r])
 | 
				
			||||||
    assert(current_room)
 | 
					    set_room_raw(rooms[r])
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
screen = {
 | 
					screen = {
 | 
				
			||||||
| 
						 | 
					@ -64,7 +66,7 @@ end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
inventory.draw = window.draw(function (self)
 | 
					inventory.draw = window.draw(function (self)
 | 
				
			||||||
    for i, item in pairs(self.items) do
 | 
					    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)
 | 
					            love.graphics.circle('line', 60*i - 30, 30, 25)
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -83,7 +85,7 @@ end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function inventory:pickup(item)
 | 
					function inventory:pickup(item)
 | 
				
			||||||
    util.add_entity(self.items, item)
 | 
					    util.add_entity(self.items, item)
 | 
				
			||||||
    self:set_pos(item.idx, item)
 | 
					    self:set_pos(item.idx[self.items], item)
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function inventory:drop(item)
 | 
					function inventory:drop(item)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										10
									
								
								obj/door.lua
									
										
									
									
									
								
							
							
						
						
									
										10
									
								
								obj/door.lua
									
										
									
									
									
								
							| 
						 | 
					@ -27,7 +27,8 @@ function m:draw()
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
m.keyMode = window.mousepressed(function (self)
 | 
					function m:keyMode()
 | 
				
			||||||
 | 
					    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
 | 
				
			||||||
| 
						 | 
					@ -48,8 +49,10 @@ m.keyMode = window.mousepressed(function (self)
 | 
				
			||||||
            set_room(self.destination)
 | 
					            set_room(self.destination)
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
    end)
 | 
					    end)
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
m.keypadMode = window.mousepressed(function (self)
 | 
					function m:keypadMode()
 | 
				
			||||||
 | 
					    self.mousepressed = window.mousepressed(function (self)
 | 
				
			||||||
        if self.locked then
 | 
					        if self.locked then
 | 
				
			||||||
            log:log("It's locked.")
 | 
					            log:log("It's locked.")
 | 
				
			||||||
        else
 | 
					        else
 | 
				
			||||||
| 
						 | 
					@ -57,7 +60,8 @@ m.keypadMode = window.mousepressed(function (self)
 | 
				
			||||||
            set_room(self.destination)
 | 
					            set_room(self.destination)
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
    end)
 | 
					    end)
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
m.mousepressed = m.keyMode
 | 
					m:keyMode()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
return m
 | 
					return m
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,9 +3,13 @@ local entity = require('entity')
 | 
				
			||||||
local keypad = require('room/keypad')
 | 
					local keypad = require('room/keypad')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local m = entity:from{
 | 
					local m = entity:from{
 | 
				
			||||||
    width = 50,
 | 
					    width = 30,
 | 
				
			||||||
    height = 50,
 | 
					    height = 40,
 | 
				
			||||||
    lines = {'fill', {0, 0, 0, 50, 50, 50, 50, 0}},
 | 
					    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,
 | 
					    code = 45100,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										29
									
								
								room.lua
									
										
									
									
									
								
							
							
						
						
									
										29
									
								
								room.lua
									
										
									
									
									
								
							| 
						 | 
					@ -26,14 +26,6 @@ function room:from(t)
 | 
				
			||||||
    return r
 | 
					    return r
 | 
				
			||||||
end
 | 
					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'}
 | 
					room.mousepressed = window.propagate{'edges', 'objects'}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function room:draw()
 | 
					function room:draw()
 | 
				
			||||||
| 
						 | 
					@ -48,6 +40,27 @@ function room:draw()
 | 
				
			||||||
    end
 | 
					    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)
 | 
					function room.calc_align(width, height)
 | 
				
			||||||
    local sx = (320 - width)/2
 | 
					    local sx = (320 - width)/2
 | 
				
			||||||
    local sy = (240 - height)/2
 | 
					    local sy = (240 - height)/2
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3,7 +3,7 @@ local edge = require("edge")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local m = room:new()
 | 
					local m = room:new()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
edge.set(m, 'down', "sundial_alley")
 | 
					edge.set(m, 'down', "Sundial alley")
 | 
				
			||||||
--edge.set(m, 'left', "alley2")
 | 
					--edge.set(m, 'left', "alley2")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
return m
 | 
					return m
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -55,8 +55,6 @@ function m:from(t)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    edge.set(kp, "down", kp.room)
 | 
					    edge.set(kp, "down", kp.room)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    register(kp)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return kp
 | 
					    return kp
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -22,8 +22,8 @@ keypad:from{
 | 
				
			||||||
    oncorrect = function (self)
 | 
					    oncorrect = function (self)
 | 
				
			||||||
        d.locked = false
 | 
					        d.locked = false
 | 
				
			||||||
    end,
 | 
					    end,
 | 
				
			||||||
}:install(m, 180, 100)
 | 
					}:install(m, 160, 90)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
edge.set(m, 'up', "alley")
 | 
					edge.set(m, 'up', "Alley")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
return m
 | 
					return m
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,8 +1,8 @@
 | 
				
			||||||
local m = {
 | 
					local m = {
 | 
				
			||||||
    ['default'] = require('room/default'),
 | 
					    ['default'] = require('room/default'),
 | 
				
			||||||
    ['doortest'] = require('room/doortest'),
 | 
					    ['doortest'] = require('room/doortest'),
 | 
				
			||||||
    ['alley'] = require("room/alley"),
 | 
					    ['Alley'] = require("room/alley"),
 | 
				
			||||||
    ['sundial_alley'] = require("room/sundial_alley"),
 | 
					    ['Sundial alley'] = require("room/sundial_alley"),
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
return m
 | 
					return m
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										9
									
								
								util.lua
									
										
									
									
									
								
							
							
						
						
									
										9
									
								
								util.lua
									
										
									
									
									
								
							| 
						 | 
					@ -23,14 +23,17 @@ end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function m.add_entity(a, x)
 | 
					function m.add_entity(a, x)
 | 
				
			||||||
    table.insert(a, x)
 | 
					    table.insert(a, x)
 | 
				
			||||||
    x.idx = #a
 | 
					    if not x.idx then
 | 
				
			||||||
 | 
					        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)
 | 
					    table.remove(a, x.idx[a])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for i, v in ipairs(a) do
 | 
					    for i, v in ipairs(a) do
 | 
				
			||||||
        v.idx = i
 | 
					        v.idx[a] = i
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue