1 decade ago by ArcadeHype
I was just wondering if there is a way to create a base class such as "EntityEnemySkeleton" and then spawn different types of enemies such as "EntityAlien" or "EntityRobot" which would extend the "EntityEnemySkeleton" class allowing my "enemies" to inherit all the same kill, check and receivedamage methods that are defined in the base "EntityEnemySkeleton" class.
I tried the following but doesn't seem to work:
My game loads up fine but my entity doesn't appear and it doesn't appear in weltmeister either. Is there a way to accomplish this task and can weltmeister load entities that are sub-classed?
I tried the following but doesn't seem to work:
ig.module( 'game.entities.enemy' ).requires( 'impact.entity' ) .defines(function() { EntityEnemy = ig.Entity.extend({ size: {x:35 , y:62}, offset: {x:0, y:0}, maxVel: {x:100, y:100}, friction: {x:150, y:0}, speed:100, flip: false, //collision properties collides: ig.Entity.COLLIDES.PASSIVE, type: ig.Entity.TYPE.B, checkAgainst: ig.Entity.TYPE.A, init: function(x,y,settings){ this.parent(x,y,settings); }, update: function(){ //near an edge? return! if(!ig.game.collisionMap.getTile( this.pos.x + (this.flip ? +4 : this.size.x -4), this.pos.y + this.size.y + 1 )){ this.flip = !this.flip; } var xdir = this.flip ? -1 : 1; this.vel.x = this.speed * xdir; this.currentAnim.flip.x = this.flip; this.parent(); }, handleMovementTrace: function(res){ this.parent(res); //collision with a wall? return! if(res.collision.x){ this.flip = !this.flip; } }, check: function( other ) { other.receiveDamage( 10, this ); }, kill: function(){ this.parent(); ig.game.spawnEntity(EntityExplosion, this.pos.x, this.pos.y, {particles:30, colorOffset:1}); }, receiveDamage: function(value){ this.parent(value); if(this.health > 0){ ig.game.spawnEntity(EntityExplosion, this.pos.x, this.pos.y, {particles:10, colorOffset: 1}); } }, }); }); //end of enemy skeleton class ig.module( 'game.entities.alien' ).requires( 'impact.entity', 'game.entities.enemy' ) .defines(function() { EntityAlien = EntityEnemy.extend({ animSheet: new ig.AnimationSheet('media/alien_one.png', 35,62), init: function(){ this.addAnim('walk', .1, [0,1,2,3,4,5]); this.parent(); }, }); }); //end of alien class
My game loads up fine but my entity doesn't appear and it doesn't appear in weltmeister either. Is there a way to accomplish this task and can weltmeister load entities that are sub-classed?