Update
This commit is contained in:
parent
0cbc05c30f
commit
3c4c6df308
9 changed files with 122 additions and 26 deletions
|
@ -17,11 +17,11 @@ function m.new(text, callback, x, y, width, height)
|
||||||
ty = (height - th) / 2
|
ty = (height - th) / 2
|
||||||
}
|
}
|
||||||
|
|
||||||
btn.mousepressed = window.mousepressed(function(self, x, y, button)
|
btn.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||||
callback(x, y, button)
|
callback(x, y, button)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
btn.draw = window.draw(function(self)
|
btn.draw = window.draw(function (self)
|
||||||
love.graphics.printf(self.text, self.tx, self.ty, self.width)
|
love.graphics.printf(self.text, self.tx, self.ty, self.width)
|
||||||
window.draw_border(self.width, self.height)
|
window.draw_border(self.width, self.height)
|
||||||
end)
|
end)
|
||||||
|
|
6
conf.lua
6
conf.lua
|
@ -1,6 +1,6 @@
|
||||||
WIDTH = 320
|
WIDTH = 400
|
||||||
HEIGHT = 240
|
HEIGHT = 300
|
||||||
MULTIPLIER = 1.5
|
MULTIPLIER = 1.2
|
||||||
|
|
||||||
function love.conf(t)
|
function love.conf(t)
|
||||||
t.window.width = MULTIPLIER * WIDTH
|
t.window.width = MULTIPLIER * WIDTH
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
rm garden.love
|
rm garden.love
|
||||||
zip garden.love *.lua
|
zip -r garden.love res/ room/ *.lua
|
||||||
cp garden.love ~/storage/downloads/
|
cp garden.love ~/storage/downloads/
|
||||||
|
|
55
main.lua
55
main.lua
|
@ -1,36 +1,46 @@
|
||||||
-- Imports
|
-- Imports
|
||||||
local window = require("window")
|
local window = require("window")
|
||||||
local button = require("button")
|
local button = require("button")
|
||||||
|
local rooms = require("rooms")
|
||||||
|
|
||||||
local inventory = {
|
local current_room = rooms['default']
|
||||||
|
|
||||||
|
screen = {
|
||||||
|
x = 0, y = 60,
|
||||||
|
width = 320,
|
||||||
|
height = 240,
|
||||||
|
}
|
||||||
|
|
||||||
|
screen.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||||
|
end)
|
||||||
|
|
||||||
|
screen.draw = window.draw(function (self)
|
||||||
|
current_room:draw()
|
||||||
|
window.draw_border(self.width, self.height)
|
||||||
|
end)
|
||||||
|
|
||||||
|
inventory = {
|
||||||
x = 0, y = 0,
|
x = 0, y = 0,
|
||||||
width = WIDTH*0.7,
|
width = screen.width,
|
||||||
height = HEIGHT*0.2,
|
height = 60,
|
||||||
|
items = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
inventory.draw = window.draw(function(self)
|
inventory.draw = window.draw(function (self)
|
||||||
|
for _, item in ipairs(self.items) do
|
||||||
|
-- item:setpos(x, y)
|
||||||
|
item:draw()
|
||||||
|
end
|
||||||
window.draw_border(self.width, self.height)
|
window.draw_border(self.width, self.height)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local screen = {
|
log = {
|
||||||
x = 0, y = inventory.height,
|
|
||||||
width = inventory.width,
|
|
||||||
height = HEIGHT - inventory.height,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
screen.draw = window.draw(function(self)
|
|
||||||
window.draw_border(self.width, self.height)
|
|
||||||
end)
|
|
||||||
|
|
||||||
local log = {
|
|
||||||
x = inventory.width , y = 0,
|
x = inventory.width , y = 0,
|
||||||
width = WIDTH*0.3,
|
width = 80,
|
||||||
height = HEIGHT,
|
height = HEIGHT,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.draw = window.draw(function (self)
|
||||||
log.draw = window.draw(function(self)
|
|
||||||
window.draw_border(self.width, self.height)
|
window.draw_border(self.width, self.height)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -46,8 +56,15 @@ function love.update(dt)
|
||||||
timer = timer + dt
|
timer = timer + dt
|
||||||
end
|
end
|
||||||
|
|
||||||
|
mw, mh = 0, 0
|
||||||
|
if love.system.getOS() == 'android' then
|
||||||
|
mw = (love.window.getWidth() - WIDTH) / 2
|
||||||
|
mh = (love.window.getHeight() - HEIGHT) / 2
|
||||||
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
love.graphics.push()
|
love.graphics.push()
|
||||||
|
love.graphics.translate(mw, mh)
|
||||||
love.graphics.scale(MULTIPLIER)
|
love.graphics.scale(MULTIPLIER)
|
||||||
|
|
||||||
screen:draw()
|
screen:draw()
|
||||||
|
|
BIN
res/defaultbg.png
Normal file
BIN
res/defaultbg.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
51
room.lua
Normal file
51
room.lua
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
local window = require('window')
|
||||||
|
|
||||||
|
-- prototype of room
|
||||||
|
-- - background
|
||||||
|
-- - objects
|
||||||
|
-- - edges
|
||||||
|
local room = {
|
||||||
|
background = love.graphics.newImage("res/defaultbg.png"),
|
||||||
|
edges = {},
|
||||||
|
objects = {},
|
||||||
|
}
|
||||||
|
|
||||||
|
function edge_position(e)
|
||||||
|
local wd = screen.width - e.width
|
||||||
|
local hd = screen.height - e.height
|
||||||
|
|
||||||
|
local t = {
|
||||||
|
['left'] = { 0, hd/2 },
|
||||||
|
['right'] = { wd, hd/2 },
|
||||||
|
['up'] = { wd/2, 0 },
|
||||||
|
['down'] = { wd/2, hd },
|
||||||
|
}
|
||||||
|
|
||||||
|
local p = t[e.dir]
|
||||||
|
return p[1], p[2]
|
||||||
|
end
|
||||||
|
|
||||||
|
local mt = { __index = room }
|
||||||
|
|
||||||
|
function room:new()
|
||||||
|
local m = {}
|
||||||
|
setmetatable(m, mt)
|
||||||
|
return m
|
||||||
|
end
|
||||||
|
|
||||||
|
room.mousepressed = window.propagate{'edges', 'objects'}
|
||||||
|
|
||||||
|
function room:draw()
|
||||||
|
love.graphics.draw(self.background, 0, 0)
|
||||||
|
|
||||||
|
for i, v in ipairs(self.objects) do
|
||||||
|
v: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)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return room
|
7
room/default.lua
Normal file
7
room/default.lua
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
local room = require('room')
|
||||||
|
|
||||||
|
local r = room:new()
|
||||||
|
|
||||||
|
r.background = love.graphics.newImage("res/defaultbg.png")
|
||||||
|
|
||||||
|
return r
|
5
rooms.lua
Normal file
5
rooms.lua
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
local m = {
|
||||||
|
['default'] = require('room/default'),
|
||||||
|
}
|
||||||
|
|
||||||
|
return m
|
18
window.lua
18
window.lua
|
@ -1,4 +1,5 @@
|
||||||
-- primitive of drawing objects
|
-- function generator for window functions
|
||||||
|
|
||||||
local w = {}
|
local w = {}
|
||||||
|
|
||||||
function w.draw(f)
|
function w.draw(f)
|
||||||
|
@ -20,6 +21,21 @@ function w.mousepressed(f)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function w.propagate(tnames)
|
||||||
|
return function(self, x, y, button)
|
||||||
|
for _, tname in ipairs(tnames) do
|
||||||
|
for i, v in pairs(self[tname]) do
|
||||||
|
local x, y = x - v.x, y - v.y
|
||||||
|
|
||||||
|
if 0 <= x and x <= v.width and 0 <= y and y <= v.height then
|
||||||
|
v:mousepressed(x, y, button)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
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