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
|
||||||
|
|
47
main.lua
47
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,7 +560,8 @@ 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
|
||||||
|
if btn.open then
|
||||||
-- sprite inside
|
-- sprite inside
|
||||||
if btn.sprite == 'guppy' then
|
if btn.sprite == 'guppy' then
|
||||||
local sheet = fishsprite('medium', false, 'swim')
|
local sheet = fishsprite('medium', false, 'swim')
|
||||||
|
@ -580,9 +602,10 @@ function love.draw()
|
||||||
love.graphics.setBlendMode('add')
|
love.graphics.setBlendMode('add')
|
||||||
love.graphics.draw(sprites['footer/reflection'], x * size, y * size, 0, size, size)
|
love.graphics.draw(sprites['footer/reflection'], x * size, y * size, 0, size, size)
|
||||||
love.graphics.setBlendMode('alpha')
|
love.graphics.setBlendMode('alpha')
|
||||||
|
end
|
||||||
|
|
||||||
-- 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