Skip to content

Instantly share code, notes, and snippets.

@gabrielflorit
Last active June 28, 2018 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrielflorit/d20720dd73169c04b53f9f22f3ebf178 to your computer and use it in GitHub Desktop.
Save gabrielflorit/d20720dd73169c04b53f9f22f3ebf178 to your computer and use it in GitHub Desktop.
SCRIPT-8
// title: sound test
initialState = {
bullets: [],
gap: 0,
actors: [{
name: 'ship',
x: 64,
y: 120,
sprite: 0
}]
}
update = (state, input, elapsed) => {
const ship = state.actors.find(d => d.name === 'ship')
state.gap--
// fire new bullet
if (input.a && state.gap <= 0) {
state.bullets.push({ x: ship.x + 4, y: 120 })
state.gap = 8
playPhrase(0)
}
// move ship
if (input.left && ship.x > 0) ship.x--
if (input.right && ship.x < 120) ship.x++
// move bullets
state.bullets.forEach(b => {
b.y--
})
}
const drawActor = (actor, fade) => {
sprite(actor.x, actor.y, actor.sprite)
}
drawActors = (state, fade) => {
state.actors.forEach(actor => drawActor(actor, fade))
}
draw = state => {
clear()
drawActors(state)
rectStroke(0, 0, 128, 128, 6)
state.bullets.forEach(b => {
circFill(b.x, b.y, 1, 0)
})
print(2, 2, 'Press A to fire', 0)
}
{
"0": [
"0c27"
]
}
{
"0": [
" 0 ",
" 343 ",
" 343 ",
" 343 ",
" 34443 ",
" 34443 ",
" 34443 ",
" 34443 "
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment