This commit is contained in:
백현웅 2025-01-03 20:36:39 +09:00
parent a340c8f8b0
commit 3179442942
5 changed files with 84 additions and 6 deletions

70
edge.lua Normal file
View file

@ -0,0 +1,70 @@
local window = require('window')
local entity = require('entity')
-- 320x240
local edge_data = {
up = {
x = 120,
y = 10,
width = 80,
height = 10,
lines = {{'fill', {0, 10, 80, 10, 40, 0}}},
},
down = {
x = 120,
y = 220,
width = 80,
height = 10,
lines = {{'fill', {0, 0, 80, 0, 40, 10}}},
},
left = {
x = 10,
y = 80,
width = 10,
height = 80,
lines = {{'fill', {10, 0, 10, 80, 0, 40}}},
},
right = {
x = 300,
y = 80,
width = 10,
height = 80,
lines = {{'fill', {0, 0, 0, 80, 10, 40}}},
}
}
local edge = entity:from{
dir = "up",
destination = "nowhere",
mousepressed = window.mousepressed(function (self)
log:log(string.format("You enter %s", self.destination))
set_room(self.destination)
end)
}
local mt = {
__index = function (t, k)
if edge_data[t.dir][k] then
return edge_data[t.dir][k]
else
return edge[k]
end
end
}
function edge:set(room, dir, dst)
local e = self:from{
dir = dir,
destination = dst,
}
setmetatable(e, mt)
table.insert(room.edges, e)
end
return edge

View file

@ -41,8 +41,8 @@ function m:draw()
elseif mode == 'fill' then
local ts = love.math.triangulate(segs)
love.graphics.setColor(0, 0, 0)
for _, t in ipairs(ts) do
love.graphics.polygon('fill', ts)
for i, t in ipairs(ts) do
love.graphics.polygon('fill', t)
end
love.graphics.setColor(1, 1, 1)

View file

@ -3,7 +3,11 @@ local window = require("window")
local button = require("button")
local rooms = require("rooms")
local current_room = rooms['default']
current_room = rooms['default']
function set_room(r)
current_room = rooms[r]
end
screen = {
x = 0, y = 60,

View file

@ -50,8 +50,7 @@ function room:draw()
end
for i, v in ipairs(self.edges) do
local x, y = edge_position(v)
love.graphics.draw(edge_arrow[v.dir], x, y)
v:draw()
end
end

View file

@ -1,10 +1,15 @@
local room = require('room')
local edge = require('edge')
local crowbar = require('item/crowbar')
local r = room:new()
r.background = love.graphics.newImage("res/defaultbg.png")
local crowbar = require('item/crowbar')
crowbar:install(r, 100, 160)
edge:set(r, 'up', "default")
edge:set(r, 'down', "default")
edge:set(r, 'left', "default")
edge:set(r, 'right', "default")
return r