Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public update()
- {
- if (this.Moving) {
- // updates coordinates
- this.updatePosition();
- // if I made a movement longest than the STEP_SIZE I fix position to be oldPosition + STEP_SIZE,
- // I set sprite in idle mode and immediatly call game.update that will get next action and make
- // the sprite moving again if there's some action to do
- if ((Math.abs(this.Position.x - this.oldPosition.x) > Configuration.STEP_SIZE_W) ||
- (Math.abs(this.Position.y - this.oldPosition.y) > Configuration.STEP_SIZE_H)) {
- this.fixPosition();
- }
- } else {
- var nextAction = this.getNextAction();
- switch(nextAction)
- {
- case 'left':
- {
- this.goLeft();
- break;
- }
- case 'right':
- {
- this.goRight();
- break;
- }
- case 'up':
- {
- this.goUp();
- break;
- }
- case 'down':
- {
- this.goDown();
- break;
- }
- default:
- {
- this.idle();
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement