Jumping on staircases.

origin
Joshua Sigona 3 years ago
parent d63f8ea2fa
commit 1f5cbd514a
  1. 17
      src/sig/SigRenderer.java
  2. 84
      src/sig/models/Staircase.java

@ -124,6 +124,20 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
return true;
}
public static boolean checkRawCollision(float x,float y,float z) {
for (int yy=0;yy<cameraHeight;yy++) {
Block b1 = blockGrid.get((float)Math.floor(vCamera.x+x+cameraCollisionPadding)+"_"+(float)Math.floor(vCamera.y+y+yy)+"_"+(float)Math.floor(vCamera.z+z+cameraCollisionPadding));
Block b2 = blockGrid.get((float)Math.floor(vCamera.x+x-cameraCollisionPadding)+"_"+(float)Math.floor(vCamera.y+y+yy)+"_"+(float)Math.floor(vCamera.z+z+cameraCollisionPadding));
Block b3 = blockGrid.get((float)Math.floor(vCamera.x+x+cameraCollisionPadding)+"_"+(float)Math.floor(vCamera.y+y+yy)+"_"+(float)Math.floor(vCamera.z+z-cameraCollisionPadding));
Block b4 = blockGrid.get((float)Math.floor(vCamera.x+x-cameraCollisionPadding)+"_"+(float)Math.floor(vCamera.y+y+yy)+"_"+(float)Math.floor(vCamera.z+z-cameraCollisionPadding));
if (b1!=null) {return false;}
if (b2!=null) {return false;}
if (b3!=null) {return false;}
if (b4!=null) {return false;}
}
return true;
}
void move() {
Vector speed = new Vector(xSpeed,0,zSpeed);
if (Vector.length(speed)>MOVESPEED) {
@ -221,9 +235,10 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
}
}
if (spaceHeld&&jumpsAvailable==1&&fallSpd==0&&!checkCollisionSquare(0,-gravity,0)) {
if (spaceHeld&&jumpsAvailable==1&&fallSpd==0&&(!checkRawCollision(0,-gravity,0))) {
jumpsAvailable=0;
fallSpd=JUMP_HEIGHT;
currentStaircase=null;
}
}

@ -95,43 +95,53 @@ public class Staircase extends Mesh{
}
public boolean handleCollision(Block b,float x,float z) {
if (SigRenderer.currentStaircase!=null&&b.pos.y==SigRenderer.currentStaircase.triangles.get(0).b.pos.y) {
float diffX=Math.min(1,Math.max(0f,SigRenderer.vCamera.x-b.pos.x));
float diffZ=Math.min(1,Math.max(0f,SigRenderer.vCamera.z-b.pos.z));
switch (b.getFacingDirection()) {
case EAST: {
if (checkCollision(SigRenderer.vCamera.x+x, b.pos.y+diffX+x+1.3f, SigRenderer.vCamera.z+z,SigRenderer.currentStaircase)) {
SigRenderer.vCamera.y=b.pos.y+diffX+0.3f;
} else {
SigRenderer.fallSpd=0;
return false;
}
}break;
case NORTH: {
if (checkCollision(SigRenderer.vCamera.x+x, b.pos.y+(1-diffZ+z)+1.3f, SigRenderer.vCamera.z+z,SigRenderer.currentStaircase)) {
SigRenderer.vCamera.y=b.pos.y+(1-diffZ)+0.3f;
} else {
SigRenderer.fallSpd=0;
return false;
}
}break;
case SOUTH: {
if (checkCollision(SigRenderer.vCamera.x+x, b.pos.y+diffZ+z+1.3f, SigRenderer.vCamera.z+z,SigRenderer.currentStaircase)) {
SigRenderer.vCamera.y=b.pos.y+diffZ+0.3f;
} else {
SigRenderer.fallSpd=0;
return false;
}
}break;
case WEST: {
if (checkCollision(SigRenderer.vCamera.x+x, b.pos.y+(1-diffX+x)+1.3f, SigRenderer.vCamera.z+z,SigRenderer.currentStaircase)) {
SigRenderer.vCamera.y=b.pos.y+(1-diffX)+0.3f;
} else {
SigRenderer.fallSpd=0;
return false;
}
}break;
}
SigRenderer.fallSpd=0;
float diffX=Math.min(1,Math.max(0.3f,SigRenderer.vCamera.x-b.pos.x));
float diffZ=Math.min(1,Math.max(0.3f,SigRenderer.vCamera.z-b.pos.z));
switch (b.getFacingDirection()) {
case EAST: {
if (checkCollision(SigRenderer.vCamera.x+x, b.pos.y+diffX+x+1.3f, SigRenderer.vCamera.z+z,SigRenderer.currentStaircase)) {
if (SigRenderer.fallSpd<=0) {
SigRenderer.vCamera.y=b.pos.y+diffX+0.3f;
}
} else {
//SigRenderer.fallSpd=0;
return false;
}
}break;
case NORTH: {
if (checkCollision(SigRenderer.vCamera.x+x, b.pos.y+(1-diffZ+z)+1.3f, SigRenderer.vCamera.z+z,SigRenderer.currentStaircase)) {
if (SigRenderer.fallSpd<=0) {
SigRenderer.vCamera.y=b.pos.y+(1-diffZ)+0.3f;
}
} else {
//SigRenderer.fallSpd=0;
return false;
}
}break;
case SOUTH: {
if (checkCollision(SigRenderer.vCamera.x+x, b.pos.y+diffZ+z+1.3f, SigRenderer.vCamera.z+z,SigRenderer.currentStaircase)) {
if (SigRenderer.fallSpd<=0) {
SigRenderer.vCamera.y=b.pos.y+diffZ+0.3f;
}
} else {
//SigRenderer.fallSpd=0;
return false;
}
}break;
case WEST: {
if (checkCollision(SigRenderer.vCamera.x+x, b.pos.y+(1-diffX+x)+1.3f, SigRenderer.vCamera.z+z,SigRenderer.currentStaircase)) {
if (SigRenderer.fallSpd<=0) {
SigRenderer.vCamera.y=b.pos.y+(1-diffX)+0.3f;
}
} else {
//SigRenderer.fallSpd=0;
return false;
}
}break;
}
if (SigRenderer.fallSpd<=0) {
SigRenderer.fallSpd=0;
}
return true;
}
if (SigRenderer.vCamera.y>=b.pos.y&&SigRenderer.vCamera.y<b.pos.y+1) {

Loading…
Cancel
Save