🔒 Locked
[java] bomberman collision
Advertisement
Original Post
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?
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.
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.
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?
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement