-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshake.lua
More file actions
37 lines (28 loc) · 667 Bytes
/
shake.lua
File metadata and controls
37 lines (28 loc) · 667 Bytes
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
32
33
34
35
36
37
local Shake = {}
Shake.growth = 5
Shake.amplitude = 3
Shake.frequency = 250
local amount
local time
function Shake.reset()
amount = 1
time = 0
end
function Shake.update(dt)
amount = math.max(1, amount ^ 0.9)
time = time + dt
end
function Shake.more(growth)
amount = amount + growth
end
function Shake.preDraw()
local shakeFactor = Shake.amplitude * math.log(amount)
local waveX = math.sin(time * Shake.frequency)
local waveY = math.cos(time * Shake.frequency)
love.graphics.push()
love.graphics.translate(shakeFactor * waveX, shakeFactor * waveY)
end
function Shake.postDraw()
love.graphics.pop()
end
return Shake