The issue I'm having:
How my collision is handled.
Since Java executes methods in a code block by the order they were written in, my method is choosing to favor 1 or the other of the If and Else statements that are used to handle my players movement.
I had that problem one time, too. You can reverse the order of your code by using constructs like this:
1 2 3 4 5 6 7 8
| do { } while(expression);
{ } if(otherExpression); |
I came across a issue regarding If and Else statements and how they're executed.
If statements work exactly the way they are supposed to. Same for while loops. (Didn't you make a topic about those, too?) You need to learn to debug your own code. Use debuggers and System.out.println(), debug graphics, or logs to diagnose problems.
That doesn't reverse the order of your code.
Also, your if statement is bizarre. Please note this is valid syntax:
And this is also valid syntax:
Putting one on the same line of the other doesn't do anything.
Also note that your if doesn't do anything, it checks for condition and then no-ops. These are all equivalent:
1 2 3 4 5 6 7 8
| if ( condition );
if ( condition ) ;
if ( condition ) {
} |
Now that we have that cleared up, to the question at hand!
Given your experience I'll explain a simple solution, because in reality collision detection/resolution is a fairly complicated problem, and difficult to get right.
If you have two entities that intersect, find the "penetration" distance for all sides (TBRL). Find the smallest positive penetration distance and adjust that side only, this will correct the positions.
There are tons of problems with this method of course, the entities could be moving too fast and pass through each other. Not only that, if they're moving fast enough the one entity could appear on the other side of an entity due to its quick speed and the opposite adjustment will occur. You could avoid this problem by taking velocity into account (only check for bottom collisions if the entity is moving down, etc). You could avoid all of these problems by choosing smart fixed time steps and maximum velocities.
I hope this helps.