carnivore

This commit is contained in:
jill 2021-01-25 17:48:31 +03:00
parent 3b70bf9b5d
commit 57fa26dfb7
Signed by: oat
GPG key ID: DD83A9617A252385
14 changed files with 106 additions and 28 deletions

View file

@ -32,26 +32,49 @@ return function(feesh, dt, food, headerbuttons, money)
if n.eattimer <= 0 and not n.dead 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
if n.size == 4 then -- carnivore
if n.shortestfood and feesh[n.shortestfood] then
local f = feesh[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
for i,f in ipairs(feesh) do
if f.size == 0 then
local dist = math.sqrt(math.pow(math.abs(f.render.x - n.render.x), 2) + math.pow(math.abs(f.render.y - n.render.y), 2))
if dist < mindist then
mindist = dist
minfood = i
end
end
end
if minfood ~= 0 then
n.shortestfood = minfood
end
end
else
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
if minfood ~= 0 then
n.shortestfood = minfood
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
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)
@ -102,6 +125,8 @@ return function(feesh, dt, food, headerbuttons, money)
if n.size > 0 then
local type = 2
if n.size == 1 then type = 1 end
if n.size == 3 then type = 3 end
if n.size == 4 then type = 4 end
table.insert(money, constr.money(n.render.x, n.render.y, type))
end
end
@ -123,13 +148,27 @@ return function(feesh, dt, food, headerbuttons, money)
bench.stopBenchmark('update_fish_position')
bench.startBenchmark('update_fish_colission')
if n.shortestfood and food[n.shortestfood] and frame % FISH_COLISSION_CHECK_FREQ == 0 then
local f = food[n.shortestfood]
if f then
if n.size == 4 then
if n.shortestfood and feesh[n.shortestfood] and frame % FISH_COLISSION_CHECK_FREQ == 0 and not n.dead then
local f = feesh[n.shortestfood]
local dist = math.abs(n.render.x - f.render.x) + math.abs(n.render.y - f.render.y)
if dist < FOOD_HITBOX then
playSound('chomp', 1, 1 + math.random() * 0.1 - 0.05)
table.remove(feesh, n.shortestfood)
n.eattimer = FISH_FOOD_3_COOLDOWN
n.render.eattimer = 0
n.shortestfood = -1
end
end
else
if n.shortestfood and food[n.shortestfood] and frame % FISH_COLISSION_CHECK_FREQ == 0 and not n.dead then
local f = food[n.shortestfood]
local dist = math.abs(n.render.x - f.x) + math.abs(n.render.y - f.y)
if dist < FOOD_HITBOX then
playSound('slurp')
playSound('slurp', 1, 1 + math.random() * 0.1 - 0.05)
table.remove(food, n.shortestfood)
local cooldowns = {FISH_FOOD_1_COOLDOWN, FISH_FOOD_2_COOLDOWN, FISH_FOOD_3_COOLDOWN}
@ -158,6 +197,14 @@ return function(feesh, dt, food, headerbuttons, money)
headerbuttons[3].open = true
headerbuttons[3].openanim = 0
end
if not headerbuttons[4].open and not headerbuttons[4].closed then
headerbuttons[4].open = true
headerbuttons[4].openanim = 0
end
end
if n.lifetime > FISH_AGE_KING and n.size == 2 then
n.size = 3
playSound('grow')
end
end
end