I’m currently programming a bomberman clone, you can see my progress at http://www.serafinstudios.com/bomberman.php if you’re interested. I was where I should be doing the collision detection. Should it all be done in one place, or should sprites take care of their own collision detection possibly in their update methods?
your code works, so you dont have to worry about much =)
i think the best rule of thumb is, do it all in one place if it doesnt end in a mess and you like it.
this is mostly the case when you have to differ between a few cases, in your case perhaps only
the bomberman-intersection with the blocks.
but if you add some things, like powerup, enemies (…) you will fastly see that it is much better
to manage to put the collison code up to the sprites.
btw: i really like your applet. but as a little suggestion/wish, it would be nice to have some “assistence”
when turning into another way along a block, because if you are not pixel perfect between two blocks,
your little avatar keeps running against the wall.
yea what I was thinking was to either make the collision box for the player smaller so its easier to fit through but always draw the sprite coorectly fitting in. I think this is possibly what they do in the original bomberman as it is possible in the originals for almost half of your head to touch flames and you still dont die. I’ll also be adding a little bit of help so it kinda guides you into the corner if you press a key to go into it. Thanks for your reply
For a collision suggesion:
Give bomberman a collision test every time you press a key to walk, and the enemies a collision test every timestep when their AIs tell them to move (if you make any). When a bomb explodes, have it check to see if anyone is nearby. This would be much more efficient than checking collision absolutely everywhere in the level. (and by only checking in a 3x3 grid around the characters – if you’re using a 2D array – you can make it even faster)
As for fixing the walking issue, I suggest having a little help that, as long as the player is not holding a movement button, will automatically call bomberman’s movement methods to make him go to the center of the nearest grid space. It is a subtle effect and works well in cases like this. (I made a Tetris clone and used that method)