diff --git a/assets/sprites/footer/gif/mbuttond.gif-autosave.kra b/assets/sprites/footer/gif/mbuttond.gif-autosave.kra deleted file mode 100644 index ed72a69..0000000 Binary files a/assets/sprites/footer/gif/mbuttond.gif-autosave.kra and /dev/null differ diff --git a/assets/sprites/footer/gif/mbuttono.gif-autosave.kra b/assets/sprites/footer/gif/mbuttono.gif-autosave.kra deleted file mode 100644 index 75fdd5d..0000000 Binary files a/assets/sprites/footer/gif/mbuttono.gif-autosave.kra and /dev/null differ diff --git a/assets/sprites/footer/gif/mbuttonu.gif-autosave.kra b/assets/sprites/footer/gif/mbuttonu.gif-autosave.kra deleted file mode 100644 index 1a633cd..0000000 Binary files a/assets/sprites/footer/gif/mbuttonu.gif-autosave.kra and /dev/null differ diff --git a/assets/sprites/footer/gif/menubar.gif-autosave.kra b/assets/sprites/footer/gif/menubar.gif-autosave.kra deleted file mode 100644 index 644ebec..0000000 Binary files a/assets/sprites/footer/gif/menubar.gif-autosave.kra and /dev/null differ diff --git a/const.lua b/const.lua index d421890..7ebf39e 100644 --- a/const.lua +++ b/const.lua @@ -11,6 +11,7 @@ FISH_EASE = ease.inOutSine -- ease used for fish movement FISH_ANGLE = 30 -- bigger angle allows for fish to swim further down/up at once FISH_FOLLOW_RANDOM = 10 +FISH_FOOD_CHECK_FREQ = 10 -- how often to check for food FISH_FOOD_COOLDOWN = 10 FISH_FOOD_HUNGRY = -5 FISH_FOOD_DEAD = -15 @@ -22,7 +23,7 @@ FISH_SIZE = 6 -- how many large guppies can you fit on the screen FOOTER_HEIGHT = 68 -FOOD_HITBOX = 0.05 +FOOD_HITBOX = 0.08 DEBUG_FISH_PATH_SUBDIVISIONS = 50 DEBUG_FISH_PREDICT_AMOUNT = 0.5 \ No newline at end of file diff --git a/constructors.lua b/constructors.lua index af8ed5c..03dda8b 100644 --- a/constructors.lua +++ b/constructors.lua @@ -50,8 +50,7 @@ function self.food(x, y, type) speed = 0.2, time = math.random(), deathtimer = 0, - type = 1, - goal = 0 -- assigns 0 as the fish so that hopefully the update loop replaces it with a valid, random one + type = 1 } return food diff --git a/main.lua b/main.lua index 3d8ab7a..ebf0660 100644 --- a/main.lua +++ b/main.lua @@ -65,7 +65,6 @@ function love.update(dt) bench.startBenchmark('update') bench.startBenchmark('update_food') - local fishgoals = {} for i,f in ipairs(food) do f.y = f.y + dt * f.speed f.time = f.time + dt @@ -75,18 +74,8 @@ function love.update(dt) f.deathtimer = f.deathtimer + dt end - if f.goal == 0 or not f.goal then - for i,n in ipairs(feesh) do - if not fishgoals[i] and n.eattimer <= 0 then - f.goal = i - end - end - end - if f.deathtimer > 1 then table.remove(food, i) - else - fishgoals[f.goal] = i end end bench.stopBenchmark('update_food') @@ -120,26 +109,41 @@ function love.update(dt) local angle = math.random(-FISH_ANGLE, FISH_ANGLE) local str = math.random(70, 200)/200/4 - if n.eattimer < -15 then - str = str * 1.3 - end - if --[[love.mouse.isDown(1) or]] fishgoals[fi] then - local mx, my = love.mouse.getPosition() - mx = mx / love.graphics.getWidth() - my = my / love.graphics.getHeight() + if n.eattimer <= 0 then -- needs to follow something + local mx, my + if n.eattimer <= 0 then + if n.shortestfood and food[n.shortestfood] then + local f = food[n.shortestfood] + mx, my = f.x, f.y + elseif frame % FISH_FOOD_CHECK_FREQ == 0 then + local minfood = 0 + local mindist = 9e9 + + for i,f in ipairs(food) do + local dist = math.sqrt(math.pow(math.abs(f.x - n.render.x), 2) + math.pow(math.abs(f.y - n.render.y), 2)) + if dist < mindist then + mindist = dist + minfood = i + end + end + + if minfood ~= 0 then + n.shortestfood = minfood + end + end - if fishgoals[fi] and food[fishgoals[fi]] then - mx = food[fishgoals[fi]].x - my = food[fishgoals[fi]].y end - angle = math.deg(math.atan2(my - n.y, mx - n.x)) + math.random(-FISH_FOLLOW_RANDOM, FISH_FOLLOW_RANDOM) + if mx and my then + angle = math.deg(math.atan2(my - n.y, mx - n.x)) + math.random(-FISH_FOLLOW_RANDOM, FISH_FOLLOW_RANDOM) + str = math.random(70, 200)/200/8 + end end local x = math.cos(math.rad(angle)) * str local y = math.sin(math.rad(angle)) * str - if not (--[[love.mouse.isDown(1) or ]]fishgoals[fi]) then + if not (n.shortestfood and food[n.shortestfood]) then x = x * math.sign(n.render.x - n.render.prevx) end @@ -155,6 +159,9 @@ function love.update(dt) 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 < -15 or (n.shortestfood and food[n.shortestfood]) then + e.speed = e.speed * 1.4 + end end end bench.stopBenchmark('update_fish_eases') @@ -181,15 +188,16 @@ function love.update(dt) n.render.x = clamp(n.render.x, 0.05, 0.95) n.render.y = clamp(n.render.y, 0.1, 0.85) - if fishgoals[fi] and frame % FISH_COLISSION_CHECK_FREQ == 0 then - local f = food[fishgoals[fi]] + if n.shortestfood and food[n.shortestfood] and frame % FISH_COLISSION_CHECK_FREQ == 0 then + local f = food[n.shortestfood] if f then local dist = math.abs(n.render.x - f.x) + math.abs(n.render.y - f.y) if dist < FOOD_HITBOX then - table.remove(food, fishgoals[fi]) + table.remove(food, n.shortestfood) n.eattimer = FISH_FOOD_COOLDOWN n.render.eattimer = 0 + n.shortestfood = -1 if n.lifetime > FISH_AGE_MEDIUM then n.size = 1