diff --git a/constructors.lua b/constructors.lua index c1f5077..500b5cf 100644 --- a/constructors.lua +++ b/constructors.lua @@ -7,7 +7,7 @@ function self.fish(x, y, type) local fish = { x = x, 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 moneytimer = 10 + math.random() * 5, -- min 10s before it can make money dead = false, diff --git a/main.lua b/main.lua index 855133a..ca3143a 100644 --- a/main.lua +++ b/main.lua @@ -57,8 +57,14 @@ function love.load() love.mouse.setCursor(cursors.default) end +local cursor +function setCursor(mouse) + cursor = mouse +end + frame = 0 function love.update(dt) + cursor = nil frame = frame + 1 bench.update() tick.update(dt) @@ -66,6 +72,12 @@ function love.update(dt) bench.startBenchmark('update') if scene.update then scene.update(dt) end bench.stopBenchmark('update') + + if cursor then + love.mouse.setCursor(cursor) + else + love.mouse.setCursor(cursors.default) + end end function love.draw() diff --git a/scenes/gameplay/draw/header.lua b/scenes/gameplay/draw/header.lua index 8449f86..07c4e09 100644 --- a/scenes/gameplay/draw/header.lua +++ b/scenes/gameplay/draw/header.lua @@ -5,23 +5,40 @@ return function(headerheight, fishsprite, headerbuttons, sheets, balance) love.graphics.setColor(1, 1, 1, 1) 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 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) + if not tooltip then tooltip = btn.tooltip end elseif hovered then love.graphics.draw(sprites['header/buttonbg_hover'], x * size, y * size, 0, size, size) + if not tooltip then tooltip = btn.tooltip end else love.graphics.draw(sprites['header/buttonbg'], x * size, y * size, 0, size, size) 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.open then -- sprite inside @@ -88,5 +105,16 @@ return function(headerheight, fishsprite, headerbuttons, sheets, balance) 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') + + 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) end \ No newline at end of file diff --git a/scenes/gameplay/main.lua b/scenes/gameplay/main.lua index 204ad17..1c00aa2 100644 --- a/scenes/gameplay/main.lua +++ b/scenes/gameplay/main.lua @@ -16,6 +16,7 @@ local headerbuttons = { cost = 100, sprite = 'guppy', openanim = 1, + tooltip = 'buy guppy', open = false, closed = false, func = function() @@ -28,6 +29,7 @@ local headerbuttons = { sprite = 'food', tier = foodtier, openanim = 1, + tooltip = 'upgrade food quality', open = false, closed = false, func = function(self) @@ -46,6 +48,7 @@ local headerbuttons = { sprite = 'foodcount', tier = foodcount, openanim = 1, + tooltip = 'upgrade food quantity', open = false, closed = false, func = function(self) @@ -62,6 +65,7 @@ local headerbuttons = { { cost = 1000, sprite = 'carnivore', + tooltip = 'buy carnivore', openanim = 1, open = false, closed = false, @@ -109,15 +113,13 @@ function self.update(dt) local x = 19 local y = 3 - local anyhover = false for b,btn in ipairs(headerbuttons) do btn.openanim = btn.openanim + dt * 6 local size = (love.graphics.getWidth()/640) local hovered = mouseOverBox(x * size, y * size, sprites['header/buttonbg']:getWidth() * size, sprites['header/buttonbg']:getHeight() * size) if btn.open and hovered then - love.mouse.setCursor(cursors.hover) - anyhover = true + setCursor(cursors.hover) end 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 x = x + incr end - if not anyhover then - love.mouse.setCursor(cursors.default) - end bench.stopBenchmark('update_buttons') @@ -136,7 +135,7 @@ function self.update(dt) bench.stopBenchmark('update_food') bench.startBenchmark('update_money') - require('scenes.gameplay.update.money')(money, dt) + require('scenes.gameplay.update.money')(money, dt, sheets) bench.stopBenchmark('update_money') bench.startBenchmark('update_fish') @@ -195,7 +194,7 @@ 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 + if dist < sheets.coin1.width/2 and not m.collected then m.collected = true m.deathtimer = 0 playSound('collect', 1, 1 + math.random() * 0.2 - 0.1) diff --git a/scenes/gameplay/update/fish.lua b/scenes/gameplay/update/fish.lua index ec612e1..c0110f3 100644 --- a/scenes/gameplay/update/fish.lua +++ b/scenes/gameplay/update/fish.lua @@ -29,6 +29,7 @@ return function(feesh, dt, food, headerbuttons, money) 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 + 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 local mx, my 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 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) end @@ -101,8 +102,9 @@ return function(feesh, dt, food, headerbuttons, money) 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 - 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 + if n.size == 4 then e.speed = e.speed * 1.1 end end if n.dead then e.speed = e.speed * 0.2 diff --git a/scenes/gameplay/update/money.lua b/scenes/gameplay/update/money.lua index 1220fb1..5fc4fba 100644 --- a/scenes/gameplay/update/money.lua +++ b/scenes/gameplay/update/money.lua @@ -1,4 +1,4 @@ -return function(money, dt) +return function(money, dt, sheets) for i,f in ipairs(money) do if not f.collected then f.y = f.y + dt * f.speed @@ -16,5 +16,10 @@ return function(money, dt) if f.deathtimer > 1 or f.collecttimer > 1 then table.remove(money, i) 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 \ No newline at end of file