Added screen shake to the siren

This commit is contained in:
2024-12-02 13:28:31 -06:00
parent ddea65d995
commit 47a5e8e789
3 changed files with 25 additions and 4 deletions

View File

@@ -2,10 +2,10 @@ require 'globals'
local Display = require 'src.display'
local GameCore = require 'src.core.game_core'
local flux = require 'packages.flux'
local timer = require 'packages.timer'
local display
local core
@@ -13,11 +13,12 @@ function love.load()
math.randomseed(os.time())
display = Display.new(VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
core = GameCore.new()
end
function love.update(dt)
timer.update(dt)
flux.update(dt)
core:update(dt)
end

View File

@@ -1,4 +1,5 @@
local gamera = require 'packages.gamera'
local vector = require 'packages.vector-light'
local Camera = {}
Camera.__index = Camera
@@ -9,7 +10,11 @@ Camera.__index = Camera
function Camera.new(worldWidth, worldHeight)
local self = setmetatable({}, Camera)
self.camera = gamera.new(0, 0, worldWidth, worldHeight)
local px, py = VIRTUAL_WIDTH / 2, VIRTUAL_HEIGHT / 2
self.camera = gamera.new(0 - px, 0 - py, worldWidth + (2 * px), worldHeight + (2 * py))
local x, y = self.camera:getPosition()
self.target = { x = x, y = y }
return self
end
@@ -29,7 +34,14 @@ end
--- @param y (number)
function Camera:moveTo(x, y)
-- TODO: Smoothing function
self.target = { x = x, y = y }
self.camera:setPosition(x, y)
end
function Camera:shake(intensity)
local t = 1 - intensity
local vx, vy = vector.randomDirection(math.exp(t * 5))
self.camera:setPosition(self.target.x + vx, self.target.y + vy)
end
return Camera

View File

@@ -1,6 +1,7 @@
local LoveNode = require 'src.utils.love_node'
local vector = require 'packages.vector-light'
local random = require 'src.utils.random'
require 'src.utils.math'
local Siren = {}
@@ -35,6 +36,13 @@ function Siren:update(dt)
self.pos = self:_findSpawnPoint()
elseif self.distanceToPlayer < self.stats.maxEffectiveRadius then
-- Shake screen
self.game.camera:shake(
math.maprange(
self.distanceToPlayer,
self.stats.minEffectiveRadius, self.stats.maxEffectiveRadius,
0, 1
)
)
end
end