Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- keyStack: [],
- /******************************************8
- * Update
- ******************************************/
- update: function()
- {
- // remove all keys from the stack that are not being held down anymore
- for( var i = this.keyStack.length; i--; ) {
- if( !ig.input.state(this.keyStack[i]) ) {
- this.keyStack.splice(i, 1);
- }
- }
- var idleSpeed = 120;
- var fastSpeed = 150;
- var backSpeed = 80;
- if( ig.input.state('upArrow') ){
- this.keyStack.push('upArrow');
- }
- else if ( ig.input.state('downArrow') ){
- this.keyStack.push('downArrow');
- }
- if( ig.input.state('leftArrow') ){
- this.keyStack.push('leftArrow');
- }
- else if( ig.input.state('rightArrow') ){
- this.keyStack.push('rightArrow');
- }
- else{
- this.vel.x = idleSpeed;
- this.currentAnim = this.anims.idle;
- this.lastKey = 'shoot';
- }
- // get the key from the top of the stack
- var lastKey = this.keyStack[this.keyStack.length-1];
- switch (lastKey)
- {
- case 'shoot':
- ig.game.spawnEntity(EntityBullet, this.pos.x + 44, this.pos.y +5, {flip:this.flip});
- break;
- case 'upArrow':
- this.vel.y = -idleSpeed;
- this.accel.x = this.speed;
- this.currentAnim = this.anims.bankLeft;
- break;
- case 'downArrow:':
- this.vel.y = idleSpeed;
- this.accel.x = this.speed;
- this.currentAnim = this.anims.bankRight;
- break;
- case 'leftArrow':
- this.vel.x = backSpeed;
- break;
- case 'rightArrow':
- this.vel.x = fastSpeed;
- break;
RAW Paste Data