Compare commits
2 commits
6ecbf07dbf
...
0f0d092339
Author | SHA1 | Date | |
---|---|---|---|
|
0f0d092339 | ||
|
bcfd75c270 |
BIN
assets/fonts/cont.ttf
Normal file
BIN
assets/fonts/pix.ttf
Normal file
BIN
assets/sprites/footer/button_open.png
Normal file
After Width: | Height: | Size: 8.6 KiB |
Before Width: | Height: | Size: 4.2 KiB |
Before Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 411 B |
Before Width: | Height: | Size: 430 B |
Before Width: | Height: | Size: 434 B |
Before Width: | Height: | Size: 628 B |
Before Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 17 KiB |
|
@ -18,9 +18,9 @@ function self.fish(x, y)
|
|||
render = {
|
||||
x = 0,
|
||||
y = 0,
|
||||
prevx = 0,
|
||||
prevy = 0,
|
||||
turn = 0,
|
||||
prevx = math.random() - 0.5,
|
||||
prevy = math.random() - 0.5,
|
||||
turn = math.random(),
|
||||
swim = 0,
|
||||
angle = 0,
|
||||
xspeed = 0,
|
||||
|
|
142
main.lua
|
@ -10,12 +10,45 @@ bench = require 'lib.benchmark'
|
|||
sprites = {}
|
||||
sound_path = {}
|
||||
music_path = {}
|
||||
fonts = {}
|
||||
|
||||
debug = false
|
||||
|
||||
food = {}
|
||||
feesh = {}
|
||||
|
||||
footerbuttons = {
|
||||
{
|
||||
cost = 100,
|
||||
sprite = 'guppy',
|
||||
openanim = 1,
|
||||
open = true,
|
||||
func = function()
|
||||
table.insert(feesh, constr.fish(math.random(), 0.3))
|
||||
end
|
||||
},
|
||||
{
|
||||
cost = 200,
|
||||
sprite = 'food',
|
||||
tier = 1,
|
||||
openanim = 1,
|
||||
open = true,
|
||||
func = function()
|
||||
--table.insert(feesh, constr.fish(math.random(), 0.3))
|
||||
end
|
||||
},
|
||||
{
|
||||
cost = 300,
|
||||
sprite = 'foodcount',
|
||||
tier = 3,
|
||||
openanim = 1,
|
||||
open = true,
|
||||
func = function()
|
||||
--table.insert(feesh, constr.fish(math.random(), 0.3))
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
local sheets = {}
|
||||
|
||||
local function newAnimation(image, width, height)
|
||||
|
@ -51,10 +84,18 @@ function love.load()
|
|||
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['footer/button_open'], sprites['footer/button_open']:getWidth()/3, sprites['footer/button_open']:getHeight())
|
||||
|
||||
for i = 1, 3 do
|
||||
table.insert(feesh, constr.fish(math.random(), math.random()))
|
||||
end
|
||||
|
||||
fonts.pix = love.graphics.newFont('assets/fonts/pix.ttf', 6)
|
||||
fonts.continuum = love.graphics.newFont('assets/fonts/cont.ttf', 14)
|
||||
fonts.default = love.graphics.newFont(12)
|
||||
end
|
||||
|
||||
local frame = 0
|
||||
|
@ -252,7 +293,7 @@ function love.update(dt)
|
|||
n.render.turn = n.render.turn + dt * math.sign(n.render.x - n.render.prevx) * 2
|
||||
n.render.turn = clamp(n.render.turn, 0, 1)
|
||||
if n.render.turn == 0 or n.render.turn == 1 then
|
||||
n.render.swim = (n.render.swim + dt * math.abs(n.render.xspeed) * 100) % 1
|
||||
n.render.swim = (n.render.swim + dt * math.abs(n.render.xspeed) * 300) % 1
|
||||
else
|
||||
n.render.swim = 0
|
||||
end
|
||||
|
@ -289,6 +330,7 @@ function love.update(dt)
|
|||
end
|
||||
|
||||
function love.draw()
|
||||
love.graphics.setFont(fonts.default)
|
||||
bench.startBenchmark('render')
|
||||
|
||||
bench.startBenchmark('render_tank')
|
||||
|
@ -330,7 +372,9 @@ function love.draw()
|
|||
bench.startBenchmark('render_shadow')
|
||||
for i, n in ipairs(feesh) do
|
||||
love.graphics.setColor(1, 1, 1, n.render.y + 0.2 - n.render.deathanim)
|
||||
love.graphics.draw(sprites['shadow'], n.render.x * sw - (sprites['shadow']:getWidth() * spritescale)/2, sh - sh * 0.18 - (sprites['shadow']:getHeight() * spritescale)/2 + n.render.y * sh * 0.08, 0, spritescale, spritescale)
|
||||
local sizes = {0.55, 0.7, 1}
|
||||
local size = sizes[n.size + 1] or 1
|
||||
love.graphics.draw(sprites['shadow'], n.render.x * sw - (sprites['shadow']:getWidth() * spritescale * size)/2, sh - sh * 0.18 - (sprites['shadow']:getHeight() * spritescale * size)/2 + n.render.y * sh * 0.08, 0, spritescale * size, spritescale * size)
|
||||
end
|
||||
bench.stopBenchmark('render_shadow')
|
||||
-- all the fish
|
||||
|
@ -480,23 +524,72 @@ function love.draw()
|
|||
|
||||
-- the game is making me do this. im sorry
|
||||
local x = 19
|
||||
local y = 3
|
||||
for b = 1, 7 do
|
||||
local hovered = mouseOverBox(x, 3, sprites['footer/buttonbg']:getWidth(), sprites['footer/buttonbg']:getHeight())
|
||||
local hovered = mouseOverBox(x * size, y * size, sprites['footer/buttonbg']:getWidth() * size, sprites['footer/buttonbg']:getHeight() * size)
|
||||
local btn = footerbuttons[b]
|
||||
|
||||
if hovered and love.mouse.isDown(1) then
|
||||
love.graphics.draw(sprites['footer/buttonbg_down'], x, 3)
|
||||
if (btn and not btn.open) or not btn then
|
||||
-- draw nothing
|
||||
elseif hovered and love.mouse.isDown(1) then
|
||||
love.graphics.draw(sprites['footer/buttonbg_down'], x * size, y * size, 0, size, size)
|
||||
elseif hovered then
|
||||
love.graphics.draw(sprites['footer/buttonbg_hover'], x, 3)
|
||||
love.graphics.draw(sprites['footer/buttonbg_hover'], x * size, y * size, 0, size, size)
|
||||
else
|
||||
love.graphics.draw(sprites['footer/buttonbg'], x, 3)
|
||||
love.graphics.draw(sprites['footer/buttonbg'], x * size, y * size, 0, size, size)
|
||||
end
|
||||
|
||||
-- insert sprite of item here
|
||||
-- insert price of item here
|
||||
love.graphics.setBlendMode('add')
|
||||
love.graphics.draw(sprites['footer/reflection'], x, 3)
|
||||
love.graphics.setBlendMode('alpha')
|
||||
-- insert closing/opening animation here
|
||||
if btn and btn.open then
|
||||
-- sprite inside
|
||||
if btn.sprite == 'guppy' then
|
||||
local sheet = fishsprite('medium', false, 'swim')
|
||||
local frame = math.floor((love.timer.getTime() * 2) % 1 * #sheet.quads) + 1
|
||||
local scale = (sprites['footer/buttonbg']:getWidth() / sheet.width) * 0.9
|
||||
local offset = (sprites['footer/buttonbg']:getWidth() * size) / 2
|
||||
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)
|
||||
elseif btn.sprite == 'food' then
|
||||
local sheets = {sheets.food2, sheets.food3}
|
||||
local sheet = sheets[btn.tier]
|
||||
|
||||
local scale = (sprites['footer/buttonbg']:getWidth() / sheet.width) * 0.65
|
||||
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)
|
||||
elseif btn.sprite == 'foodcount' then
|
||||
love.graphics.setFont(fonts.continuum)
|
||||
local offset = (sprites['footer/buttonbg']:getWidth() * size) / 2
|
||||
|
||||
local bordersize = 1
|
||||
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.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
|
||||
|
||||
-- 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
|
||||
if (btn and not btn.openanim == 1) then
|
||||
local sheet = sheets.buttonopen
|
||||
local anim = 0
|
||||
if btn then anim = btn.openanim end
|
||||
local frame = math.floor(anim % 1 * #sheet.quads) + 1
|
||||
love.graphics.draw(sheet.spriteSheet, sheet.quads[frame], x * size, y * size, 0, size, size)
|
||||
end
|
||||
end
|
||||
|
||||
local incr = 69 -- its like button positions but forcefully shoved into a recursive function :D
|
||||
if b == 2 then incr = 57 end
|
||||
|
@ -518,6 +611,29 @@ function love.mousepressed(x, y, b)
|
|||
end
|
||||
end
|
||||
|
||||
function love.mousereleased(x, y, b)
|
||||
local footerheight = FOOTER_HEIGHT * love.graphics.getWidth()/640
|
||||
local size = footerheight / FOOTER_HEIGHT
|
||||
|
||||
if b == 1 then
|
||||
local x = 19
|
||||
for i = 1, 7 do
|
||||
local hovered = mouseOverBox(x * size, 3 * size, sprites['footer/buttonbg']:getWidth() * size, sprites['footer/buttonbg']:getHeight() * size)
|
||||
|
||||
if hovered then
|
||||
if footerbuttons[i] and footerbuttons[i].open then
|
||||
footerbuttons[i].func()
|
||||
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
|
||||
|
||||
function love.keypressed(key)
|
||||
if key == 'f3' then
|
||||
debug = not debug
|
||||
|
|