This commit is contained in:
jill 2021-01-23 22:42:56 +03:00
parent f61d3383d4
commit 74bf2a7045
Signed by: oat
GPG key ID: DD83A9617A252385
10 changed files with 118 additions and 18 deletions

BIN
assets/audio/sfx/buzzer.ogg Executable file

Binary file not shown.

BIN
assets/audio/sfx/collect.ogg Executable file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

View file

@ -8,6 +8,7 @@ function self.fish(x, y)
y = y,
size = 0, -- 0 for small, 1 for medium, 2 for big, 3 for king
eattimer = 0 + math.random() * 2, -- starts out hungry, with a 2s delay
moneytimer = 10 + math.random() * 5, -- min 10s before it can make money
dead = false,
lifetime = 0,
@ -58,4 +59,19 @@ function self.food(x, y, type)
return food
end
function self.money(x, y, type)
local money = {
x = x,
y = y,
speed = 0.2,
time = math.random(),
deathtimer = 0,
collected = false,
collecttimer = 0,
type = type
}
return money
end
return self

120
main.lua
View file

@ -18,6 +18,9 @@ debug = false
food = {}
feesh = {}
money = {}
local balance = 100
foodtier = 1
foodcount = 1
@ -107,7 +110,10 @@ function love.load()
sheets.buttonopen = newAnimation(sprites['footer/button_open'], sprites['footer/button_open']:getWidth()/3, sprites['footer/button_open']:getHeight())
for i = 1, 3 do
sheets.money1 = newAnimation(sprites['money/coin1'], sprites['money/coin1']:getWidth()/10, sprites['money/coin1']:getHeight())
sheets.money2 = newAnimation(sprites['money/coin2'], sprites['money/coin2']:getWidth()/10, sprites['money/coin2']:getHeight())
for i = 1, 2 do
table.insert(feesh, constr.fish(math.random(), math.random()))
end
@ -146,6 +152,27 @@ function love.update(dt)
end
bench.stopBenchmark('update_food')
bench.startBenchmark('update_money')
for i,f in ipairs(money) do
if not f.collected then
f.y = f.y + dt * f.speed
f.y = clamp(f.y, 0, 0.9)
end
f.time = f.time + dt
if f.y == 0.9 and not f.collected then
f.deathtimer = f.deathtimer + dt
end
if f.collected then
f.collecttimer = f.collecttimer + dt
end
if f.deathtimer > 1 or f.collecttimer > 1 then
table.remove(money, i)
end
end
bench.stopBenchmark('update_money')
bench.startBenchmark('update_fish')
for fi, n in ipairs(feesh) do
bench.startBenchmark('update_fish_eases')
@ -241,6 +268,17 @@ function love.update(dt)
n.lifetime = n.lifetime + dt
n.eattimer = n.eattimer - dt
n.moneytimer = n.moneytimer - dt
if n.moneytimer < 0 and not n.dead then
n.moneytimer = n.moneytimer + math.random() * 5 + 5
if n.size > 0 then
local type = 2
if n.size == 1 then type = 1 end
table.insert(money, constr.money(n.render.x, n.render.y, type))
end
end
local sumx = 0
local sumy = 0
@ -401,6 +439,19 @@ function love.draw()
love.graphics.setBlendMode('alpha')
bench.stopBenchmark('render_wave')
bench.startBenchmark('render_food')
for _,f in ipairs(food) do
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
love.graphics.setColor(1, 1, 1, 1 - f.deathtimer)
love.graphics.draw(sheet.spriteSheet, sheet.quads[math.max(math.min(frame, #sheet.quads), 1)], x, y, 0, spritescale, spritescale, sheet.width/2, sheet.height/2)
end
bench.stopBenchmark('render_food')
-- shadow
bench.startBenchmark('render_shadow')
for i, n in ipairs(feesh) do
@ -534,19 +585,6 @@ function love.draw()
end
end
bench.stopBenchmark('render_fish')
bench.startBenchmark('render_food')
for _,f in ipairs(food) do
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
love.graphics.setColor(1, 1, 1, 1 - f.deathtimer)
love.graphics.draw(sheet.spriteSheet, sheet.quads[math.max(math.min(frame, #sheet.quads), 1)], x, y, 0, spritescale, spritescale, sheet.width/2, sheet.height/2)
end
bench.stopBenchmark('render_food')
bench.stopBenchmark('render_tank')
bench.startBenchmark('render_footer')
@ -631,8 +669,28 @@ function love.draw()
if b >= 3 then incr = 73 end
x = x + incr
end
-- money count
love.graphics.setFont(fonts.continuum)
love.graphics.setColor(179/255, 254/255, 89/255)
local leftpad = 100
love.graphics.printf(balance, round(sw * 0.965 - leftpad), round(FOOTER_HEIGHT - 25), leftpad, 'right')
love.graphics.setFont(fonts.default)
bench.stopBenchmark('render_footer')
bench.startBenchmark('render_money')
for _,f in ipairs(money) do
local sheet = sheets['money' .. (f.type)]
local x = mix(f.x * sw, sw / 9 * 8, ease.outCubic(f.collecttimer))
local y = mix(f.y * sh, FOOTER_HEIGHT - 20, ease.outCubic(f.collecttimer))
local frame = math.floor((f.time%1) * #sheet.quads) + 1
love.graphics.setColor(1, 1, 1, 1 - f.deathtimer)
love.graphics.draw(sheet.spriteSheet, sheet.quads[math.max(math.min(frame, #sheet.quads), 1)], x, y, 0, spritescale, spritescale, sheet.width/2, sheet.height/2)
end
bench.stopBenchmark('render_money')
love.graphics.setColor(1, 1, 1, 1)
love.graphics.print('FPS: ' .. 1 / love.timer.getDelta(), 0, sh - 16)
@ -641,9 +699,30 @@ function love.draw()
end
function love.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 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
return
end
end
end
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))
playSound('dropfood')
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 footerheight = FOOTER_HEIGHT * love.graphics.getWidth()/640
@ -656,8 +735,13 @@ function love.mousepressed(x, y, b)
if hovered then
if footerbuttons[i] and footerbuttons[i].open then
footerbuttons[i].func(footerbuttons[i])
playSound('buttonclick')
if balance >= footerbuttons[i].cost then
footerbuttons[i].func(footerbuttons[i])
playSound('buttonclick')
balance = balance - footerbuttons[i].cost
else
playSound('buzzer')
end
end
end