diff --git a/edge.lua b/edge.lua new file mode 100644 index 0000000..b51355a --- /dev/null +++ b/edge.lua @@ -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 diff --git a/entity.lua b/entity.lua index 7f74718..4893017 100644 --- a/entity.lua +++ b/entity.lua @@ -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) diff --git a/main.lua b/main.lua index fca4c60..c192b2b 100644 --- a/main.lua +++ b/main.lua @@ -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, diff --git a/room.lua b/room.lua index de8cf78..1a1d2c0 100644 --- a/room.lua +++ b/room.lua @@ -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 diff --git a/room/default.lua b/room/default.lua index b1a5779..02c1303 100644 --- a/room/default.lua +++ b/room/default.lua @@ -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