Skip to content

Instantly share code, notes, and snippets.

@darkhog
Last active June 30, 2018 13:26
Show Gist options
  • Save darkhog/6c51a7aead2e185816fbb9f27da2f053 to your computer and use it in GitHub Desktop.
Save darkhog/6c51a7aead2e185816fbb9f27da2f053 to your computer and use it in GitHub Desktop.
SCRIPT-8
{
"0": {
"0": {
"0": 1
},
"1": {
"0": 1
},
"2": {
"0": 1
},
"3": {
"0": 1,
"1": 2
},
"4": {
"0": 1,
"1": 3
},
"5": {
"0": 1,
"1": 2
},
"6": {
"0": 1,
"1": 3
},
"7": {
"0": 1,
"1": 2
},
"8": {
"0": 1,
"1": 3,
"2": 5,
"3": 4
},
"9": {
"0": 1,
"1": 2,
"2": 5,
"3": 4
},
"10": {
"0": 1,
"2": 5,
"3": 4
},
"11": {
"0": 1,
"2": 5,
"3": 4
},
"12": {
"0": 1,
"2": 5,
"3": 4
},
"13": {
"0": 1,
"2": 5,
"3": 4
},
"14": {
"0": 1,
"2": 5,
"3": 4
},
"15": {
"0": 1
}
}
}
// title: sound test
initialState = {
bullets: [],
gap: 0,
actors: [{
name: 'ship',
x: 64,
y: 120,
sprite: 0
}]
}
playSong(0,true)
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--
//bullet collision
if (b.y<8) {
b.y=-1000
}
})
}
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, 'Score ', 0)
}
{
"0": [
"0c27"
],
"1": [
"0b05",
"2b06",
"4b05",
"6b04",
"7b04",
"9b05",
"11b06",
"13b05",
"15b04"
],
"2": [
"0e37",
"4e37",
"5d37",
"9e37",
"10f37",
"11f37",
"12f#37"
],
"3": [
"0e37",
"4e37",
"5d37",
"9e37",
"10d#37",
"11d#37",
"12d37"
],
"4": [
"0a37",
"3a37",
"8f#37",
"9f#27",
"10f#17",
"11f#07"
],
"5": [
"0g37",
"3g37",
"8e37",
"9e27",
"10e17",
"11e07"
]
}
{
"0": {
"0": 0
}
}
{
"0": [
" 0 ",
" 343 ",
" 343 ",
" 343 ",
" 34443 ",
" 34443 ",
" 34443 ",
" 34443 "
],
"1": [
" 0000",
" 002112",
" 0113223",
"01123333",
"11233444",
"12334455",
"23345566",
"23455677"
],
"2": [
"00000 ",
"111100 ",
"2111110 ",
"33222110",
"43333210",
"54433220",
"65544320",
"76654320"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment