1 decade ago by sanity
I am currently having some trouble with getting my enemy entity to spawn on a timer after death. Currently when the zombie dies the timer will start and when i hits 0 the text displayed from the draw function respawns but the zombie/animation does not, and without that you cant damage the entity. Also i have figured out how to set global variables inside of the main.js and use them within my entities but, how do i do the opposite and use variables like the default health variable associated with entities? I have tried using .getEntityByName and .getEntitiesByType to pass the entity into a variable inside the main.js but i keep getting errors. if anyone can find a problem with my code or have a better way of doing it i would love to see an example.
zombie.js
Main.js
zombie.js
draw: function(){ var x = ig.system.width/2; var y = ig.system.height/2 - 20; this.statText.draw('Level: '+ig.game.zombielevel, x+45, y-30, ig.Font.ALIGN.CENTER); this.statText.draw('Health: '+this.health, x+45, y-20, ig.Font.ALIGN.CENTER); this.statText.draw('Attack: '+ig.game.zombieattack, x+45, y-10, ig.Font.ALIGN.CENTER); this.statText.draw('Defense: '+ig.game.zombiedefense, x+45, y, ig.Font.ALIGN.CENTER); this.statText.draw('Experience: '+ig.game.zombieexperience, x+45, y+10, ig.Font.ALIGN.CENTER); this.parent(); }, update: function(){ if(this.health > 2){ //This was just to see if i could get the timer to pause/unpause ig.game.deathtimer.pause(); }else if( this.health < 2 ){ ig.game.deathtimer.reset(); } this.parent(); }, kill: function(){ //Declare what you get on death ig.game.deathtimer.reset(); ig.game.playerexperience = ig.game.playerexperience + ig.game.zombieexperience; this.parent(); }
Main.js
update: function() { if( this.deathtimer.delta() >= 0 ){ ig.game.spawnEntity( EntityZombie, this.startPosition.x, this.startPosition.y ); this.deathtimer.reset(); this.parent(); } this.parent(); }