more button functionality
This commit is contained in:
parent
0f0d092339
commit
737ae2efe0
2 changed files with 70 additions and 47 deletions
|
@ -52,7 +52,7 @@ function self.food(x, y, type)
|
||||||
speed = 0.2,
|
speed = 0.2,
|
||||||
time = math.random(),
|
time = math.random(),
|
||||||
deathtimer = 0,
|
deathtimer = 0,
|
||||||
type = 1
|
type = type
|
||||||
}
|
}
|
||||||
|
|
||||||
return food
|
return food
|
||||||
|
|
115
main.lua
115
main.lua
|
@ -17,6 +17,9 @@ debug = false
|
||||||
food = {}
|
food = {}
|
||||||
feesh = {}
|
feesh = {}
|
||||||
|
|
||||||
|
foodtier = 1
|
||||||
|
foodcount = 1
|
||||||
|
|
||||||
footerbuttons = {
|
footerbuttons = {
|
||||||
{
|
{
|
||||||
cost = 100,
|
cost = 100,
|
||||||
|
@ -30,21 +33,33 @@ footerbuttons = {
|
||||||
{
|
{
|
||||||
cost = 200,
|
cost = 200,
|
||||||
sprite = 'food',
|
sprite = 'food',
|
||||||
tier = 1,
|
tier = foodtier,
|
||||||
openanim = 1,
|
openanim = 1,
|
||||||
open = true,
|
open = true,
|
||||||
func = function()
|
func = function(self)
|
||||||
--table.insert(feesh, constr.fish(math.random(), 0.3))
|
self.openanim = 0
|
||||||
|
foodtier = foodtier + 1
|
||||||
|
if foodtier >= 3 then
|
||||||
|
self.open = false
|
||||||
|
else
|
||||||
|
self.tier = foodtier
|
||||||
|
end
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
cost = 300,
|
cost = 300,
|
||||||
sprite = 'foodcount',
|
sprite = 'foodcount',
|
||||||
tier = 3,
|
tier = foodcount,
|
||||||
openanim = 1,
|
openanim = 1,
|
||||||
open = true,
|
open = true,
|
||||||
func = function()
|
func = function(self)
|
||||||
--table.insert(feesh, constr.fish(math.random(), 0.3))
|
self.openanim = 0
|
||||||
|
foodcount = foodcount + 1
|
||||||
|
if foodcount >= 9 then
|
||||||
|
self.open = false
|
||||||
|
else
|
||||||
|
self.tier = foodcount
|
||||||
|
end
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,6 +120,12 @@ function love.update(dt)
|
||||||
bench.update()
|
bench.update()
|
||||||
|
|
||||||
bench.startBenchmark('update')
|
bench.startBenchmark('update')
|
||||||
|
bench.startBenchmark('update_buttons')
|
||||||
|
for _,btn in ipairs(footerbuttons) do
|
||||||
|
btn.openanim = btn.openanim + dt * 6
|
||||||
|
end
|
||||||
|
bench.stopBenchmark('update_buttons')
|
||||||
|
|
||||||
bench.startBenchmark('update_food')
|
bench.startBenchmark('update_food')
|
||||||
for i,f in ipairs(food) do
|
for i,f in ipairs(food) do
|
||||||
f.y = f.y + dt * f.speed
|
f.y = f.y + dt * f.speed
|
||||||
|
@ -504,7 +525,7 @@ function love.draw()
|
||||||
|
|
||||||
bench.startBenchmark('render_food')
|
bench.startBenchmark('render_food')
|
||||||
for _,f in ipairs(food) do
|
for _,f in ipairs(food) do
|
||||||
local sheet = sheets.food1
|
local sheet = sheets['food' .. (f.type)]
|
||||||
local x = f.x * sw
|
local x = f.x * sw
|
||||||
local y = f.y * sh
|
local y = f.y * sh
|
||||||
local frame = math.floor((f.time%1) * #sheet.quads) + 1
|
local frame = math.floor((f.time%1) * #sheet.quads) + 1
|
||||||
|
@ -539,50 +560,52 @@ function love.draw()
|
||||||
love.graphics.draw(sprites['footer/buttonbg'], x * size, y * size, 0, size, size)
|
love.graphics.draw(sprites['footer/buttonbg'], x * size, y * size, 0, size, size)
|
||||||
end
|
end
|
||||||
|
|
||||||
if btn and btn.open then
|
if btn then
|
||||||
-- sprite inside
|
if btn.open then
|
||||||
if btn.sprite == 'guppy' then
|
-- sprite inside
|
||||||
local sheet = fishsprite('medium', false, 'swim')
|
if btn.sprite == 'guppy' then
|
||||||
local frame = math.floor((love.timer.getTime() * 2) % 1 * #sheet.quads) + 1
|
local sheet = fishsprite('medium', false, 'swim')
|
||||||
local scale = (sprites['footer/buttonbg']:getWidth() / sheet.width) * 0.9
|
local frame = math.floor((love.timer.getTime() * 2) % 1 * #sheet.quads) + 1
|
||||||
local offset = (sprites['footer/buttonbg']:getWidth() * size) / 2
|
local scale = (sprites['footer/buttonbg']:getWidth() / sheet.width) * 0.9
|
||||||
love.graphics.draw(sheet.spriteSheet, sheet.quads[frame], x * size + offset, y * size + offset*0.75, 0, size * scale, size * scale, sheet.width/2, sheet.width/2)
|
local offset = (sprites['footer/buttonbg']:getWidth() * size) / 2
|
||||||
elseif btn.sprite == 'food' then
|
love.graphics.draw(sheet.spriteSheet, sheet.quads[frame], x * size + offset, y * size + offset*0.75, 0, size * scale, size * scale, sheet.width/2, sheet.width/2)
|
||||||
local sheets = {sheets.food2, sheets.food3}
|
elseif btn.sprite == 'food' then
|
||||||
local sheet = sheets[btn.tier]
|
local sheets = {sheets.food2, sheets.food3}
|
||||||
|
local sheet = sheets[btn.tier]
|
||||||
|
|
||||||
local scale = (sprites['footer/buttonbg']:getWidth() / sheet.width) * 0.65
|
local scale = (sprites['footer/buttonbg']:getWidth() / sheet.width) * 0.65
|
||||||
local offset = (sprites['footer/buttonbg']:getWidth() * size) / 2
|
local offset = (sprites['footer/buttonbg']:getWidth() * size) / 2
|
||||||
love.graphics.draw(sheet.spriteSheet, sheet.quads[1], x * size + offset, y * size + offset*0.75, 0, size * scale, size * scale, sheet.width/2, sheet.width/2)
|
love.graphics.draw(sheet.spriteSheet, sheet.quads[1], x * size + offset, y * size + offset*0.75, 0, size * scale, size * scale, sheet.width/2, sheet.width/2)
|
||||||
elseif btn.sprite == 'foodcount' then
|
elseif btn.sprite == 'foodcount' then
|
||||||
love.graphics.setFont(fonts.continuum)
|
love.graphics.setFont(fonts.continuum)
|
||||||
local offset = (sprites['footer/buttonbg']:getWidth() * size) / 2
|
local offset = (sprites['footer/buttonbg']:getWidth() * size) / 2
|
||||||
|
|
||||||
local bordersize = 1
|
local bordersize = 1
|
||||||
for _,p in ipairs({{0, 1}, {1, 0}, {1, 1}, {-1, 0}, {0, -1}, {-1, -1}, {1, -1}, {-1, 1}}) do
|
for _,p in ipairs({{0, 1}, {1, 0}, {1, 1}, {-1, 0}, {0, -1}, {-1, -1}, {1, -1}, {-1, 1}}) do
|
||||||
love.graphics.setColor(0, 0, 0, 0.5)
|
love.graphics.setColor(0, 0, 0, 0.5)
|
||||||
love.graphics.printf(btn.tier + 1, round(x * size) + p[1] * bordersize, round(y * size + offset*0.75 - fonts.continuum:getHeight()/2) + p[2] * bordersize, round(sprites['footer/buttonbg']:getWidth() * size), 'center')
|
love.graphics.printf(btn.tier + 1, round(x * size) + p[1] * bordersize, round(y * size + offset*0.75 - fonts.continuum:getHeight()/2) + p[2] * bordersize, round(sprites['footer/buttonbg']:getWidth() * size), 'center')
|
||||||
|
end
|
||||||
|
|
||||||
|
love.graphics.setColor(0, 1, 0)
|
||||||
|
love.graphics.printf(btn.tier + 1, round(x * size), round(y * size + offset*0.75 - fonts.continuum:getHeight()/2), round(sprites['footer/buttonbg']:getWidth() * size), 'center')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- price
|
||||||
|
love.graphics.setFont(fonts.pix)
|
||||||
|
local font = love.graphics.getFont()
|
||||||
love.graphics.setColor(0, 1, 0)
|
love.graphics.setColor(0, 1, 0)
|
||||||
love.graphics.printf(btn.tier + 1, round(x * size), round(y * size + offset*0.75 - fonts.continuum:getHeight()/2), round(sprites['footer/buttonbg']:getWidth() * size), 'center')
|
love.graphics.printf('$' .. btn.cost, round(x * size), round(y * size + 51 * size - font:getHeight()/2), round(sprites['footer/buttonbg']:getWidth() * size), 'center')
|
||||||
|
love.graphics.setColor(1, 1, 1)
|
||||||
|
love.graphics.setFont(fonts.default)
|
||||||
|
|
||||||
|
-- reflection
|
||||||
|
love.graphics.setBlendMode('add')
|
||||||
|
love.graphics.draw(sprites['footer/reflection'], x * size, y * size, 0, size, size)
|
||||||
|
love.graphics.setBlendMode('alpha')
|
||||||
end
|
end
|
||||||
|
|
||||||
-- price
|
|
||||||
love.graphics.setFont(fonts.pix)
|
|
||||||
local font = love.graphics.getFont()
|
|
||||||
love.graphics.setColor(0, 1, 0)
|
|
||||||
love.graphics.printf('$' .. btn.cost, round(x * size), round(y * size + 51 * size - font:getHeight()/2), round(sprites['footer/buttonbg']:getWidth() * size), 'center')
|
|
||||||
love.graphics.setColor(1, 1, 1)
|
|
||||||
love.graphics.setFont(fonts.default)
|
|
||||||
|
|
||||||
-- reflection
|
|
||||||
love.graphics.setBlendMode('add')
|
|
||||||
love.graphics.draw(sprites['footer/reflection'], x * size, y * size, 0, size, size)
|
|
||||||
love.graphics.setBlendMode('alpha')
|
|
||||||
|
|
||||||
-- open/close anim
|
-- open/close anim
|
||||||
if (btn and not btn.openanim == 1) then
|
if (btn and btn.openanim < 1) then
|
||||||
local sheet = sheets.buttonopen
|
local sheet = sheets.buttonopen
|
||||||
local anim = 0
|
local anim = 0
|
||||||
if btn then anim = btn.openanim end
|
if btn then anim = btn.openanim end
|
||||||
|
@ -606,8 +629,8 @@ function love.draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.mousepressed(x, y, b)
|
function love.mousepressed(x, y, b)
|
||||||
if b == 2 then
|
if b == 1 and y > FOOTER_HEIGHT and #food < foodcount then
|
||||||
table.insert(food, constr.food(x/love.graphics.getWidth(), y/love.graphics.getHeight(), 1))
|
table.insert(food, constr.food(x/love.graphics.getWidth(), y/love.graphics.getHeight(), foodtier))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -622,7 +645,7 @@ function love.mousereleased(x, y, b)
|
||||||
|
|
||||||
if hovered then
|
if hovered then
|
||||||
if footerbuttons[i] and footerbuttons[i].open then
|
if footerbuttons[i] and footerbuttons[i].open then
|
||||||
footerbuttons[i].func()
|
footerbuttons[i].func(footerbuttons[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue