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

BIN
assets/audio/sfx/chomp.ogg Normal file

Binary file not shown.

View file

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 28 KiB

View file

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View file

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View file

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

View file

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View file

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View file

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

View file

@ -20,6 +20,7 @@ FISH_FOOD_DEAD = -13
FISH_AGE_MEDIUM = 25 -- the age, in seconds, needed for a guppy to become a medium guppy
FISH_AGE_BIG = 65 -- see above, but for big
FISH_AGE_KING = 15 * 60 -- see above, but for king (15 minutes)
FISH_SIZE = 6 -- how many large guppies can you fit on the screen

View file

@ -2,11 +2,12 @@ require 'const'
local self = {}
function self.fish(x, y)
function self.fish(x, y, type)
type = type or 0
local fish = {
x = x,
y = y,
size = 0, -- 0 for small, 1 for medium, 2 for big, 3 for king
size = type, -- 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,

View file

@ -57,6 +57,8 @@ return function(feesh, spritescale, fishsprite)
size = 'big'
elseif n.size == 3 then
size = 'king'
elseif n.size == 4 then
size = 'carnivore'
end
local sheet = fishsprite(size, false, anim)

View file

@ -1,7 +1,11 @@
local moneysheets = {
'coin1', 'coin2', 'star', 'diamond', 'chest'
}
return function(money, sheets, spritescale)
local sw, sh = love.graphics.getDimensions()
for _,f in ipairs(money) do
local sheet = sheets['money' .. (f.type)]
local sheet = sheets[moneysheets[f.type]]
local x = mix(f.x * sw, sw / 9 * 8, ease.outCubic(f.collecttimer))
local y = mix(f.y * sh, HEADER_HEIGHT - 20, ease.outCubic(f.collecttimer))
local frame = math.floor((f.time%1) * #sheet.quads) + 1

View file

@ -16,7 +16,7 @@ local headerbuttons = {
cost = 100,
sprite = 'guppy',
openanim = 1,
open = true,
open = false,
closed = false,
func = function()
playSound('splash', 0.7, 0.8)
@ -28,7 +28,7 @@ local headerbuttons = {
sprite = 'food',
tier = foodtier,
openanim = 1,
open = true,
open = false,
closed = false,
func = function(self)
self.openanim = 0
@ -46,7 +46,7 @@ local headerbuttons = {
sprite = 'foodcount',
tier = foodcount,
openanim = 1,
open = true,
open = false,
closed = false,
func = function(self)
self.openanim = 0
@ -58,6 +58,17 @@ local headerbuttons = {
self.tier = foodcount
end
end
},
{
cost = 1000,
sprite = 'carnivore',
openanim = 1,
open = false,
closed = false,
func = function()
playSound('splash', 0.7, 0.8)
table.insert(feesh, constr.fish(math.random(), 0.3, 4))
end
}
}
@ -82,11 +93,14 @@ function self.load()
sheets.buttonopen = newAnimation(sprites['header/button_open'], sprites['header/button_open']:getWidth()/3, sprites['header/button_open']:getHeight())
sheets.money1 = newAnimation(sprites['money/coin1'], sprites['money/coin1']:getWidth()/10, sprites['money/coin1']:getHeight())
sheets.money2 = newAnimation(sprites['money/coin2'], sprites['money/coin2']:getWidth()/10, sprites['money/coin2']:getHeight())
sheets.coin1 = newAnimation(sprites['money/coin1'], sprites['money/coin1']:getWidth()/10, sprites['money/coin1']:getHeight())
sheets.coin2 = newAnimation(sprites['money/coin2'], sprites['money/coin2']:getWidth()/10, sprites['money/coin2']:getHeight())
sheets.star = newAnimation(sprites['money/star'], sprites['money/star']:getWidth()/10, sprites['money/star']:getHeight())
sheets.diamond = newAnimation(sprites['money/diamond'], sprites['money/diamond']:getWidth()/10, sprites['money/diamond']:getHeight())
sheets.chest = newAnimation(sprites['money/chest'], sprites['money/chest']:getWidth()/10, sprites['money/chest']:getHeight())
for i = 1, 2 do
table.insert(feesh, constr.fish(math.random(), math.random()))
table.insert(feesh, constr.fish(math.random(), math.random(), 0))
end
end
@ -108,6 +122,12 @@ function self.update(dt)
bench.startBenchmark('update_fish')
require('scenes.gameplay.update.fish')(feesh, dt, food, headerbuttons, money)
bench.stopBenchmark('update_fish')
if debug then
for _,b in ipairs(headerbuttons) do
b.open = true
end
end
end
function self.draw()
@ -162,6 +182,9 @@ function self.mousepressed(x, y, b)
if m.type == 1 then balance = balance + 15 end
if m.type == 2 then balance = balance + 35 end
if m.type == 3 then balance = balance + 40 end
if m.type == 4 then balance = balance + 200 end
if m.type == 5 then balance = balance + 2000 end
return
end
@ -188,7 +211,7 @@ function self.mousepressed(x, y, b)
if hovered then
if headerbuttons[i] and headerbuttons[i].open then
if balance >= headerbuttons[i].cost then
if balance >= headerbuttons[i].cost or debug then
headerbuttons[i].func(headerbuttons[i])
playSound('buttonclick')
balance = balance - headerbuttons[i].cost

View file

@ -32,6 +32,29 @@ 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.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(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
@ -51,7 +74,7 @@ return function(feesh, dt, food, headerbuttons, money)
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
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]
if f then
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