3am refactoring lets go
This commit is contained in:
parent
e2703105dd
commit
5fbf569c65
11 changed files with 769 additions and 708 deletions
124
scenes/gameplay/draw/fish.lua
Normal file
124
scenes/gameplay/draw/fish.lua
Normal file
|
@ -0,0 +1,124 @@
|
|||
return function(feesh, spritescale, fishsprite)
|
||||
local sw, sh = love.graphics.getDimensions()
|
||||
for i, n in ipairs(feesh) do
|
||||
local x = n.render.x * sw
|
||||
local y = n.render.y * sh
|
||||
|
||||
-- rest of feesh
|
||||
local size = 'small'
|
||||
local anim = 'swim'
|
||||
|
||||
local sample = fishsprite('medium', false, 'swim')
|
||||
|
||||
local sizex = 1
|
||||
local turn = n.render.turn
|
||||
if n.render.turndir == -1 then turn = 1 - turn; sizex = -1 end
|
||||
|
||||
local turnframe = math.floor(turn * (#sample.quads - 1)) + 1
|
||||
if #sample.quads == turnframe then
|
||||
sizex = -1 * sizex
|
||||
turnframe = 1
|
||||
end
|
||||
|
||||
local frame = math.floor(n.render.swim * (#sample.quads - 1)) + 1
|
||||
|
||||
if turnframe ~= 1 and turnframe ~= #sample.quads then
|
||||
anim = 'turn'
|
||||
frame = turnframe
|
||||
end
|
||||
|
||||
if n.render.eattimer <= 1 then
|
||||
anim = 'eat'
|
||||
frame = math.floor(n.render.eattimer * (#sample.quads - 1)) + 1
|
||||
end
|
||||
|
||||
if n.dead then
|
||||
anim = 'die'
|
||||
local a = math.min(math.abs(n.eattimer - FISH_FOOD_DEAD) * 1.4, 1) - n.render.deathanim * 0.4
|
||||
frame = math.floor(a * (#sample.quads - 1)) + 1
|
||||
end
|
||||
|
||||
local angle = n.render.angle
|
||||
if angle > math.pi/2 then
|
||||
angle = angle - math.pi
|
||||
end
|
||||
if angle < -math.pi/2 then
|
||||
angle = angle + math.pi
|
||||
end
|
||||
|
||||
angle = angle * math.max(math.min((-math.abs(angle) + math.pi * 0.5) / (math.pi * 0.5) * 2, 1), 0)
|
||||
angle = angle * 0.5
|
||||
|
||||
if n.size == 0 then
|
||||
size = 'small'
|
||||
elseif n.size == 1 then
|
||||
size = 'medium'
|
||||
elseif n.size == 2 then
|
||||
size = 'big'
|
||||
elseif n.size == 3 then
|
||||
size = 'king'
|
||||
end
|
||||
|
||||
local sheet = fishsprite(size, false, anim)
|
||||
local sadsheet = fishsprite(size, true, anim)
|
||||
|
||||
local alpha = n.render.hungry == 1 and 0 or 1
|
||||
love.graphics.setColor(1, 1, 1, alpha - n.render.deathanim)
|
||||
love.graphics.draw(sheet.spriteSheet, sheet.quads[math.max(math.min(frame, #sample.quads), 1)], x, y, angle, sizex * spritescale, spritescale, sample.width/2, sample.height/2)
|
||||
love.graphics.setColor(1, 1, 1, n.render.hungry - n.render.deathanim)
|
||||
love.graphics.draw(sadsheet.spriteSheet, sheet.quads[math.max(math.min(frame, #sample.quads), 1)], x, y, angle, sizex * spritescale, spritescale, sample.width/2, sample.height/2)
|
||||
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
if debug then love.graphics.print(shrt(n.eattimer), x + 20, y + 20) end
|
||||
|
||||
if debug then
|
||||
for _,e in ipairs(n.eases) do
|
||||
love.graphics.setColor(1, 0, 0, 0.75)
|
||||
love.graphics.line(e.fromx * sw, e.fromy * sh, e.x * sw, e.y * sh)
|
||||
|
||||
love.graphics.setColor(0, 0, 1, 0.75)
|
||||
love.graphics.line(mix(e.fromx, e.x, FISH_EASE(e.a)) * sw, mix(e.fromy, e.y, FISH_EASE(e.a)) * sh, n.render.x * sw, n.render.y * sh)
|
||||
end
|
||||
|
||||
local subdiv = DEBUG_FISH_PATH_SUBDIVISIONS
|
||||
local adv = DEBUG_FISH_PREDICT_AMOUNT
|
||||
local pos = {}
|
||||
local valid = {}
|
||||
|
||||
for i = 1, subdiv do
|
||||
local a = ((i - 1) / (subdiv - 1)) * (adv * 2) - adv
|
||||
|
||||
local sumx = 0
|
||||
local sumy = 0
|
||||
local mina = 0
|
||||
local maxa = 1
|
||||
for _, e in ipairs(n.eases) do
|
||||
local a = e.a + a
|
||||
mina = math.min(mina, a)
|
||||
maxa = math.max(maxa, a)
|
||||
sumx = sumx + mix(e.fromx, e.x, FISH_EASE(a))
|
||||
sumy = sumy + mix(e.fromy, e.y, FISH_EASE(a))
|
||||
end
|
||||
|
||||
table.insert(pos, sumx / #n.eases * sw)
|
||||
table.insert(pos, sumy / #n.eases * sh)
|
||||
table.insert(valid, not (maxa > 1 or mina < 0))
|
||||
end
|
||||
|
||||
for i = 0, #pos/2 - 1 do
|
||||
local x1 = pos[i * 2 + 1]
|
||||
local y1 = pos[i * 2 + 1 + 1]
|
||||
local x2 = pos[i * 2 + 2 + 1]
|
||||
local y2 = pos[i * 2 + 3 + 1]
|
||||
local valid = valid[i + 1]
|
||||
|
||||
if not x2 or not y2 then break end
|
||||
|
||||
love.graphics.setColor(0, 1, 0, 1)
|
||||
if not valid then love.graphics.setColor(0, 0.5, 1, 0.7) end
|
||||
|
||||
love.graphics.line(x1, y1, x2, y2)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
13
scenes/gameplay/draw/food.lua
Normal file
13
scenes/gameplay/draw/food.lua
Normal file
|
@ -0,0 +1,13 @@
|
|||
return function(food, sheets, spritescale)
|
||||
local sw, sh = love.graphics.getDimensions()
|
||||
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
|
||||
end
|
91
scenes/gameplay/draw/header.lua
Normal file
91
scenes/gameplay/draw/header.lua
Normal file
|
@ -0,0 +1,91 @@
|
|||
return function(headerheight, fishsprite, headerbuttons, sheets, balance)
|
||||
local sw, sh = love.graphics.getDimensions()
|
||||
local base = sprites['header/base']
|
||||
local size = headerheight / HEADER_HEIGHT
|
||||
love.graphics.setColor(1, 1, 1, 1)
|
||||
love.graphics.draw(base, 0, 0, 0, size, size)
|
||||
|
||||
-- the game is making me do this. im sorry
|
||||
local x = 19
|
||||
local y = 3
|
||||
for b = 1, 7 do
|
||||
local hovered = mouseOverBox(x * size, y * size, sprites['header/buttonbg']:getWidth() * size, sprites['header/buttonbg']:getHeight() * size)
|
||||
local btn = headerbuttons[b]
|
||||
|
||||
if (btn and not btn.open) or not btn then
|
||||
-- draw nothing
|
||||
elseif hovered and love.mouse.isDown(1) then
|
||||
love.graphics.draw(sprites['header/buttonbg_down'], x * size, y * size, 0, size, size)
|
||||
elseif hovered then
|
||||
love.graphics.draw(sprites['header/buttonbg_hover'], x * size, y * size, 0, size, size)
|
||||
else
|
||||
love.graphics.draw(sprites['header/buttonbg'], x * size, y * size, 0, size, size)
|
||||
end
|
||||
|
||||
if btn then
|
||||
if 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['header/buttonbg']:getWidth() / sheet.width) * 0.9
|
||||
local offset = (sprites['header/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['header/buttonbg']:getWidth() / sheet.width) * 0.65
|
||||
local offset = (sprites['header/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['header/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['header/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['header/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['header/buttonbg']:getWidth() * size), 'center')
|
||||
love.graphics.setColor(1, 1, 1)
|
||||
love.graphics.setFont(fonts.default)
|
||||
|
||||
-- reflection
|
||||
love.graphics.setBlendMode('add')
|
||||
love.graphics.draw(sprites['header/reflection'], x * size, y * size, 0, size, size)
|
||||
love.graphics.setBlendMode('alpha')
|
||||
end
|
||||
|
||||
-- open/close anim
|
||||
if (btn and 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
|
||||
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(HEADER_HEIGHT - 25), leftpad, 'right')
|
||||
love.graphics.setFont(fonts.default)
|
||||
end
|
12
scenes/gameplay/draw/money.lua
Normal file
12
scenes/gameplay/draw/money.lua
Normal file
|
@ -0,0 +1,12 @@
|
|||
return function(money, sheets, spritescale)
|
||||
local sw, sh = love.graphics.getDimensions()
|
||||
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, HEADER_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
|
||||
end
|
9
scenes/gameplay/draw/shadow.lua
Normal file
9
scenes/gameplay/draw/shadow.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
return function(feesh, spritescale)
|
||||
local sw, sh = love.graphics.getDimensions()
|
||||
for i, n in ipairs(feesh) do
|
||||
love.graphics.setColor(1, 1, 1, n.render.y + 0.2 - n.render.deathanim)
|
||||
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
|
||||
end
|
22
scenes/gameplay/draw/wave.lua
Normal file
22
scenes/gameplay/draw/wave.lua
Normal file
|
@ -0,0 +1,22 @@
|
|||
return function(headerheight, sheets)
|
||||
local sw, sh = love.graphics.getDimensions()
|
||||
local wavecount = round(sw / sprites['wave/wavecenter']:getWidth())
|
||||
local wavescale = sw / (wavecount * sprites['wave/wavecenter']:getWidth())
|
||||
for i = 1, wavecount do
|
||||
local a = (i - 1) / wavecount
|
||||
local x = a * sw
|
||||
local frame = round((1 - math.abs(love.timer.getTime()%2-1)) * #sheets.wavecenter.quads)
|
||||
love.graphics.setBlendMode('add')
|
||||
|
||||
local sheet = sheets.wavecenter
|
||||
local sizex = 1
|
||||
if i == 1 or i == wavecount then
|
||||
sheet = sheets.waveside
|
||||
end
|
||||
if i == wavecount then
|
||||
sizex = -1
|
||||
end
|
||||
love.graphics.draw(sheet.spriteSheet, sheet.quads[math.max(frame, 1)], x + (sprites['wave/wavecenter']:getWidth() * wavescale)/2, headerheight + 20, 0, wavescale * sizex, wavescale, sprites['wave/wavecenter']:getWidth()/2)
|
||||
end
|
||||
love.graphics.setBlendMode('alpha')
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue