Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ig.module(
- 'game.entities.enemy'
- )
- .requires(
- 'impact.entity'
- )
- .defines(function () {
- EntityEnemy = ig.Entity.extend({
- collides: ig.Entity.COLLIDES.PASSIVE,
- size: {x: 8, y: 12},
- maxVel: {x: 30, y: 400},
- friction: {x: 300, y: 0},
- animSheet: new ig.AnimationSheet('media/gunter.png', 8, 12),
- init: function (x, y, settings) {
- this.parent(x, y, settings);
- this.addAnim('idle', 1, [0]);
- this.addAnim('walking', 0.4, [0, 1]);
- },
- flipped: false,
- update: function () {
- this.currentAnim.flip.x = this.flipped;
- // Set current anim based on velocity
- if (this.vel.x < 0) {
- this.currentAnim = this.anims.walking;
- this.flipped = false;
- } else if (this.vel.x > 0) {
- this.currentAnim = this.anims.walking;
- this.flipped = true;
- } else {
- this.currentAnim = this.anims.idle;
- }
- // Move towards player
- var player = ig.game.getEntitiesByType('EntityPlayer')[0];
- if (player) {
- if (this.pos.x > player.pos.x) {
- this.accel.x = -40;
- } else if (this.pos.x < player.pos.x) {
- this.accel.x = 40;
- }
- }
- this.parent();
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement