more button functionality

This commit is contained in:
jill 2021-01-23 17:22:14 +03:00
parent 0f0d092339
commit 737ae2efe0
Signed by: oat
GPG key ID: DD83A9617A252385
2 changed files with 70 additions and 47 deletions

View file

@ -52,7 +52,7 @@ function self.food(x, y, type)
speed = 0.2,
time = math.random(),
deathtimer = 0,
type = 1
type = type
}
return food

View file

@ -17,6 +17,9 @@ debug = false
food = {}
feesh = {}
foodtier = 1
foodcount = 1
footerbuttons = {
{
cost = 100,
@ -30,21 +33,33 @@ footerbuttons = {
{
cost = 200,
sprite = 'food',
tier = 1,
tier = foodtier,
openanim = 1,
open = true,
func = function()
--table.insert(feesh, constr.fish(math.random(), 0.3))
func = function(self)
self.openanim = 0
foodtier = foodtier + 1
if foodtier >= 3 then
self.open = false
else
self.tier = foodtier
end
end
},
{
cost = 300,
sprite = 'foodcount',
tier = 3,
tier = foodcount,
openanim = 1,
open = true,
func = function()
--table.insert(feesh, constr.fish(math.random(), 0.3))
func = function(self)
self.openanim = 0
foodcount = foodcount + 1
if foodcount >= 9 then
self.open = false
else
self.tier = foodcount
end
end
}
}
@ -105,6 +120,12 @@ function love.update(dt)
bench.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')
for i,f in ipairs(food) do
f.y = f.y + dt * f.speed
@ -504,7 +525,7 @@ function love.draw()
bench.startBenchmark('render_food')
for _,f in ipairs(food) do
local sheet = sheets.food1
local sheet = sheets['food' .. (f.type)]
local x = f.x * sw
local y = f.y * sh
local frame = math.floor((f.time%1) * #sheet.quads) + 1
@ -539,7 +560,8 @@ function love.draw()
love.graphics.draw(sprites['footer/buttonbg'], x * size, y * size, 0, size, size)
end
if btn and btn.open then
if btn then
if btn.open then
-- sprite inside
if btn.sprite == 'guppy' then
local sheet = fishsprite('medium', false, 'swim')
@ -580,9 +602,10 @@ function love.draw()
love.graphics.setBlendMode('add')
love.graphics.draw(sprites['footer/reflection'], x * size, y * size, 0, size, size)
love.graphics.setBlendMode('alpha')
end
-- open/close anim
if (btn and not btn.openanim == 1) then
if (btn and btn.openanim < 1) then
local sheet = sheets.buttonopen
local anim = 0
if btn then anim = btn.openanim end
@ -606,8 +629,8 @@ function love.draw()
end
function love.mousepressed(x, y, b)
if b == 2 then
table.insert(food, constr.food(x/love.graphics.getWidth(), y/love.graphics.getHeight(), 1))
if b == 1 and y > FOOTER_HEIGHT and #food < foodcount then
table.insert(food, constr.food(x/love.graphics.getWidth(), y/love.graphics.getHeight(), foodtier))
end
end
@ -622,7 +645,7 @@ function love.mousereleased(x, y, b)
if hovered then
if footerbuttons[i] and footerbuttons[i].open then
footerbuttons[i].func()
footerbuttons[i].func(footerbuttons[i])
end
end