-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshake.lua
31 lines (25 loc) · 842 Bytes
/
shake.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
local noise = love.math.noise
local function update(s, dt, camera)
if s.remaining < 0 then return end
local k = s.remaining / s.duration
local x = (noise(s.seed+0, s.remaining * s.freq) - 0.5) * 2
local y = (noise(s.seed+1, s.remaining * s.freq) - 0.5) * 2
local angle = (noise(s.seed+2, s.remaining * s.freq) - 0.5) * 2
local d = s.magnitude * k
x, y = x * d, y * d
angle = angle * s.rotationMagnitude
camera.cx, camera.cy = camera.cx + x, camera.cy + y
camera.angle = camera.angle + angle
s.remaining = s.remaining - dt
end
local class = { update = update }
class.__index = class
local function new(dist, rot, time, freq)
return setmetatable({
seed = math.random() * 1000,
remaining = time, duration = time,
freq = freq,
magnitude = dist, rotationMagnitude = rot
}, class)
end
return { new = new, class = class }