Skip to content

Commit

Permalink
Added Y collision (jumping on blocks).
Browse files Browse the repository at this point in the history
  • Loading branch information
mk12 committed Dec 19, 2011
1 parent bd83b88 commit 4d272bf
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/com/hecticcraft/mycraft/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class Player {
/**
* The initial upward velocity this Player will have upon jumping.
*/
private static final float INITAL_JUMP_VELOCITY = 0.25f;
private static final float INITAL_JUMP_VELOCITY = 0.2f;

/**
* The height of what the Player is currently standing on.
Expand Down Expand Up @@ -143,7 +143,28 @@ void collision(Chunk chunk) {
}
}

if (velocity > 0) {
// falling
if (deltaPosition.y <= 0) {
int drop = (int)height;
/*
do {
ray--;
} while (ray >= 0 && chunk.getBlockType(new Block((int)Math.round(position.x), ray, (int)Math.round(position.z))) == 0);*/

// Error Checking needed!!
while (drop >= 1 && !((chunk.getBlockType(new Block((int)(position.x), drop-1, (int)(position.z))) != 0)
|| (chunk.getBlockType(new Block((int)(position.x+0.25f), drop-1, (int)(position.z))) != 0)
|| (chunk.getBlockType(new Block((int)(position.x), drop-1, (int)(position.z+0.25f))) != 0)
|| (chunk.getBlockType(new Block((int)(position.x+0.25f), drop-1, (int)(position.z+0.25f))) != 0)
|| (chunk.getBlockType(new Block((int)(position.x-0.25f), drop-1, (int)(position.z))) != 0)
|| (chunk.getBlockType(new Block((int)(position.x), drop-1, (int)(position.z-0.25f))) != 0)
|| (chunk.getBlockType(new Block((int)(position.x-0.25f), drop-1, (int)(position.z-0.25f))) != 0)
|| (chunk.getBlockType(new Block((int)(position.x+0.25f), drop-1, (int)(position.z-0.25f))) != 0)
|| (chunk.getBlockType(new Block((int)(position.x-0.25f), drop-1, (int)(position.z+0.25f))) != 0))) {
drop--;
}

ground = drop;

} else {

Expand Down Expand Up @@ -186,6 +207,9 @@ void move(GameStateInputData input, float multiplier) {
if (height < ground) {
height = ground;
velocity = 0;
} else if (height + CAMERA_HEIGHT > 8) {
height = 8 - CAMERA_HEIGHT;
velocity = 0;
}

camera.setPositionY(height+CAMERA_HEIGHT);
Expand Down

0 comments on commit 4d272bf

Please sign in to comment.