here's some basic Java code from one of my games that i made about 2.5 years ago.
if it's too long, tell me and i'll edit it down.
public void updateBuffer() {
buffer.height = body.height;
buffer.width = body.width;
if (isJump) {
if (direction == 0)
buffer.x = body.x - 20;
else
buffer.x = body.x + 20;
} else {
if (direction == 0)
buffer.x = body.x - 10;
else
buffer.x = body.x + 10;
}
}
public void move(walls w) {
if (!isFalling()) {
body.x += xVelocity;
if (xVelocity > 0) {
xVelocity += 2;
} else if (xVelocity < 0) {
xVelocity -= 2;
}
updateBuffer();
if (!isJump) {
boolean safe = false;
for (Rectangle a : w.getList()) {
if (buffer.intersects(a)) {
safe = true;
break;
}
}
if (!safe) {
dead = true;
if (direction == 0)
xVelocity += 2;
else
xVelocity -= 2;
}
} else {
for (Rectangle a : w.getList()) {
if (a.intersects(buffer)) {
if (direction == 1)
body.x += (a.x - body.x - 10);
else
body.x -= (body.x - a.x - 20);
stop();
break;
}
}
}
} else {
if (direction == 1) {
if (xVelocity > 0)
xVelocity -= 4;
else if (xVelocity < -2)
xVelocity = 0;
} else {
if (xVelocity < 0)
xVelocity += 4;
else if (xVelocity > 2)
xVelocity = 0;
}
body.x += xVelocity;
if (yVelocity == 0)
yVelocity += 9;
else
yVelocity += 4;
body.y += yVelocity;
if (body.y > 380) {
body.width = 20;
body.height = 10;
body.y = 380;
}
}
}
bonus points if you can kind of figure out what it's supposed to do