Big JM, I don't understand whay a check for columns (j) should not need to know anything about (i).
And the rows check doesn't seem to even be accessing an array, unless Java has really
: I guess it does. I think it looked weird to me because [s:1zcmstu8]usually I use temporary variables to access the 2D array:[/s:1zcmstu8] I'm not sure what I'm trying to say here
for(i = 0; i < 4; i++)
for(j = 0; j < 5; j++)
arr[ i ][ j ] = i * j;
I just tried changing Math.round to Math.floor. Changing it to floor did solve collision problems on the rightmost side of blocks, but the leftmost side is still having problems. In addition, changing to Math.floor caused the "magnet effect" when jumping and when moving left.
On the other hand, using Math.ceil did the exact opposite: it solve collision problems on the leftmost side, while the rightmost side experienced faulty collision. It also caused the "magnet effect" when the player makes contact with the ground and when the player moves right.
The problem is which ever way you round you will have a gap (It'll round over, ignoring the solid you were standing on to begin with, and still are), you need to check the collision of both
floor and ceil, as see if either one
is solid. (Later you'll also have to see if one is a death block, eg) It doesn't make sense to collide with only one
block if clearly the player is right between them.
The point on the player used for relative X/Y should be in the middle for this case. then floor will return the leftmostX or topmostY and ceil will return the rightmostX and topmostY.
The only problem with that is it'll say you're colliding with tiles on the ground even if you over lap them just a little (I don't remember if SMW does that or not, but it'll be bad if you were standing next to lava, eg)
Edit:Just remembered, SMW has a smaller bounding box, so you can overlap tiles without colliding with them (or standing on them) that's why you can stand next to a wall with Mario's face in it.
the results of floor() on the left point of the player (or actually a little more than the exact left)
the results of ceil() on the right most (or a little less than the exact right)
This is what I mean:
I don't know how big the bounding box actually is though in SMW. I used 20x20 for example.
It should check the left corner and right corner of the bounding box
In the third picture, the left edge is still barely on the block (a scenario you're having problems with collision with) I guess you'd floor both points. I'm trying to illustrate checking four corner points instead of one.
Like in Big JM's example,
since at least the right point is on a solid block, the player is standing on it (though it's also standing on whatever is under the other one, in this case air, but it could be lava, eg)