I'm playing around with a bomberman clone to learn game-developement.
So far I've done tiles, movement, collision detection, and item pickup. I also have pseudo bombplacing (just graphics and collision, no real functionality).
I've made a jsFiddle of the game with the functionality I currently have. The code in the fiddle is very ugly though. Scroll past the map and you find how I place bombs.
Anyway, what I would like to do is an object, that has the general information about bombs like:
function Bomb(){ this.radius = player.bombRadius; this.placeBomb = function (){ if(player.bombs != 0){ // place bomb } } this.explosion = function (){ // Explosion } } I don't really know how to fit it into the code though. Everytime I place a bomb, do I do var bomb = new Bomb(); or do i need to constantly have that in the script to be able to access it.
How does the bomb do damage? Is it as simple as doing X,Y in all directions until radius runs out or object stops it? Can I use something like setTimeout(bomb.explosion, 3000) as timer?
Any help is appreciated, be it a simple explanation of the theory or code examples based on the fiddle. When I tried the object way it breaks the code.
Update: I now place bombs, and after a certain amount of time delete it depending on the position I placed it. But if I place a bomb before the first bomb explodes it only deletes one of them (obviously since bombX and bombY has changed since the first was placed).
Now i need to know how to fix this issue, maybe create a new array with all of the bomb positions? What's the best way of doing this?
Current code:
function placeBomb(){ if(placebomb && player.bombs != 0){ map[player.Y][player.X].object = 2; bombX = player.X; bombY = player.Y; placebomb = false; player.bombs--; setTimeout(explode, 3000); } } function explode(){ alert('BOOM!'); delete map[bombY][bombX].object; player.bombs++; }