Compare commits
No commits in common. "6ecbf07dbf2150d00a4da5df18687ffac3cdd7e3" and "436d5f0301abe88742d2ef6576ccc1d01bf2c85c" have entirely different histories.
6ecbf07dbf
...
436d5f0301
7 changed files with 38 additions and 74 deletions
BIN
assets/sprites/footer/gif/mbuttond.gif-autosave.kra
Normal file
BIN
assets/sprites/footer/gif/mbuttond.gif-autosave.kra
Normal file
Binary file not shown.
BIN
assets/sprites/footer/gif/mbuttono.gif-autosave.kra
Normal file
BIN
assets/sprites/footer/gif/mbuttono.gif-autosave.kra
Normal file
Binary file not shown.
BIN
assets/sprites/footer/gif/mbuttonu.gif-autosave.kra
Normal file
BIN
assets/sprites/footer/gif/mbuttonu.gif-autosave.kra
Normal file
Binary file not shown.
BIN
assets/sprites/footer/gif/menubar.gif-autosave.kra
Normal file
BIN
assets/sprites/footer/gif/menubar.gif-autosave.kra
Normal file
Binary file not shown.
|
@ -11,7 +11,6 @@ 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_ANGLE = 30 -- bigger angle allows for fish to swim further down/up at once
|
||||||
FISH_FOLLOW_RANDOM = 10
|
FISH_FOLLOW_RANDOM = 10
|
||||||
|
|
||||||
FISH_FOOD_CHECK_FREQ = 10 -- how often to check for food
|
|
||||||
FISH_FOOD_COOLDOWN = 10
|
FISH_FOOD_COOLDOWN = 10
|
||||||
FISH_FOOD_HUNGRY = -5
|
FISH_FOOD_HUNGRY = -5
|
||||||
FISH_FOOD_DEAD = -15
|
FISH_FOOD_DEAD = -15
|
||||||
|
@ -23,7 +22,7 @@ FISH_SIZE = 6 -- how many large guppies can you fit on the screen
|
||||||
|
|
||||||
FOOTER_HEIGHT = 68
|
FOOTER_HEIGHT = 68
|
||||||
|
|
||||||
FOOD_HITBOX = 0.08
|
FOOD_HITBOX = 0.05
|
||||||
|
|
||||||
DEBUG_FISH_PATH_SUBDIVISIONS = 50
|
DEBUG_FISH_PATH_SUBDIVISIONS = 50
|
||||||
DEBUG_FISH_PREDICT_AMOUNT = 0.5
|
DEBUG_FISH_PREDICT_AMOUNT = 0.5
|
|
@ -8,7 +8,6 @@ function self.fish(x, y)
|
||||||
y = y,
|
y = y,
|
||||||
size = 0, -- 0 for small, 1 for medium, 2 for big, 3 for king
|
size = 0, -- 0 for small, 1 for medium, 2 for big, 3 for king
|
||||||
eattimer = 0 + math.random() * 2, -- starts out hungry, with a 2s delay
|
eattimer = 0 + math.random() * 2, -- starts out hungry, with a 2s delay
|
||||||
dead = false,
|
|
||||||
|
|
||||||
lifetime = 0,
|
lifetime = 0,
|
||||||
|
|
||||||
|
@ -27,7 +26,6 @@ function self.fish(x, y)
|
||||||
yspeed = 0,
|
yspeed = 0,
|
||||||
eattimer = 1,
|
eattimer = 1,
|
||||||
hungry = 0,
|
hungry = 0,
|
||||||
deathanim = 0,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +50,8 @@ function self.food(x, y, type)
|
||||||
speed = 0.2,
|
speed = 0.2,
|
||||||
time = math.random(),
|
time = math.random(),
|
||||||
deathtimer = 0,
|
deathtimer = 0,
|
||||||
type = 1
|
type = 1,
|
||||||
|
goal = 0 -- assigns 0 as the fish so that hopefully the update loop replaces it with a valid, random one
|
||||||
}
|
}
|
||||||
|
|
||||||
return food
|
return food
|
||||||
|
|
104
main.lua
104
main.lua
|
@ -52,7 +52,7 @@ function love.load()
|
||||||
|
|
||||||
sheets.food1 = newAnimation(sprites['food/1'], sprites['food/1']:getWidth()/10, sprites['food/1']:getHeight())
|
sheets.food1 = newAnimation(sprites['food/1'], sprites['food/1']:getWidth()/10, sprites['food/1']:getHeight())
|
||||||
|
|
||||||
for i = 1, 3 do
|
for i = 1, 10 do
|
||||||
table.insert(feesh, constr.fish(math.random(), math.random()))
|
table.insert(feesh, constr.fish(math.random(), math.random()))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -65,6 +65,7 @@ function love.update(dt)
|
||||||
|
|
||||||
bench.startBenchmark('update')
|
bench.startBenchmark('update')
|
||||||
bench.startBenchmark('update_food')
|
bench.startBenchmark('update_food')
|
||||||
|
local fishgoals = {}
|
||||||
for i,f in ipairs(food) do
|
for i,f in ipairs(food) do
|
||||||
f.y = f.y + dt * f.speed
|
f.y = f.y + dt * f.speed
|
||||||
f.time = f.time + dt
|
f.time = f.time + dt
|
||||||
|
@ -74,8 +75,18 @@ function love.update(dt)
|
||||||
f.deathtimer = f.deathtimer + dt
|
f.deathtimer = f.deathtimer + dt
|
||||||
end
|
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
|
if f.deathtimer > 1 then
|
||||||
table.remove(food, i)
|
table.remove(food, i)
|
||||||
|
else
|
||||||
|
fishgoals[f.goal] = i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
bench.stopBenchmark('update_food')
|
bench.stopBenchmark('update_food')
|
||||||
|
@ -109,41 +120,26 @@ function love.update(dt)
|
||||||
|
|
||||||
local angle = math.random(-FISH_ANGLE, FISH_ANGLE)
|
local angle = math.random(-FISH_ANGLE, FISH_ANGLE)
|
||||||
local str = math.random(70, 200)/200/4
|
local str = math.random(70, 200)/200/4
|
||||||
|
if n.eattimer < -15 then
|
||||||
|
str = str * 1.3
|
||||||
|
end
|
||||||
|
|
||||||
if n.eattimer <= 0 and not n.dead then -- needs to follow something
|
if --[[love.mouse.isDown(1) or]] fishgoals[fi] then
|
||||||
local mx, my
|
local mx, my = love.mouse.getPosition()
|
||||||
if n.eattimer <= 0 then
|
mx = mx / love.graphics.getWidth()
|
||||||
if n.shortestfood and food[n.shortestfood] then
|
my = my / love.graphics.getHeight()
|
||||||
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
|
end
|
||||||
if mx and my then
|
angle = math.deg(math.atan2(my - n.y, mx - n.x)) + math.random(-FISH_FOLLOW_RANDOM, FISH_FOLLOW_RANDOM)
|
||||||
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
|
end
|
||||||
|
|
||||||
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 (--[[love.mouse.isDown(1) or ]]fishgoals[fi]) then
|
||||||
x = x * math.sign(n.render.x - n.render.prevx)
|
x = x * math.sign(n.render.x - n.render.prevx)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -159,12 +155,6 @@ function love.update(dt)
|
||||||
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
|
|
||||||
e.speed = e.speed * 1.3
|
|
||||||
end
|
|
||||||
if n.dead then
|
|
||||||
e.speed = e.speed * 0.2
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
bench.stopBenchmark('update_fish_eases')
|
bench.stopBenchmark('update_fish_eases')
|
||||||
|
@ -190,19 +180,16 @@ function love.update(dt)
|
||||||
|
|
||||||
n.render.x = clamp(n.render.x, 0.05, 0.95)
|
n.render.x = clamp(n.render.x, 0.05, 0.95)
|
||||||
n.render.y = clamp(n.render.y, 0.1, 0.85)
|
n.render.y = clamp(n.render.y, 0.1, 0.85)
|
||||||
bench.stopBenchmark('update_fish_position')
|
|
||||||
|
|
||||||
bench.startBenchmark('update_fish_colission')
|
if fishgoals[fi] and frame % FISH_COLISSION_CHECK_FREQ == 0 then
|
||||||
if n.shortestfood and food[n.shortestfood] and frame % FISH_COLISSION_CHECK_FREQ == 0 then
|
local f = food[fishgoals[fi]]
|
||||||
local f = food[n.shortestfood]
|
|
||||||
if f then
|
if f then
|
||||||
local dist = math.abs(n.render.x - f.x) + math.abs(n.render.y - f.y)
|
local dist = math.abs(n.render.x - f.x) + math.abs(n.render.y - f.y)
|
||||||
|
|
||||||
if dist < FOOD_HITBOX then
|
if dist < FOOD_HITBOX then
|
||||||
table.remove(food, n.shortestfood)
|
table.remove(food, fishgoals[fi])
|
||||||
n.eattimer = FISH_FOOD_COOLDOWN
|
n.eattimer = FISH_FOOD_COOLDOWN
|
||||||
n.render.eattimer = 0
|
n.render.eattimer = 0
|
||||||
n.shortestfood = -1
|
|
||||||
|
|
||||||
if n.lifetime > FISH_AGE_MEDIUM then
|
if n.lifetime > FISH_AGE_MEDIUM then
|
||||||
n.size = 1
|
n.size = 1
|
||||||
|
@ -213,7 +200,7 @@ function love.update(dt)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
bench.stopBenchmark('update_fish_colission')
|
bench.stopBenchmark('update_fish_position')
|
||||||
|
|
||||||
bench.startBenchmark('update_fish_render')
|
bench.startBenchmark('update_fish_render')
|
||||||
if frame % FISH_RENDER_FREQ == 0 then
|
if frame % FISH_RENDER_FREQ == 0 then
|
||||||
|
@ -262,27 +249,12 @@ function love.update(dt)
|
||||||
n.render.swim = 0
|
n.render.swim = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
if not n.dead then
|
n.render.turndir = math.sign(n.render.x - n.render.prevx)
|
||||||
n.render.turndir = math.sign(n.render.x - n.render.prevx)
|
|
||||||
end
|
|
||||||
|
|
||||||
local m = n.eattimer < FISH_FOOD_HUNGRY and 1 or -1
|
local m = n.eattimer < FISH_FOOD_HUNGRY and 1 or -1
|
||||||
n.render.hungry = clamp(n.render.hungry + dt * m * 3, 0, 1)
|
n.render.hungry = clamp(n.render.hungry + dt * m * 3, 0, 1)
|
||||||
|
|
||||||
bench.stopBenchmark('update_fish_render')
|
bench.stopBenchmark('update_fish_render')
|
||||||
|
|
||||||
if n.eattimer <= FISH_FOOD_DEAD then
|
|
||||||
n.dead = true
|
|
||||||
|
|
||||||
local timeSinceDead = math.abs(n.eattimer - FISH_FOOD_DEAD)
|
|
||||||
n.render.y = n.render.y + timeSinceDead/5 * math.min(timeSinceDead, 1)
|
|
||||||
n.render.y = clamp(n.render.y, 0, 0.85)
|
|
||||||
if n.render.y == 0.85 then
|
|
||||||
n.render.deathanim = n.render.deathanim + dt
|
|
||||||
if n.render.deathanim > 1 then
|
|
||||||
table.remove(feesh, fi)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
bench.stopBenchmark('update_fish')
|
bench.stopBenchmark('update_fish')
|
||||||
bench.stopBenchmark('update')
|
bench.stopBenchmark('update')
|
||||||
|
@ -329,7 +301,7 @@ function love.draw()
|
||||||
-- shadow
|
-- shadow
|
||||||
bench.startBenchmark('render_shadow')
|
bench.startBenchmark('render_shadow')
|
||||||
for i, n in ipairs(feesh) do
|
for i, n in ipairs(feesh) do
|
||||||
love.graphics.setColor(1, 1, 1, n.render.y + 0.2 - n.render.deathanim)
|
love.graphics.setColor(1, 1, 1, n.render.y + 0.2)
|
||||||
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)
|
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)
|
||||||
end
|
end
|
||||||
bench.stopBenchmark('render_shadow')
|
bench.stopBenchmark('render_shadow')
|
||||||
|
@ -350,14 +322,14 @@ function love.draw()
|
||||||
if n.render.turndir == -1 then turn = 1 - turn; sizex = -1 end
|
if n.render.turndir == -1 then turn = 1 - turn; sizex = -1 end
|
||||||
|
|
||||||
local turnframe = math.floor(turn * (#sample.quads - 1)) + 1
|
local turnframe = math.floor(turn * (#sample.quads - 1)) + 1
|
||||||
if #sample.quads == turnframe then
|
if #sample.quads == 10 then
|
||||||
sizex = -1 * sizex
|
sizex = -1 * sizex
|
||||||
turnframe = 1
|
turnframe = 1
|
||||||
end
|
end
|
||||||
|
|
||||||
local frame = math.floor(n.render.swim * (#sample.quads - 1)) + 1
|
local frame = math.floor(n.render.swim * (#sample.quads - 1)) + 1
|
||||||
|
|
||||||
if turnframe ~= 1 and turnframe ~= #sample.quads then
|
if turnframe ~= 1 and turnframe ~= 10 then
|
||||||
anim = 'turn'
|
anim = 'turn'
|
||||||
frame = turnframe
|
frame = turnframe
|
||||||
end
|
end
|
||||||
|
@ -367,12 +339,6 @@ function love.draw()
|
||||||
frame = math.floor(n.render.eattimer * (#sample.quads - 1)) + 1
|
frame = math.floor(n.render.eattimer * (#sample.quads - 1)) + 1
|
||||||
end
|
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
|
local angle = n.render.angle
|
||||||
if angle > math.pi/2 then
|
if angle > math.pi/2 then
|
||||||
angle = angle - math.pi
|
angle = angle - math.pi
|
||||||
|
@ -398,9 +364,9 @@ function love.draw()
|
||||||
local sadsheet = fishsprite(size, true, anim)
|
local sadsheet = fishsprite(size, true, anim)
|
||||||
|
|
||||||
local alpha = n.render.hungry == 1 and 0 or 1
|
local alpha = n.render.hungry == 1 and 0 or 1
|
||||||
love.graphics.setColor(1, 1, 1, alpha - n.render.deathanim)
|
love.graphics.setColor(1, 1, 1, alpha)
|
||||||
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.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.setColor(1, 1, 1, n.render.hungry)
|
||||||
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.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)
|
love.graphics.setColor(1, 1, 1)
|
||||||
|
|
Loading…
Reference in a new issue