Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample scrolling routine. Uses frame.scrollCircular() method.
function gamePlay() {
player.sprite = new Sprite.Profile("girl-walking", bgFrame, 18, 9, 'e', 'stand');
// Mask the sprite. 219 = solid block. 2 = green
maskFrame( player.sprite.frame, ascii(219), 2 );
player.sprite.frame.draw();
var userInput = '';
while( ascii(userInput) != 13 ) {
userInput = console.getkey(K_UPPER | K_NOCRLF);
// User has pushed a key, but don't anything
// unless the sprite is allowed to move.
if ( player.sprite.canMove() ) {
if ( userInput == KEY_LEFT ) {
if (player.sprite.bearing != 'w') {
player.sprite.turnTo('w');
}
bgFrameBot.scrollCircular(-1,0);
bgFrameMid.scrollCircular(-2,0);
bgFrameTop.scrollCircular(-3,0);
}
else if ( userInput == KEY_RIGHT ) {
if (player.sprite.bearing != 'e') {
player.sprite.turnTo('e');
}
bgFrameBot.scrollCircular(1,0);
bgFrameMid.scrollCircular(2,0);
bgFrameTop.scrollCircular(3,0);
}
if ( userInput == KEY_LEFT || KEY_RIGHT ) {
// update lastMove attribute manually
// so I can use sprite.canMove()
player.sprite.lastMove = system.timer;
if ( player.sprite.position == 'walk' ) {
player.sprite.position = 'stand';
player.sprite.frame.draw();
Sprite.cycle();
}
else if ( player.sprite.position == 'stand' ) {
player.sprite.position = 'walk';
player.sprite.frame.draw();
Sprite.cycle();
}
}
Sprite.cycle();
} // if player.sprite.canMove
} // end while
} // gamePlay()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment