Added screen shake to the siren
This commit is contained in:
7
main.lua
7
main.lua
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user