1 decade ago by Robodude
Hi,
I just read through the "Introducing HTML5 Game Development" book and had a good time building the "Resident Raver" game they walk you through. I'm interested in expanding it to further learn the in's and outs of Impact.
One thing that sort of bugged me with the code was that he stored a lot of player centric stuff (like how many lives are remaining) in the main.js file. From a structural point, I would prefer to have the remaining lives within the player entity.
So I was able to get it working by making the following changes:
First, I added a 'lives' property to my player entity
Next, I modified the call back inside the player's kill() to include the amount of lives left.
And finally when respawning the player, I send over the amount of remaining lives when I spawn the new player entity.
Now this works fine, and I'm satisfied, but I'm worried about including more and more player options - such as ammunition & the deaths counter. It would seem that I would have to send a longer and longer list of settings properties when I spawn in the new entity.
Is there a better way of doing this?
Thanks,
John
I just read through the "Introducing HTML5 Game Development" book and had a good time building the "Resident Raver" game they walk you through. I'm interested in expanding it to further learn the in's and outs of Impact.
One thing that sort of bugged me with the code was that he stored a lot of player centric stuff (like how many lives are remaining) in the main.js file. From a structural point, I would prefer to have the remaining lives within the player entity.
So I was able to get it working by making the following changes:
First, I added a 'lives' property to my player entity
Next, I modified the call back inside the player's kill() to include the amount of lives left.
kill: function(){ this.deathSFX.play(); ig.game.respawnPosition = this.startPosition; var x = this.startPosition.x; var y = this.startPosition.y; ig.game.spawnEntity(EntityDeathExplosion, this.pos.x, this.pos.y, { callBack: this.onDeath(this.lives) } ); this.parent(); },
And finally when respawning the player, I send over the amount of remaining lives when I spawn the new player entity.
onDeath: function(lives){ ig.game.stats.deaths++; console.log("++++"); console.log(this.lives); lives--; if (lives <= 0){ ig.game.gameOver(); } else { ig.game.spawnEntity(EntityPlayer, ig.game.respawnPosition.x, ig.game.respawnPosition.y, {lives: lives}); } },
Now this works fine, and I'm satisfied, but I'm worried about including more and more player options - such as ammunition & the deaths counter. It would seem that I would have to send a longer and longer list of settings properties when I spawn in the new entity.
Is there a better way of doing this?
Thanks,
John