Advertisement
Guest User

enemy.js

a guest
Mar 29th, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ig.module(
  2.     'game.entities.enemy'
  3. )
  4. .requires(
  5.     'impact.entity'
  6. )
  7. .defines(function () {
  8.     EntityEnemy = ig.Entity.extend({
  9.         collides: ig.Entity.COLLIDES.PASSIVE,
  10.  
  11.         size: {x: 8, y: 12},
  12.  
  13.         maxVel: {x: 30, y: 400},
  14.         friction: {x: 300, y: 0},
  15.  
  16.         animSheet: new ig.AnimationSheet('media/gunter.png', 8, 12),
  17.  
  18.         init: function (x, y, settings) {
  19.             this.parent(x, y, settings);
  20.             this.addAnim('idle', 1, [0]);
  21.             this.addAnim('walking', 0.4, [0, 1]);
  22.         },
  23.  
  24.         flipped: false,
  25.         update: function () {
  26.             this.currentAnim.flip.x = this.flipped;
  27.  
  28.             // Set current anim based on velocity
  29.             if (this.vel.x < 0) {
  30.                 this.currentAnim = this.anims.walking;
  31.                 this.flipped = false;
  32.             } else if (this.vel.x > 0) {
  33.                 this.currentAnim = this.anims.walking;
  34.                 this.flipped = true;
  35.             } else {
  36.                 this.currentAnim = this.anims.idle;
  37.             }
  38.  
  39.             // Move towards player
  40.             var player = ig.game.getEntitiesByType('EntityPlayer')[0];
  41.             if (player) {
  42.                 if (this.pos.x > player.pos.x) {
  43.                     this.accel.x = -40;
  44.                 } else if (this.pos.x < player.pos.x) {
  45.                     this.accel.x = 40;
  46.                 }
  47.             }
  48.  
  49.             this.parent();
  50.         }
  51.     });
  52. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement