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; 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() { void move() {
Vector speed = new Vector(xSpeed,0,zSpeed); Vector speed = new Vector(xSpeed,0,zSpeed);
if (Vector.length(speed)>MOVESPEED) { 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; jumpsAvailable=0;
fallSpd=JUMP_HEIGHT; fallSpd=JUMP_HEIGHT;
currentStaircase=null;
} }
} }

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

Loading…
Cancel
Save