Jan Willem's screenshake formula
Jan from Vlambeer tweeted his formula for implementing screenshake, a popular technique in indie games to achieve juiciness.
In pseudo-code:
view_xview = viewx + random(shake) - shake/2
view_yview = viewy + random(shake) - shake/2
if shake > 0:
shake -= 1
else:
shake = 0
if shake > 10:
shake *= 0.9
In PICO-8 it translates to:
function draw_screenshake()
local shake_x = rnd(shake) - shake/2
local shake_y = rnd(shake) - shake/2
-- -0.5 instead of -1 due to pico8 low-res
shake = max(shake - 0.5, 0)
if shake > 10 then
shake *= 0.9
end
camera(shake_x, shake_y)
end