Advertisement
Guest User

player.js

a guest
Mar 29th, 2013
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ig.module(
  2.     'game.entities.player'
  3. )
  4. .requires(
  5.     'impact.entity'
  6. )
  7. .defines(function () {
  8.     EntityPlayer = ig.Entity.extend({
  9.         collides: ig.Entity.COLLIDES.PASSIVE,
  10.  
  11.         // Hitbox size and offset, fine tuned for good collisions
  12.         size: {x: 6, y: 22},
  13.         offset: {x: 2, y: 0},
  14.        
  15.         maxVel: {x: 50, y: 400},
  16.         friction: {x: 300, y: 0},
  17.  
  18.         animSheet: new ig.AnimationSheet('media/player.png', 10, 22),
  19.  
  20.         init: function (x, y, settings) {
  21.             this.parent(x, y, settings);
  22.             // Add the animations
  23.             this.addAnim('idle', 1, [0]);
  24.             this.addAnim('run', 0.1, [1,2,3,4]);
  25.             this.addAnim('idleRun', 1, [1]);
  26.         },
  27.  
  28.         accelGround: 200,
  29.         accelAir: 100,
  30.         jump: 90,
  31.         flipped: false,
  32.         update: function () {
  33.             // Slower acceleration if in the air
  34.             var accel = this.standing? this.accelGround : this.accelAir;
  35.             if (ig.input.state('left')) {
  36.                 this.accel.x = -accel;
  37.                 this.flipped = true;
  38.             } else if (ig.input.state('right')) {
  39.                 this.accel.x = accel;
  40.                 this.flipped = false;
  41.             } else {
  42.                 this.accel.x = 0;
  43.             }
  44.  
  45.             if (ig.input.pressed('jump') && this.standing) {
  46.                 this.vel.y = -this.jump;
  47.             }
  48.  
  49.             // Handle animations
  50.             if (this.vel.x != 0) {
  51.                 this.currentAnim = this.anims.run;
  52.             } else {
  53.                 this.currentAnim = this.anims.idle;
  54.             }
  55.  
  56.             this.currentAnim.flip.x = this.flipped;
  57.  
  58.             this.parent();
  59.         },
  60.  
  61.         collideWith: function (other, axis) {
  62.             console.log('hey');
  63.         }
  64.     });
  65. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement