2021-01-23 23:30:01 +00:00
|
|
|
local self = {}
|
|
|
|
|
|
|
|
local sheets = {}
|
|
|
|
|
|
|
|
local food = {}
|
|
|
|
local feesh = {}
|
|
|
|
local money = {}
|
|
|
|
|
|
|
|
local balance = 100
|
|
|
|
|
|
|
|
local foodtier = 1
|
|
|
|
local foodcount = 1
|
|
|
|
|
|
|
|
local headerbuttons = {
|
|
|
|
{
|
|
|
|
cost = 100,
|
|
|
|
sprite = 'guppy',
|
|
|
|
openanim = 1,
|
2021-01-25 14:48:31 +00:00
|
|
|
open = false,
|
2021-01-23 23:30:01 +00:00
|
|
|
closed = false,
|
|
|
|
func = function()
|
|
|
|
playSound('splash', 0.7, 0.8)
|
|
|
|
table.insert(feesh, constr.fish(math.random(), 0.3))
|
|
|
|
end
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cost = 200,
|
|
|
|
sprite = 'food',
|
|
|
|
tier = foodtier,
|
|
|
|
openanim = 1,
|
2021-01-25 14:48:31 +00:00
|
|
|
open = false,
|
2021-01-23 23:30:01 +00:00
|
|
|
closed = false,
|
|
|
|
func = function(self)
|
|
|
|
self.openanim = 0
|
|
|
|
foodtier = foodtier + 1
|
|
|
|
if foodtier >= 3 then
|
|
|
|
self.open = false
|
2021-01-24 17:46:52 +00:00
|
|
|
self.closed = true
|
2021-01-23 23:30:01 +00:00
|
|
|
else
|
|
|
|
self.tier = foodtier
|
|
|
|
end
|
|
|
|
end
|
|
|
|
},
|
|
|
|
{
|
|
|
|
cost = 300,
|
|
|
|
sprite = 'foodcount',
|
|
|
|
tier = foodcount,
|
|
|
|
openanim = 1,
|
2021-01-25 14:48:31 +00:00
|
|
|
open = false,
|
2021-01-23 23:30:01 +00:00
|
|
|
closed = false,
|
|
|
|
func = function(self)
|
|
|
|
self.openanim = 0
|
|
|
|
foodcount = foodcount + 1
|
|
|
|
if foodcount >= 9 then
|
|
|
|
self.open = false
|
2021-01-24 17:46:52 +00:00
|
|
|
self.closed = true
|
2021-01-23 23:30:01 +00:00
|
|
|
else
|
|
|
|
self.tier = foodcount
|
|
|
|
end
|
|
|
|
end
|
2021-01-25 14:48:31 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
cost = 1000,
|
|
|
|
sprite = 'carnivore',
|
|
|
|
openanim = 1,
|
|
|
|
open = false,
|
|
|
|
closed = false,
|
|
|
|
func = function()
|
|
|
|
playSound('splash', 0.7, 0.8)
|
|
|
|
table.insert(feesh, constr.fish(math.random(), 0.3, 4))
|
|
|
|
end
|
2021-01-23 23:30:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
local sheets = {}
|
|
|
|
|
|
|
|
local function fishsprite(size, hungry, anim)
|
|
|
|
-- anim is turn, swim, eat or die
|
|
|
|
if anim == 'die' then hungry = false end
|
|
|
|
|
|
|
|
local spritename = size .. '_' .. (hungry and 'hungry_' or '') .. anim
|
|
|
|
local spr = sprites['fish/' .. spritename]
|
|
|
|
return newAnimation(spr, spr:getWidth()/10, spr:getHeight())
|
|
|
|
end
|
|
|
|
|
|
|
|
function self.load()
|
|
|
|
sheets.wavecenter = newAnimation(sprites['wave/wavecenter'], sprites['wave/wavecenter']:getWidth(), sprites['wave/wavecenter']:getHeight()/12)
|
|
|
|
sheets.waveside = newAnimation(sprites['wave/waveside'], sprites['wave/waveside']:getWidth(), sprites['wave/waveside']:getHeight()/12)
|
|
|
|
|
|
|
|
sheets.food1 = newAnimation(sprites['food/1'], sprites['food/1']:getWidth()/10, sprites['food/1']:getHeight())
|
|
|
|
sheets.food2 = newAnimation(sprites['food/2'], sprites['food/2']:getWidth()/10, sprites['food/2']:getHeight())
|
|
|
|
sheets.food3 = newAnimation(sprites['food/3'], sprites['food/3']:getWidth()/10, sprites['food/3']:getHeight())
|
|
|
|
|
|
|
|
sheets.buttonopen = newAnimation(sprites['header/button_open'], sprites['header/button_open']:getWidth()/3, sprites['header/button_open']:getHeight())
|
|
|
|
|
2021-01-25 14:48:31 +00:00
|
|
|
sheets.coin1 = newAnimation(sprites['money/coin1'], sprites['money/coin1']:getWidth()/10, sprites['money/coin1']:getHeight())
|
|
|
|
sheets.coin2 = newAnimation(sprites['money/coin2'], sprites['money/coin2']:getWidth()/10, sprites['money/coin2']:getHeight())
|
|
|
|
sheets.star = newAnimation(sprites['money/star'], sprites['money/star']:getWidth()/10, sprites['money/star']:getHeight())
|
|
|
|
sheets.diamond = newAnimation(sprites['money/diamond'], sprites['money/diamond']:getWidth()/10, sprites['money/diamond']:getHeight())
|
|
|
|
sheets.chest = newAnimation(sprites['money/chest'], sprites['money/chest']:getWidth()/10, sprites['money/chest']:getHeight())
|
2021-01-23 23:30:01 +00:00
|
|
|
|
|
|
|
for i = 1, 2 do
|
2021-01-25 14:48:31 +00:00
|
|
|
table.insert(feesh, constr.fish(math.random(), math.random(), 0))
|
2021-01-23 23:30:01 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function self.update(dt)
|
|
|
|
bench.startBenchmark('update_buttons')
|
|
|
|
for _,btn in ipairs(headerbuttons) do
|
|
|
|
btn.openanim = btn.openanim + dt * 6
|
|
|
|
end
|
|
|
|
bench.stopBenchmark('update_buttons')
|
|
|
|
|
|
|
|
bench.startBenchmark('update_food')
|
|
|
|
require('scenes.gameplay.update.food')(food, dt)
|
|
|
|
bench.stopBenchmark('update_food')
|
|
|
|
|
|
|
|
bench.startBenchmark('update_money')
|
|
|
|
require('scenes.gameplay.update.money')(money, dt)
|
|
|
|
bench.stopBenchmark('update_money')
|
|
|
|
|
|
|
|
bench.startBenchmark('update_fish')
|
2021-01-24 17:46:52 +00:00
|
|
|
require('scenes.gameplay.update.fish')(feesh, dt, food, headerbuttons, money)
|
2021-01-23 23:30:01 +00:00
|
|
|
bench.stopBenchmark('update_fish')
|
2021-01-25 14:48:31 +00:00
|
|
|
|
|
|
|
if debug then
|
|
|
|
for _,b in ipairs(headerbuttons) do
|
|
|
|
b.open = true
|
|
|
|
end
|
|
|
|
end
|
2021-01-23 23:30:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function self.draw()
|
|
|
|
bench.startBenchmark('render_tank')
|
|
|
|
|
|
|
|
local sw, sh = love.graphics.getDimensions()
|
|
|
|
local headerheight = HEADER_HEIGHT * sw/640
|
|
|
|
local yscale = (sh-headerheight)/sh
|
|
|
|
|
|
|
|
local sample = fishsprite('medium', false, 'swim')
|
|
|
|
local spritescale = (math.min(sw, sh)/FISH_SIZE) / math.min(sample.width, sample.height)
|
|
|
|
|
|
|
|
stretchto(sprites['bg/1'], 0, headerheight - HEADER_HEIGHT, 0, sw, sh - (headerheight - HEADER_HEIGHT))
|
|
|
|
|
|
|
|
-- waves
|
|
|
|
bench.startBenchmark('render_wave')
|
|
|
|
require('scenes.gameplay.draw.wave')(headerheight, sheets)
|
|
|
|
bench.stopBenchmark('render_wave')
|
|
|
|
|
|
|
|
-- shadow
|
|
|
|
bench.startBenchmark('render_shadow')
|
|
|
|
require('scenes.gameplay.draw.shadow')(feesh, spritescale)
|
|
|
|
bench.stopBenchmark('render_shadow')
|
|
|
|
|
|
|
|
bench.startBenchmark('render_food')
|
|
|
|
require('scenes.gameplay.draw.food')(food, sheets, spritescale)
|
|
|
|
bench.stopBenchmark('render_food')
|
|
|
|
|
|
|
|
-- all the fish
|
|
|
|
bench.startBenchmark('render_fish')
|
|
|
|
require('scenes.gameplay.draw.fish')(feesh, spritescale, fishsprite)
|
|
|
|
bench.stopBenchmark('render_fish')
|
|
|
|
bench.stopBenchmark('render_tank')
|
|
|
|
|
|
|
|
bench.startBenchmark('render_header')
|
|
|
|
require('scenes.gameplay.draw.header')(headerheight, fishsprite, headerbuttons, sheets, balance)
|
|
|
|
bench.stopBenchmark('render_header')
|
|
|
|
|
|
|
|
bench.startBenchmark('render_money')
|
|
|
|
require('scenes.gameplay.draw.money')(money, sheets, spritescale)
|
|
|
|
bench.stopBenchmark('render_money')
|
|
|
|
end
|
|
|
|
|
|
|
|
function self.mousepressed(x, y, b)
|
|
|
|
if b == 1 then
|
|
|
|
for _,m in ipairs(money) do
|
|
|
|
local dist = math.abs(x/love.graphics.getWidth() - m.x) + math.abs(y/love.graphics.getHeight() - m.y)
|
|
|
|
if dist < 0.1 and not m.collected then
|
|
|
|
m.collected = true
|
|
|
|
m.deathtimer = 0
|
|
|
|
playSound('collect', 1, 1 + math.random() * 0.2 - 0.1)
|
|
|
|
|
|
|
|
if m.type == 1 then balance = balance + 15 end
|
|
|
|
if m.type == 2 then balance = balance + 35 end
|
2021-01-25 14:48:31 +00:00
|
|
|
if m.type == 3 then balance = balance + 40 end
|
|
|
|
if m.type == 4 then balance = balance + 200 end
|
|
|
|
if m.type == 5 then balance = balance + 2000 end
|
2021-01-23 23:30:01 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if b == 1 and y > HEADER_HEIGHT and #food < foodcount then
|
|
|
|
if balance >= 5 then
|
|
|
|
table.insert(food, constr.food(x/love.graphics.getWidth(), y/love.graphics.getHeight(), foodtier))
|
|
|
|
playSound('dropfood')
|
|
|
|
balance = balance - 5
|
|
|
|
else
|
|
|
|
playSound('buzzer')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local headerheight = HEADER_HEIGHT * love.graphics.getWidth()/640
|
|
|
|
local size = headerheight / HEADER_HEIGHT
|
|
|
|
|
|
|
|
if b == 1 then
|
|
|
|
local x = 19
|
|
|
|
for i = 1, 7 do
|
|
|
|
local hovered = mouseOverBox(x * size, 3 * size, sprites['header/buttonbg']:getWidth() * size, sprites['header/buttonbg']:getHeight() * size)
|
|
|
|
|
|
|
|
if hovered then
|
|
|
|
if headerbuttons[i] and headerbuttons[i].open then
|
2021-01-25 14:48:31 +00:00
|
|
|
if balance >= headerbuttons[i].cost or debug then
|
2021-01-23 23:30:01 +00:00
|
|
|
headerbuttons[i].func(headerbuttons[i])
|
|
|
|
playSound('buttonclick')
|
|
|
|
balance = balance - headerbuttons[i].cost
|
|
|
|
else
|
|
|
|
playSound('buzzer')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local incr = 69 -- its like button positions but forcefully shoved into a recursive function :D
|
|
|
|
if b == 2 then incr = 57 end
|
|
|
|
if b >= 3 then incr = 73 end
|
|
|
|
x = x + incr
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return self
|