Update
This commit is contained in:
parent
3a6c9ec3ad
commit
568a6c779c
11 changed files with 236 additions and 14 deletions
2
conf.lua
2
conf.lua
|
@ -2,6 +2,8 @@ WIDTH = 528
|
|||
HEIGHT = 300
|
||||
MULTIPLIER = 1.2
|
||||
|
||||
Seed_colour = {0.4, 0.2, 0.4}
|
||||
|
||||
--[[
|
||||
SCREEN_WIDTH = 320
|
||||
SCREEN_HEIGHT = 240
|
||||
|
|
5
edge.lua
5
edge.lua
|
@ -52,6 +52,11 @@ local edge = entity:from{
|
|||
end)
|
||||
}
|
||||
|
||||
edge.draw = window.draw(function (self)
|
||||
love.graphics.setLineJoin('bevel')
|
||||
self:draw_lines(self.lines)
|
||||
end)
|
||||
|
||||
local mt = {
|
||||
__index = function (t, k)
|
||||
if edge_data[t.dir][k] then
|
||||
|
|
|
@ -46,8 +46,6 @@ local function draw_line(l)
|
|||
end
|
||||
|
||||
function m:draw_lines(lines)
|
||||
love.graphics.push('all')
|
||||
love.graphics.translate(self.x, self.y)
|
||||
love.graphics.setLineWidth(2)
|
||||
|
||||
if type(lines[1]) == 'string' then
|
||||
|
@ -57,13 +55,11 @@ function m:draw_lines(lines)
|
|||
draw_line(l)
|
||||
end
|
||||
end
|
||||
|
||||
love.graphics.pop()
|
||||
end
|
||||
|
||||
function m:draw()
|
||||
m.draw = window.draw(function (self)
|
||||
self:draw_lines(self.lines)
|
||||
end
|
||||
end)
|
||||
|
||||
m.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||
end)
|
||||
|
|
24
item/flask.lua
Normal file
24
item/flask.lua
Normal file
|
@ -0,0 +1,24 @@
|
|||
local window = require('window')
|
||||
local item = require('item')
|
||||
|
||||
local line = {
|
||||
15, 0, 25, 0,
|
||||
40, 40, 0, 40,
|
||||
}
|
||||
|
||||
local m = item:from{
|
||||
width = 40,
|
||||
height = 40,
|
||||
colour = {0, 0, 0},
|
||||
name = "Flask",
|
||||
description = "A glass container filled with liquid.",
|
||||
}
|
||||
|
||||
m.draw = window.draw(function (self)
|
||||
love.graphics.setColor(self.colour)
|
||||
love.graphics.polygon('fill', line)
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
love.graphics.polygon('line', line)
|
||||
end)
|
||||
|
||||
return m
|
|
@ -19,13 +19,13 @@ local m = entity:from{
|
|||
code = 0,
|
||||
}
|
||||
|
||||
function m:draw()
|
||||
m.draw = window.draw(function (self)
|
||||
if self.locked then
|
||||
self:draw_lines(locked_door)
|
||||
else
|
||||
self:draw_lines(open_door)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
function m:keyMode()
|
||||
self.mousepressed = window.mousepressed(function (self)
|
||||
|
|
|
@ -5,11 +5,14 @@ local seed = require("item/seed")
|
|||
local pot = {
|
||||
{'fill', {60, 80, 100, 80, 100, 90, 60, 90}},
|
||||
{'fill', {65, 90, 95, 90, 90, 120, 70, 120}},
|
||||
{'line', {80, 80, 70, 60, 60, 50}},
|
||||
{'line', {70, 60, 80, 50}},
|
||||
}
|
||||
|
||||
local m = entity:from{
|
||||
width = 120,
|
||||
height = 120,
|
||||
grown = false,
|
||||
}
|
||||
|
||||
function m:update()
|
||||
|
@ -17,6 +20,26 @@ end
|
|||
|
||||
m.draw = window.draw(function (self)
|
||||
self:draw_lines(pot)
|
||||
|
||||
if grown then
|
||||
love.graphics.circle('fill', 80, 50, 5)
|
||||
for i = 0, 7 do
|
||||
local x = 80 + 7 * math.sin(math.pi * i)
|
||||
local y = 50 + 7 * math.cos(math.pi * i)
|
||||
love.graphics.line(80, 50, x, y)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
m.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||
local i = inventory.selected_item
|
||||
|
||||
if i and i.name == "Flask" then
|
||||
inventory:use()
|
||||
local seed = seed:from{ colour = i.colour }
|
||||
self.grown = true
|
||||
seed:install(self.room, self.width + 80, self.height + 50)
|
||||
end
|
||||
end)
|
||||
|
||||
return m
|
||||
|
|
24
obj/trashcan.lua
Normal file
24
obj/trashcan.lua
Normal file
|
@ -0,0 +1,24 @@
|
|||
local util = require("util")
|
||||
local window = require("window")
|
||||
local entity = require("entity")
|
||||
|
||||
local m = entity:from{
|
||||
width = 50,
|
||||
height = 50,
|
||||
lines = {'fill', {0, 0, 50, 0, 40, 50, 10, 50}},
|
||||
items = {},
|
||||
}
|
||||
|
||||
m.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||
local i = inventory.selected_item
|
||||
if i then
|
||||
util.add_entity(self.items, i)
|
||||
inventory:use()
|
||||
elseif #self.items > 0 then
|
||||
local last = self.items[#self.items]
|
||||
util.del_entity(self.items, last)
|
||||
inventory:pickup(last)
|
||||
end
|
||||
end)
|
||||
|
||||
return m
|
4
room.lua
4
room.lua
|
@ -28,7 +28,7 @@ end
|
|||
|
||||
room.mousepressed = window.propagate{'edges', 'objects'}
|
||||
|
||||
function room:draw()
|
||||
room.draw = window.draw(function (self)
|
||||
self:draw_lines(self.lines)
|
||||
|
||||
for i, v in ipairs(self.objects) do
|
||||
|
@ -38,7 +38,7 @@ function room:draw()
|
|||
for i, v in ipairs(self.edges) do
|
||||
v:draw()
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
function room:insert(obj)
|
||||
util.add_entity(self.objects, obj)
|
||||
|
|
|
@ -2,17 +2,22 @@ local window = require("window")
|
|||
local room = require("room")
|
||||
local edge = require("edge")
|
||||
local plant = require("obj/plant")
|
||||
local trashcan = require("obj/trashcan")
|
||||
|
||||
local m = room:from{
|
||||
}
|
||||
|
||||
local p = plant:from{
|
||||
colour = Seed_colour,
|
||||
room = m,
|
||||
}
|
||||
|
||||
p:install(m, 50, 40)
|
||||
p:install(m, 40, 80)
|
||||
|
||||
trashcan:new():install(m, 180, 140)
|
||||
|
||||
edge.set(m, 'left', "vivarium_table")
|
||||
edge.set(m, 'right', "vivarium_lock")
|
||||
edge.set(m, 'down', "Sundial Alley")
|
||||
edge.set(m, 'down', "Sundial alley")
|
||||
|
||||
return m
|
||||
|
|
|
@ -1,10 +1,145 @@
|
|||
local util = require("util")
|
||||
local window = require("window")
|
||||
local entity = require("entity")
|
||||
local room = require("room")
|
||||
local edge = require("edge")
|
||||
local button = require("button")
|
||||
local flask = require("item/flask")
|
||||
|
||||
local m = room:from{
|
||||
local function getColor(c)
|
||||
local t = {
|
||||
Red = { 1, 0, 0 },
|
||||
Green = { 0, 1, 0 },
|
||||
Blue = { 0, 0, 1 },
|
||||
}
|
||||
|
||||
if type(c) == "string" then
|
||||
return t[c]
|
||||
else
|
||||
return c
|
||||
end
|
||||
end
|
||||
|
||||
local mixer = entity:from{
|
||||
width = 130,
|
||||
height = 110,
|
||||
con_width = 60,
|
||||
con_height = 100,
|
||||
colours = {},
|
||||
timer = 0,
|
||||
anim = 0,
|
||||
}
|
||||
|
||||
function mixer:empty()
|
||||
self.colours = {}
|
||||
self.anim = 0
|
||||
end
|
||||
|
||||
local mempty = button.new("Empty", function ()
|
||||
mixer:empty()
|
||||
end,
|
||||
75, 5, 50, 45)
|
||||
|
||||
local mmix = button.new("Mix", function ()
|
||||
local len = #mixer.colours
|
||||
local c = {0, 0, 0}
|
||||
|
||||
for k, v in ipairs(mixer.colours) do
|
||||
local v = getColor(v)
|
||||
for i = 1, 3 do
|
||||
c[i] = c[i] + v[i]
|
||||
end
|
||||
end
|
||||
|
||||
for i = 1, 3 do
|
||||
c[i] = c[i] / len
|
||||
end
|
||||
|
||||
mixer.colours = {}
|
||||
for i = 1, len do
|
||||
mixer.colours[i] = c
|
||||
end
|
||||
end,
|
||||
75, 60, 50, 45)
|
||||
|
||||
mixer.draw = window.draw(function (self)
|
||||
local y = self.con_height + 5
|
||||
for i, v in ipairs(self.colours) do
|
||||
love.graphics.setColor(getColor(v))
|
||||
local h = 5
|
||||
if i == #self.colours then
|
||||
h = h * self.anim
|
||||
end
|
||||
y = y - h
|
||||
|
||||
love.graphics.rectangle('fill', 5, y, self.con_width, h)
|
||||
end
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
|
||||
mempty:draw()
|
||||
mmix:draw()
|
||||
|
||||
love.graphics.rectangle('line', 5, 5, self.con_width, self.con_height)
|
||||
|
||||
love.graphics.rectangle('line', 0, 0, self.width, self.height)
|
||||
end)
|
||||
|
||||
mixer.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||
if util.inside(x, y, 5, 5, self.con_width, self.con_height) and #self.colours > 0 then
|
||||
local f = flask:from{ colour = getColor(self.colours[1]) }
|
||||
f:itemMode()
|
||||
inventory:pickup(f)
|
||||
self:empty()
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
window.iterate({mempty, mmix}, x, y, button)
|
||||
end)
|
||||
|
||||
mixer.update = function (self, dt)
|
||||
self.timer = self.timer + dt
|
||||
if self.timer > 1/20 then
|
||||
self.timer = self.timer - 1/20
|
||||
self.anim = self.anim + 1/20
|
||||
if self.anim > 1 then
|
||||
self.anim = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function mixer:add(colour)
|
||||
table.insert(self.colours, colour)
|
||||
self.anim = 0
|
||||
end
|
||||
|
||||
local vial = entity:from {
|
||||
width = 20,
|
||||
height = 60,
|
||||
colour = ""
|
||||
}
|
||||
|
||||
vial.draw = window.draw(function (self)
|
||||
love.graphics.setColor(getColor(self.colour))
|
||||
love.graphics.rectangle('fill', 0, 0, 20, 50)
|
||||
love.graphics.arc('fill', 'open', 10, 50, 10, 0, math.pi)
|
||||
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
love.graphics.line(0, 50, 0, 0, 20, 0, 20, 50)
|
||||
love.graphics.arc('line', 'open', 10, 50, 10, 0, math.pi)
|
||||
end)
|
||||
|
||||
vial.mousepressed = window.mousepressed(function (self, x, y, button)
|
||||
mixer:add(self.colour)
|
||||
end)
|
||||
|
||||
local m = room:new()
|
||||
|
||||
mixer:install(m, 160, 40)
|
||||
vial:from{ colour = "Red" }:install(m, 20, 40)
|
||||
vial:from{ colour = "Green" }:install(m, 60, 40)
|
||||
vial:from{ colour = "Blue" }:install(m, 100, 40)
|
||||
|
||||
edge.set(m, 'down', "Vivarium")
|
||||
|
||||
m.draw = window.draw(function (self)
|
||||
|
@ -13,7 +148,15 @@ m.draw = window.draw(function (self)
|
|||
love.graphics.rectangle('line', 10, 200, 20, 40)
|
||||
love.graphics.rectangle('line', 290, 200, 20, 40)
|
||||
|
||||
for i, v in ipairs(self.objects) do
|
||||
v:draw()
|
||||
end
|
||||
|
||||
self.edges[1]:draw()
|
||||
end)
|
||||
|
||||
m.update = function (self, dt)
|
||||
mixer:update(dt)
|
||||
end
|
||||
|
||||
return m
|
||||
|
|
|
@ -28,7 +28,7 @@ end
|
|||
function w.iterate(t, x, y, button)
|
||||
for i, v in util.ipairs_rev(t) do
|
||||
if v:mousepressed(x, y, button) then
|
||||
return
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue