Bregalad wrote:
Okay, to check on wich metatile the player is, you need to do a 4-bit shiftright (division by 16) division while checking block solidity. But I didn't understand what you were saying with the remainder. It would tell the distance between the wall and the player ? By how miracle ?
The remainder are the bits you shifted out in the division. Instead of throwing them away, put them on another variable. Better yet, AND the player's coordinate with %00001111 to get the lower bits before you shift them off. Those 4 will tell you how far the player is in the block. Say we have a very smal level composed by 2 16x16 pixel blocks. The fist one is empty and the second is solid. The player is at position (8, 8) and tries to move 12 pixels to the right. That would place it at point (20, 8). You take the 20 and divide by 16, wich will result in 1, with 4 as remainder. Dividing the Y coordinate by 16 will result in 0. The position (1, 0) in the map is a solid block, meaning the player can not enter it. The number 4 (remainder) represents how many pixels in the block the player is. Since position 4 is the 5th pixel inside the solid block, if you subtract 5 from the player now you'll make sure it is as close to the solid block as possible, but remain at block (0, 0).
Quote:
Also, the collision detection isn't that simple. For all stuff I check 4 points, topleft, topright, bottomleft and bottomright. All 4 have to collid nothing, else the collision fail. If the player goes up, it is useless to check bottomleft and bottomright, as it is useless to check bottomright and topright when going left. So this add a lot of simplicity when the player/monster is going to a single direciton at time.
As you said, there is no need to check the top left or the bottom left points if you're moving right, it is a waste of time. A hit will never happen at the left if you're moving right. But yeah, my examples are a little simple. In a real case you'd do what I said to all points that need checking. So, when moving right and checking for problems in the X axis, you'll check if the topright or the bottomright points are inside a solid block. If either is, push the player back the ammount of pixels it's in (remainder + 1).
Then you check the Y axis. If you moved down, check the bottom left and bottom righ points. If any of them is inside a solid block, push the player up.
Quote:
I use that trick for the player, but not for ennemies, because their AI is made in a way it was simpler to do so. Also, I move the player 2 pixels, then 1 pixels, then 2 again, etc.... When moving of 2 pixels, I don't check for collision for the first pixel, so it should work fine with 2 pixel precision.
When the player moves diagonal, I check for horizontal and vertical deplacement separately and it works fine.
If your player moves so little at a time, why did you say you checked all the pixels from one point to the other?
Quote:
Maybe for 4 it would be decent, but for 8 or 16 it would be undecent.
The example I gave will work fine, as long as you move less or the same as the size of the blocks.
Quote:
That's probably what I hate about Mario Bross. When you entnter in a wall, you look ejected from it. I just have that system, to time your jump and move straightly it just suck in my opinion.
Also, the first MegaMan seems to push player and objects to the block to the right if he's in a solid block. It will ususally never happen, but glitches in the game make it happen.
When you kill a monster in a wall, if he throws an item, it will move to a block per frame.
As far as I remember you don't actually
see anything beeing pushed back, as this step should be done before rendering the sprites. At least in my engine, the player enters the wall and is pushed back all before rendering it's sprites, so you get the impression that it just stoped at the wall, no bouncing or anything.