more cursor stuff

This commit is contained in:
jill 2021-01-25 19:42:27 +03:00
parent c4d1846765
commit 00f4f5a30b
Signed by: oat
GPG Key ID: DD83A9617A252385
6 changed files with 59 additions and 13 deletions

View File

@ -7,7 +7,7 @@ function self.fish(x, y, type)
local fish = { local fish = {
x = x, x = x,
y = y, y = y,
size = type, -- 0 for small, 1 for medium, 2 for big, 3 for king, 4 for carnivore size = 2, -- 0 for small, 1 for medium, 2 for big, 3 for king, 4 for carnivore
eattimer = 0 + math.random() * 2, -- starts out hungry, with a 2s delay eattimer = 0 + math.random() * 2, -- starts out hungry, with a 2s delay
moneytimer = 10 + math.random() * 5, -- min 10s before it can make money moneytimer = 10 + math.random() * 5, -- min 10s before it can make money
dead = false, dead = false,

View File

@ -57,8 +57,14 @@ function love.load()
love.mouse.setCursor(cursors.default) love.mouse.setCursor(cursors.default)
end end
local cursor
function setCursor(mouse)
cursor = mouse
end
frame = 0 frame = 0
function love.update(dt) function love.update(dt)
cursor = nil
frame = frame + 1 frame = frame + 1
bench.update() bench.update()
tick.update(dt) tick.update(dt)
@ -66,6 +72,12 @@ function love.update(dt)
bench.startBenchmark('update') bench.startBenchmark('update')
if scene.update then scene.update(dt) end if scene.update then scene.update(dt) end
bench.stopBenchmark('update') bench.stopBenchmark('update')
if cursor then
love.mouse.setCursor(cursor)
else
love.mouse.setCursor(cursors.default)
end
end end
function love.draw() function love.draw()

View File

@ -5,23 +5,40 @@ return function(headerheight, fishsprite, headerbuttons, sheets, balance)
love.graphics.setColor(1, 1, 1, 1) love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(base, 0, 0, 0, size, size) love.graphics.draw(base, 0, 0, 0, size, size)
local tooltip
local tooltipText
local tooltipx
local tooltipy
-- the game is making me do this. im sorry -- the game is making me do this. im sorry
local x = 19 local x = 19
local y = 3 local y = 3
for b = 1, 7 do for b = 1, 7 do
local hovered = mouseOverBox(x * size, y * size, sprites['header/buttonbg']:getWidth() * size, sprites['header/buttonbg']:getHeight() * size) local hovered = mouseOverBox(x * size, y * size, sprites['header/buttonbg']:getWidth() * size, sprites['header/buttonbg']:getHeight() * size)
local btn = headerbuttons[b] local btn = headerbuttons[b]
if (btn and not btn.open) or not btn then if (btn and not btn.open) or not btn then
-- draw nothing -- draw nothing
elseif hovered and love.mouse.isDown(1) then elseif hovered and love.mouse.isDown(1) then
love.graphics.draw(sprites['header/buttonbg_down'], x * size, y * size, 0, size, size) love.graphics.draw(sprites['header/buttonbg_down'], x * size, y * size, 0, size, size)
if not tooltip then tooltip = btn.tooltip end
elseif hovered then elseif hovered then
love.graphics.draw(sprites['header/buttonbg_hover'], x * size, y * size, 0, size, size) love.graphics.draw(sprites['header/buttonbg_hover'], x * size, y * size, 0, size, size)
if not tooltip then tooltip = btn.tooltip end
else else
love.graphics.draw(sprites['header/buttonbg'], x * size, y * size, 0, size, size) love.graphics.draw(sprites['header/buttonbg'], x * size, y * size, 0, size, size)
end end
if tooltip and btn and not tooltipText then
if not btn.tooltipText then
btn.tooltipText = love.graphics.newText(fonts.pix, tooltip)
end
tooltipText = btn.tooltipText
tooltipx = x + sprites['header/buttonbg']:getWidth() * size * 0.5 - tooltipText:getWidth()/2
tooltipy = y + sprites['header/buttonbg']:getWidth() * size
end
if btn then if btn then
if btn.open then if btn.open then
-- sprite inside -- sprite inside
@ -88,5 +105,16 @@ return function(headerheight, fishsprite, headerbuttons, sheets, balance)
love.graphics.setColor(179/255, 254/255, 89/255) love.graphics.setColor(179/255, 254/255, 89/255)
local leftpad = 100 local leftpad = 100
love.graphics.printf(balance, round(sw * 0.965 - leftpad), round(HEADER_HEIGHT - 25), leftpad, 'right') love.graphics.printf(balance, round(sw * 0.965 - leftpad), round(HEADER_HEIGHT - 25), leftpad, 'right')
if tooltipText then
love.graphics.setColor(254/255, 254/255, 199/255)
love.graphics.rectangle('fill', round(tooltipx - 5), round(tooltipy - 5), round(tooltipText:getWidth() + 10), round(tooltipText:getHeight() + 10))
love.graphics.setColor(2/255, 2/255, 2/255)
love.graphics.rectangle('line', round(tooltipx - 5), round(tooltipy - 5), round(tooltipText:getWidth() + 10), round(tooltipText:getHeight() + 10))
love.graphics.setFont(fonts.pix)
love.graphics.draw(tooltipText, round(tooltipx), round(tooltipy))
end
love.graphics.setFont(fonts.default) love.graphics.setFont(fonts.default)
end end

View File

@ -16,6 +16,7 @@ local headerbuttons = {
cost = 100, cost = 100,
sprite = 'guppy', sprite = 'guppy',
openanim = 1, openanim = 1,
tooltip = 'buy guppy',
open = false, open = false,
closed = false, closed = false,
func = function() func = function()
@ -28,6 +29,7 @@ local headerbuttons = {
sprite = 'food', sprite = 'food',
tier = foodtier, tier = foodtier,
openanim = 1, openanim = 1,
tooltip = 'upgrade food quality',
open = false, open = false,
closed = false, closed = false,
func = function(self) func = function(self)
@ -46,6 +48,7 @@ local headerbuttons = {
sprite = 'foodcount', sprite = 'foodcount',
tier = foodcount, tier = foodcount,
openanim = 1, openanim = 1,
tooltip = 'upgrade food quantity',
open = false, open = false,
closed = false, closed = false,
func = function(self) func = function(self)
@ -62,6 +65,7 @@ local headerbuttons = {
{ {
cost = 1000, cost = 1000,
sprite = 'carnivore', sprite = 'carnivore',
tooltip = 'buy carnivore',
openanim = 1, openanim = 1,
open = false, open = false,
closed = false, closed = false,
@ -109,15 +113,13 @@ function self.update(dt)
local x = 19 local x = 19
local y = 3 local y = 3
local anyhover = false
for b,btn in ipairs(headerbuttons) do for b,btn in ipairs(headerbuttons) do
btn.openanim = btn.openanim + dt * 6 btn.openanim = btn.openanim + dt * 6
local size = (love.graphics.getWidth()/640) local size = (love.graphics.getWidth()/640)
local hovered = mouseOverBox(x * size, y * size, sprites['header/buttonbg']:getWidth() * size, sprites['header/buttonbg']:getHeight() * size) local hovered = mouseOverBox(x * size, y * size, sprites['header/buttonbg']:getWidth() * size, sprites['header/buttonbg']:getHeight() * size)
if btn.open and hovered then if btn.open and hovered then
love.mouse.setCursor(cursors.hover) setCursor(cursors.hover)
anyhover = true
end end
local incr = 69 -- its like button positions but forcefully shoved into a recursive function :D local incr = 69 -- its like button positions but forcefully shoved into a recursive function :D
@ -125,9 +127,6 @@ function self.update(dt)
if b >= 3 then incr = 73 end if b >= 3 then incr = 73 end
x = x + incr x = x + incr
end end
if not anyhover then
love.mouse.setCursor(cursors.default)
end
bench.stopBenchmark('update_buttons') bench.stopBenchmark('update_buttons')
@ -136,7 +135,7 @@ function self.update(dt)
bench.stopBenchmark('update_food') bench.stopBenchmark('update_food')
bench.startBenchmark('update_money') bench.startBenchmark('update_money')
require('scenes.gameplay.update.money')(money, dt) require('scenes.gameplay.update.money')(money, dt, sheets)
bench.stopBenchmark('update_money') bench.stopBenchmark('update_money')
bench.startBenchmark('update_fish') bench.startBenchmark('update_fish')
@ -195,7 +194,7 @@ function self.mousepressed(x, y, b)
if b == 1 then if b == 1 then
for _,m in ipairs(money) do for _,m in ipairs(money) do
local dist = math.abs(x/love.graphics.getWidth() - m.x) + math.abs(y/love.graphics.getHeight() - m.y) 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 if dist < sheets.coin1.width/2 and not m.collected then
m.collected = true m.collected = true
m.deathtimer = 0 m.deathtimer = 0
playSound('collect', 1, 1 + math.random() * 0.2 - 0.1) playSound('collect', 1, 1 + math.random() * 0.2 - 0.1)

View File

@ -29,6 +29,7 @@ return function(feesh, dt, food, headerbuttons, money)
local str = math.random(70, 200)/200/4 local str = math.random(70, 200)/200/4
angle = mix(angle, math.deg(math.atan2((0.5 + math.sin(love.timer.getTime()/10 + fi) * 0.2) - n.y, 0)), 0.1) -- slightly head towards the middle, to prevent getting stuck at the bottom or top angle = mix(angle, math.deg(math.atan2((0.5 + math.sin(love.timer.getTime()/10 + fi) * 0.2) - n.y, 0)), 0.1) -- slightly head towards the middle, to prevent getting stuck at the bottom or top
local followingObj = (n.shortestfood and food[n.shortestfood] and n.size ~= 4) or (n.shortestfood and feesh[n.shortestfood] and n.size == 4)
if n.eattimer <= 0 and not n.dead then -- needs to follow something if n.eattimer <= 0 and not n.dead then -- needs to follow something
local mx, my local mx, my
if n.eattimer <= 0 then if n.eattimer <= 0 then
@ -85,7 +86,7 @@ return function(feesh, dt, food, headerbuttons, money)
local x = math.cos(math.rad(angle)) * str local x = math.cos(math.rad(angle)) * str
local y = math.sin(math.rad(angle)) * str local y = math.sin(math.rad(angle)) * str
if not ((n.shortestfood and food[n.shortestfood]) or n.dead) then if not (followingObj or n.dead) then
x = x * math.sign(n.render.x - n.render.prevx) x = x * math.sign(n.render.x - n.render.prevx)
end end
@ -101,8 +102,9 @@ return function(feesh, dt, food, headerbuttons, money)
end end
e.speed = 1 / (math.sqrt(math.pow(math.abs(e.x - e.fromx), 2) + math.pow(math.abs(e.y - e.fromy), 2))/2) / 15 e.speed = 1 / (math.sqrt(math.pow(math.abs(e.x - e.fromx), 2) + math.pow(math.abs(e.y - e.fromy), 2))/2) / 15
if n.eattimer < FISH_FOOD_HUNGRY or (n.shortestfood and food[n.shortestfood]) then if n.eattimer < FISH_FOOD_HUNGRY or followingObj then
e.speed = e.speed * 1.3 e.speed = e.speed * 1.3
if n.size == 4 then e.speed = e.speed * 1.1 end
end end
if n.dead then if n.dead then
e.speed = e.speed * 0.2 e.speed = e.speed * 0.2

View File

@ -1,4 +1,4 @@
return function(money, dt) return function(money, dt, sheets)
for i,f in ipairs(money) do for i,f in ipairs(money) do
if not f.collected then if not f.collected then
f.y = f.y + dt * f.speed f.y = f.y + dt * f.speed
@ -16,5 +16,10 @@ return function(money, dt)
if f.deathtimer > 1 or f.collecttimer > 1 then if f.deathtimer > 1 or f.collecttimer > 1 then
table.remove(money, i) table.remove(money, i)
end end
local dist = math.abs(love.mouse.getX() - f.x * love.graphics.getWidth()) + math.abs(love.mouse.getY() - f.y * love.graphics.getHeight())
if dist < sheets.coin1.width/2 and not f.collected then
setCursor(cursors.hover)
end
end end
end end