Skip to content

Instantly share code, notes, and snippets.

@gabrielflorit
Last active June 6, 2018 02:49
Show Gist options
  • Save gabrielflorit/a77202c92a3e90a9b4e2a191cfae23c0 to your computer and use it in GitHub Desktop.
Save gabrielflorit/a77202c92a3e90a9b4e2a191cfae23c0 to your computer and use it in GitHub Desktop.
SCRIPT-8
// title: Time-travel demo
initialState = {
actors: [
{
name: 'ghost',
x: 64,
y: 0,
dy: 0.6,
sprite: 1
},
{
name: 'mari',
x: 0,
y: 128 - 16,
dx: 1.5,
sprite: 0
},
]
}
drawActors = (state, fade) => {
state.actors.forEach(actor => {
sprite(actor.x, actor.y, actor.sprite, fade ? -4 : 0)
})
}
update = (state, input, elapsed) => {
// modify ghost
state.actors[0].y += state.actors[0].dy
if (state.actors[0].y >= 128 - 16) {
state.actors[0].dy = 0
}
// modify mario
if (input.right) {
state.actors[1].x += state.actors[1].dx
}
}
draw = state => {
clear()
range(16).forEach(i => {
sprite(i * 8, 128 - 8, 2)
})
drawActors(state)
}
{
"0": [
" 2220 ",
" 22222",
" 30370 ",
" 300330",
" 3000 ",
" 220331 ",
"03333352",
" 3 4 "
],
"1": [
" ",
" 2224 ",
" 222224 ",
"22002004",
"22072704",
"22222244",
"22222244",
"2 22 244"
],
"2": [
"22224224",
"23445445",
"24445445",
"24445445",
"24663224",
"22242445",
"24342345",
"36654665"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment