Hi, i could really use some help with the collison detection for my tile game. There are alot of problem with this algorithm but my mainproblem is when the hero is standing on top off a block i cant get him to fall off. He keeps floating away in the air when he should start falling. I also got trouble figuring out how to move when he jumps and hits the bottom of a block and should start falling back. Any help to optimize this and general tips is very appriciated!
public void move(long delta){
if(jumping){
dy = dy + gravity;
}
float newx = (dx * delta) / 1000;
float newy = (dy * delta) / 1000;
Rectangle me = new Rectangle(
(int)(x + newx),
(int)(y + newy),
(int)(getWidth()),
(int)(getHeight())
);
Rectangle block = new Rectangle(
(int)(25*16),
(int)(29*16),
(int)16,
(int)16
);
if(y + getHeight() > Game.SCREEN_HEIGHT){
dy = 0;
newy = 0;
jumping = false;
y = Game.SCREEN_HEIGHT - getHeight();
}
if(me.intersects(block)){
if(newx > 0){
x = (float)block.getX() - getWidth();
newx = 0;
}
else if(newx < 0){
x = (float)block.getX() + 16;
newx = 0;
}
if(newy > 0){
y = (float)block.getY() - getHeight();
jumping = false;
newy = 0;
dy = 0;
}
else if(newy < 0){
y = (float)block.getMaxY() + 16;
newy = -(newy);
}
}
x += newx;
y += newy;
}