Last active
August 29, 2015 14:13
-
-
Save Kirkman/fc53eac2c6818604022d to your computer and use it in GitHub Desktop.
Sample scrolling routine. Uses frame.scrollCircular() method.
This file contains 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
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