Skip to content

Instantly share code, notes, and snippets.

@thykka
Created July 22, 2020 21:28
Show Gist options
  • Select an option

  • Save thykka/117d5ff23f36bdb9f58001242aa20575 to your computer and use it in GitHub Desktop.

Select an option

Save thykka/117d5ff23f36bdb9f58001242aa20575 to your computer and use it in GitHub Desktop.
SCRIPT-8
const SP_TOPS = [0, 1, 2];
const SP_BOTTOMS = [16, 17, 18];
init = S => {
S.player = {
x: 32,
y: 32,
topSprite: 1,
bottomSprite: 2,
shade: 0,
flip: false
}
}
update = (S, input, elapsed) => {
if(input.aPressed) S.isEditing = !S.isEditing;
if(S.isEditing) {
if(input.bPressed) S.focusBottom = !S.focusBottom;
if(input.rightPressed) {
if(S.focusBottom) {
S.player.bottomSprite = (S.player.bottomSprite + 1) % SP_BOTTOMS.length;
} else {
S.player.topSprite = (S.player.topSprite + 1) % SP_TOPS.length;
}
}
else if(input.leftPressed) {
if(S.focusBottom) {
S.player.bottomSprite = (S.player.bottomSprite + SP_BOTTOMS.length - 1) % SP_BOTTOMS.length;
} else {
S.player.topSprite = (S.player.topSprite + SP_TOPS.length - 1) % SP_TOPS.length;
}
}
log('editing')
}
}
draw = S => {
clear();
drawPlayer(S.player)
if(S.isEditing) drawEditHints(S);
}
function drawEditHints(S) {
const x = S.player.x - 5;
const y = S.player.y + (S.focusBottom ? 4 : -4)
print(x, y, '<', 4)
print(x + 14, y, '>', 4)
}
function drawPlayer({ x, y, topSprite, bottomSprite, shade = 0, flip = false }) {
const spriteTop = SP_TOPS[topSprite];
const spriteBottom = SP_BOTTOMS[bottomSprite];
sprite(x, y - 4, spriteTop, -shade, flip, false);
sprite(x, y + 4, spriteBottom, -shade, flip, false);
}
{
"iframeVersion": "0.1.280",
"lines": [
56,
0,
0,
0,
0,
0,
0,
0
]
}
{
"0": [
" 222 ",
" 222 ",
" 222 ",
" 222 ",
" 12221 ",
"2122112 ",
"2111112 ",
"2111112 "
],
"1": [
" 222 ",
" 222 ",
" 222 ",
" 222 ",
" 12221 ",
"1112111 ",
"1111111 ",
"1111111 "
],
"2": [
" 222 ",
" 222 ",
" 222 ",
" 222 ",
" 12221 ",
"2122212 ",
"2112112 ",
"2111112 "
],
"16": [
"2111112 ",
"2111112 ",
"2555552 ",
" 55555 ",
" 55 55 ",
" 55 55 ",
"666 666 ",
" "
],
"17": [
"2111112 ",
"2111112 ",
"2111112 ",
" 55555 ",
" 55 55 ",
" 55 55 ",
"666 666 ",
" "
],
"18": [
"2222222 ",
"2555552 ",
"2 555 2 ",
" 2 2 ",
" 2 2 ",
" 2 2 ",
" 66 66 ",
" "
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment