[java] bomberman collision

Started by
7 comments, last by bigbadboo 18 years, 8 months ago
I'm working on a bomberman clone which can be seen [ here ] and have a question about the player tile collision. At the moment the player sprite is 16 x 24. whereas the space the player can travel between tiles is 16 x 16. When the collision detection I'm using asks for the player height I specifically say its 16 instead of 24 so that the player can actually move around, with the head overlapping at the top. The problem is that movement is tricky and its hard to move between some tiles as the player has to be in the 'pixel perfect' position to actually fit through the tiles. If you play the game a bit you'll see what I mean. I can make it really easy to move between the tiles by specifying the player width and height to be around 14 pixels, however when I draw the sprite then it overlaps horizontally by 2 pixels and also the player can move 2 pixels to high. How should I go about making it easy for the player to move around but still draw the sprite correctly?
-----------------[ serafin studios ]
Advertisement
Well, don't let him move 1 pixel at a time, but each time he moves, he has to move like 4 pixels at a time (you'll smooth that out ofcourse).. That way he can quite easily move..
sorry maybe i wasn't too clear, I'm not bothered with the speed at which he moves at the moment, rather the fact that its very hard to fit between the tiles. or am I understanding you wrong?
-----------------[ serafin studios ]
I think you misunderstood me as well... He'll still move at the same speed, but even if you release the key after two pixels, he'll continue until he reaches the fourth.. That way, it should be quite easy to see/know when you can move in between the tiles.. :)
Well, there are two ways to address this.

1. The first option is an auto centering effect. When the player stops pressing a direction the avatar doesn't just stop, it determines which tile it is inside and only stops competely once centered. Obviously this changes the control a little, as you lose the judgement call required to make sure you are placed cleanly in a tile as the game does that for you. I actually prefer this.

2. The other option is to effectively curve the corners of your blocks, which is what Bomberman does. Notice that pushing into the corner of a solid tile actually sees the avatar slide around the corner a little. You'llbasically need to detect how close to the corner the player is when pushing against a solid block. The closer they are, the more you push them away from the center of that tile at a right angle.


Hmmm, I guess that might be a little hard to understand, it certainly isn't easy to explain but either one of those will solve the problem, it's a matter of preference.

Hope thats of some use.
Thanks for the quick replys guys im gona try some of this stuff and let you know what happens! :)
-----------------[ serafin studios ]
How about using a circle as the collision 'box' for the blocking tiles? So if a blocking tile is at x,y, then give it a radius of the box's width / 2, and then do collison using that radius. Basically each blocking tile is really a circle.
--------------------------A good discussion is like a miniskirt; Short enough to pertain interest and long enough to cover the subject..
Wouldnt that mean you would actually be able to move into the tile slightly at the edges because even though the collision for the tile is being handled as a circle, the tile image is essentially a square? I got it working though as a square, I used ghosted method #2. You can check it out in action here. what you think?
-----------------[ serafin studios ]
That works pretty good. Did you make use of any Java libraries to make this game?
--------------------------A good discussion is like a miniskirt; Short enough to pertain interest and long enough to cover the subject..

This topic is closed to new replies.

Advertisement