Last active
April 21, 2020 09:31
-
-
Save bnolan/faa429dffaac1f1be90b103a502df60c to your computer and use it in GitHub Desktop.
Snake for vidscreen in cryptovoxels
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
let x, y, xd, yd, z | |
feature.on('click', e => { | |
reset() | |
}) | |
function reset () { | |
x = 32 | |
y = 32 | |
xd = 1 | |
yd = 0 | |
for (z = 0 ; z < feature.screenWidth * feature.screenHeight * 3; z++) { | |
feature.screen[z] = 0 | |
} | |
} | |
function died () { | |
reset() | |
} | |
feature.on('frame', e => { | |
// Draw random background noise | |
for (z = 0 ; z < 100; z++) { | |
let i = Math.floor(Math.random() * 64 * 64) * 3 | |
let r = Math.random() * 128 | |
feature.screen[i + 0] = r | |
} | |
// Move the head | |
x += xd | |
y += yd | |
// Hit the edge of the screen | |
if (x >= feature.screenWidth || x <= 0 || y >= feature.screenHeight || y <= 0) { | |
died() | |
} | |
// Get position into the screen array | |
let i = (y * 64 + x) * 3 | |
// Hit my tail | |
if (feature.screen[i + 1] > 0) { | |
died() | |
} | |
// Set green + blue | |
feature.screen[i + 1] = 255 | |
feature.screen[i + 2] = 128 | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment