Skip to content

Instantly share code, notes, and snippets.

@gabrielflorit
Last active March 17, 2020 21:46
Show Gist options
  • Save gabrielflorit/2251ac87a0e295839b3a450937257e46 to your computer and use it in GitHub Desktop.
Save gabrielflorit/2251ac87a0e295839b3a450937257e46 to your computer and use it in GitHub Desktop.
SCRIPT-8
// title: replay setup
// This demonstrates how to setup a cassette so you can see
// your actors past and present.
// All you need to do: create an actors array in state,
// and give each actor a unique string id.
// That's it. Now when you hit PAUSE, you'll see the actors
// under the timeline. Click the actor button to see the
// past and future.
init = state => {
state.actors = [
{
id: 'ball',
x: 10,
y: 64,
dx: 1,
dy: 1,
sprite: 0
}
]
}
update = (state, input, elapsed) => {
const ball = state.actors.find(actor => actor.id === 'ball')
// Adjust velocity
if (input.downPressed) ball.dy += 0.5
if (input.upPressed) ball.dy -= 0.5
if (input.leftPressed) ball.dx -= 0.5
if (input.rightPressed) ball.dx += 0.5
// Bounce off edges
if (ball.x <= 0 || ball.x >= 120) {
ball.dx *= -1
}
if (ball.y <= 0 || ball.y >= 120) {
ball.dy *= -1
}
// Move ball
ball.x += ball.dx
ball.y += ball.dy
}
draw = state => {
clear()
drawActors(state)
}
{
"iframeVersion": "0.1.273",
"lines": [
50,
0,
0,
0,
0,
0,
0,
0
]
}
{
"0": [
" 000000 ",
"00000000",
"00000000",
"00000000",
"00000300",
"00000300",
"00033300",
" 000000 "
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment