1 decade ago by wytshadow
I would like for my enemy to idle in the last direction he was facing, but i'm not exactly sure where to place that code and what verbage to use. Here is the code i have so far...
i know i want something like "if last movement was ig.ai.ACTION.MoveLeft then use this.current.Anim = this.anims.idleleft;" I'm just not sure where to put it and what exact words i would use.
ig.module( 'game.entities.smartguy' ) .requires( 'impact.entity', 'plugins.ai' ) .defines(function(){ EntitySmartguy = ig.Entity.extend({ animSheet: new ig.AnimationSheet( 'media/enemy_infantry_sprite_sheet.png', 50, 50 ), size: {x: 25, y:38}, offset: {x: 12, y: 8}, speed: 30, type: ig.Entity.TYPE.B, checkAgainst: ig.Entity.TYPE.A, collides: ig.Entity.COLLIDES.PASSIVE, init: function( x, y, settings ) { this.addAnim('idle', 1, [27]); this.addAnim('idleleft', 1, [25]); this.addAnim('idleright', 1, [24]); this.addAnim('idleup', 1, [26]); this.addAnim('down', 0.15, [27,22,23]); this.addAnim('left', 0.15, [25,16,17]); this.addAnim('right', 0.15, [24,18,19]); this.addAnim('up', 0.15, [26,20,21]); this.addAnim('shootidledown', 0.05, [14,15]); this.addAnim('shootidleleft', 0.05, [25,10,11]); this.addAnim('shootidleright', 0.05, [24,8,9]); this.addAnim('shootidleup', 0.05, [26,12,13]); ai = new ig.ai(this); this.parent( x, y, settings ); }, update: function() { /* let the artificial intelligence engine tell us what to do */ var action = ai.getAction(this); /* listen to the commands with an appropriate animation and velocity */ switch(action){ case ig.ai.ACTION.Rest: this.currentAnim = this.anims.idle; this.vel.x = 0; this.vel.y = 0; break; case ig.ai.ACTION.MoveLeft : this.currentAnim = this.anims.left; this.vel.x = -this.speed; break; case ig.ai.ACTION.MoveRight : this.currentAnim = this.anims.right; this.vel.x = this.speed; break; case ig.ai.ACTION.MoveUp : this.currentAnim = this.anims.up; this.vel.y = -this.speed; break; case ig.ai.ACTION.MoveDown : this.currentAnim = this.anims.down; this.vel.y = this.speed; break; case ig.ai.ACTION.Attack: this.currentAnim = this.anims.shootidledown; this.vel.x = 0; this.vel.y = 0; ig.game.getEntitiesByType('EntityPlayer')[0].receiveDamage(0,this); break; /* use the defaults if no command is send*/ default : this.currentAnim = this.anims.idle; this.vel.x = 0; this.vel.y = 0; break; } this.parent(); } }); });
i know i want something like "if last movement was ig.ai.ACTION.MoveLeft then use this.current.Anim = this.anims.idleleft;" I'm just not sure where to put it and what exact words i would use.