Last active
September 5, 2020 23:16
-
-
Save thykka/9483024913ee99a6fcbcce725b5b35e4 to your computer and use it in GitHub Desktop.
SCRIPT-8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
init = state => { | |
state.time = 0 | |
state.actors = [...createTickets(20), createPlayer()] | |
state.gameSpeed = 32; | |
} | |
function createPlayer() { | |
return { | |
id: 'player', | |
x: 0, | |
y: 120, | |
vx: 0, | |
vy: 0, | |
sprite: 32, | |
brighten: 1 | |
} | |
} | |
function createTickets(length) { | |
return [...Array.from({ length }, (_, i) => { | |
return { | |
id: 'ticket-' + i, | |
x: Math.random() * 120 | 0, | |
y: -8, | |
w: Math.random() / 2 + 0.25, | |
sprite: Math.random() * 4 | 0, | |
brighten: (-3 + Math.random() * 3) | 0 | |
} | |
})] | |
} | |
update = (state, input, elapsed) => { | |
state.delta = elapsed / 1000; | |
state.time += elapsed | |
updateTickets(state) | |
updatePlayer(state, input) | |
log(state.actors.length) | |
} | |
function updatePlayer(state, input) { | |
const player = state.actors.find(a => a.id === 'player'); | |
if(input.right) { | |
player.vx = player.vx + 0.4 | |
} | |
if(input.left) { | |
player.vx = player.vx - 0.4 | |
} | |
player.vx = clamp(player.vx * 0.816, -1.5, 1.5) | |
if(Math.abs(player.vx) < 0.25) { | |
player.vx = 0 | |
} | |
if(player.vx < 0) { | |
player.flipH = true; | |
} else if(player.vx > 0) { | |
player.flipH = false; | |
} | |
player.x += player.vx * state.delta * 100 | |
player.y += player.vy * state.delta * 100 | |
player.sprite = 32 + Math.floor(state.time / 30 * Math.abs(player.vx)) % 5 | |
} | |
function updateTickets(state) { | |
const tickets = state.actors.filter(a => a.id.indexOf('ticket') === 0); | |
tickets.forEach(ticket => { | |
ticket.x += Math.sin(ticket.w * state.time / 100) * ticket.w | |
ticket.y += (state.gameSpeed * state.delta * ticket.w * 4); | |
ticket.sprite = Math.floor(ticket.w * state.gameSpeed * state.time / 1000) % 4 | |
}) | |
// cleanup | |
state.actors = state.actors.filter(a => !a.id.indexOf('ticket') === 0 || a.y < 128) | |
if(state.actors.length < 20) { | |
state.actors.push(...createTickets(1)) | |
} | |
} | |
draw = state => { | |
clear() | |
drawActors(state) | |
drawPlayer(state) | |
} | |
function drawPlayer(state) { | |
const player = state.actors.find(a => a.id === 'player'); | |
sprite(player.x, player.y - 8, 16, player.brighten, player.flipH, player.flipV) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"iframeVersion": "0.1.280", | |
"lines": [ | |
88, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0 | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"0": [ | |
" ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 " | |
], | |
"1": [ | |
" ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 " | |
], | |
"2": [ | |
" ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 " | |
], | |
"3": [ | |
" ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 " | |
], | |
"16": [ | |
" ", | |
" 00 ", | |
" 00 ", | |
" 00 ", | |
" 0 ", | |
" 000 ", | |
" 00000 ", | |
" 00000 " | |
], | |
"17": [ | |
" ", | |
"0 00 0", | |
"0 00 0", | |
"0 00 0", | |
" 0 0 0 ", | |
" 00000 ", | |
" 0000 ", | |
" 0000 " | |
], | |
"18": [ | |
" 0 0 ", | |
" 0 00 0 ", | |
" 0 00 0 ", | |
" 0 000 ", | |
" 0 0 0 ", | |
" 0000 ", | |
" 0000 ", | |
" 0000 " | |
], | |
"32": [ | |
" 00000 ", | |
" 00000 ", | |
" 00000 ", | |
" 0000 ", | |
" 0 0 ", | |
" 0 0 ", | |
" 0 0 ", | |
" 0 0 " | |
], | |
"33": [ | |
" 00000 ", | |
" 00000 ", | |
" 00000 ", | |
" 0000 ", | |
" 0 0 ", | |
" 0 0 ", | |
" 0 0 ", | |
" 0 0 " | |
], | |
"34": [ | |
" 00000 ", | |
" 00000 ", | |
" 00000 ", | |
" 0000 ", | |
" 00 0 ", | |
" 0 0 ", | |
" 0 0 ", | |
" 0 " | |
], | |
"35": [ | |
" 00000 ", | |
" 00000 ", | |
" 00000 ", | |
" 0000 ", | |
" 0 0 ", | |
" 0 0 ", | |
" 0 ", | |
" 0 " | |
], | |
"36": [ | |
" 00000 ", | |
" 00000 ", | |
" 00000 ", | |
" 0000 ", | |
" 0 0 ", | |
" 0 0 ", | |
" 0 0 ", | |
" 0 " | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment