I don't know if there's a platform engine already, but it's not too hard to make. Since you said you were having problems with physics, here's some pseudocode (adapted from my game, may have bugs):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
| class Character { int x; int y; int vx; int vy;
boolean leftCollision = false; boolean rightCollision = false; boolean bottomCollision = false; boolean topCollision = false;
void processPhysics() { if(vx > 0 && !rightKeyPressed) vx -= 0.025; else if(vx < 0 && !leftKeyPressed) vx += 0.025; if(!bottomCollision) vy -= 0.050; double maxX = x + vx; double maxY = y + vy; double distance = Math.sqrt(vx * vx + vy * vy); if(distance == 0) distance = 0.005; double i = 0; double moveX = x; double moveY = y; while(i < distance) { double pos = i/distance; moveX = x + dx * pos; moveY = y + dy * pos; if(collisionLeft && vx < 0) { vx = 0; leftCollision = true; break; } else leftCollision = false; if(collisionRight && vx > 0) { vx = 0; rightCollision = true; break; } else rightCollision = false; if(collisionBottom && vy < 0) { vy = 0; bottomCollision = true; break; } else bottomCollision = false; if(topCollision && vy > 0) { vy = 0; topCollision = true; break; } else topCollision = false; i += 0.005; } x = moveX; y = moveY; } } |
Basically you just use a velocity vector, then move the character along that vector until it hits something.
For your controls, just change the x/y velocity appropriately.