Strafe controls to replace turn controls. Ignore Y axis when not in flying mode.
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
6f48971a74
commit
8e79afdf99
@ -22,6 +22,7 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
|
|||||||
|
|
||||||
public static boolean WIREFRAME = false;
|
public static boolean WIREFRAME = false;
|
||||||
public static boolean PROFILING = false;
|
public static boolean PROFILING = false;
|
||||||
|
public static boolean FLYING_MODE = false;
|
||||||
public static int SCREEN_WIDTH=1280;
|
public static int SCREEN_WIDTH=1280;
|
||||||
public static int SCREEN_HEIGHT=720;
|
public static int SCREEN_HEIGHT=720;
|
||||||
public final static long TIMEPERTICK = 16666667l;
|
public final static long TIMEPERTICK = 16666667l;
|
||||||
@ -57,13 +58,25 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
|
|||||||
public static HashMap<TextureType,Texture> blockTextures = new HashMap<TextureType,Texture>();
|
public static HashMap<TextureType,Texture> blockTextures = new HashMap<TextureType,Texture>();
|
||||||
|
|
||||||
boolean upHeld=false,downHeld=false,leftHeld=false,rightHeld=false,
|
boolean upHeld=false,downHeld=false,leftHeld=false,rightHeld=false,
|
||||||
aHeld=false,sHeld=false,dHeld=false,wHeld=false;
|
aHeld=false,sHeld=false,dHeld=false,wHeld=false,qHeld=false,eHeld=false;
|
||||||
|
|
||||||
public static MouseEvent request;
|
public static MouseEvent request;
|
||||||
public static MouseEvent temp_request;
|
public static MouseEvent temp_request;
|
||||||
public static MouseHandler answer;
|
public static MouseHandler answer;
|
||||||
public static MouseHandler tempAnswer = null;
|
public static MouseHandler tempAnswer = null;
|
||||||
|
|
||||||
|
void move(Vector v) {
|
||||||
|
if (FLYING_MODE||!blockGrid.containsKey((float)Math.floor(vCamera.x+v.x)+"_"+(float)Math.floor(vCamera.y)+"_"+(float)Math.floor(vCamera.z))) {
|
||||||
|
vCamera.x+=v.x;
|
||||||
|
}
|
||||||
|
if (FLYING_MODE||!blockGrid.containsKey((float)Math.floor(vCamera.x)+"_"+(float)Math.floor(vCamera.y+v.y)+"_"+(float)Math.floor(vCamera.z))) {
|
||||||
|
vCamera.y+=v.y;
|
||||||
|
}
|
||||||
|
if (FLYING_MODE||!blockGrid.containsKey((float)Math.floor(vCamera.x)+"_"+(float)Math.floor(vCamera.y)+"_"+(float)Math.floor(vCamera.z+v.z))) {
|
||||||
|
vCamera.z+=v.z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void runGameLoop() {
|
public void runGameLoop() {
|
||||||
if (upHeld) {
|
if (upHeld) {
|
||||||
pitch+=TURNSPEED;
|
pitch+=TURNSPEED;
|
||||||
@ -77,37 +90,33 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
|
|||||||
if (leftHeld) {
|
if (leftHeld) {
|
||||||
roll+=MOVESPEED;
|
roll+=MOVESPEED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wHeld||sHeld) {
|
if (wHeld||sHeld) {
|
||||||
Vector forward = Vector.multiply(vLookDir,MOVESPEED);
|
Vector forward = Vector.multiply(vLookDir,MOVESPEED);
|
||||||
|
if (!FLYING_MODE) {
|
||||||
|
forward.y=0;
|
||||||
|
}
|
||||||
if (wHeld) {
|
if (wHeld) {
|
||||||
if (!blockGrid.containsKey((float)Math.floor(vCamera.x+forward.x)+"_"+(float)Math.floor(vCamera.y)+"_"+(float)Math.floor(vCamera.z))) {
|
move(forward);
|
||||||
vCamera.x+=forward.x;
|
|
||||||
}
|
|
||||||
if (!blockGrid.containsKey((float)Math.floor(vCamera.x)+"_"+(float)Math.floor(vCamera.y+forward.y)+"_"+(float)Math.floor(vCamera.z))) {
|
|
||||||
vCamera.y+=forward.y;
|
|
||||||
}
|
|
||||||
if (!blockGrid.containsKey((float)Math.floor(vCamera.x)+"_"+(float)Math.floor(vCamera.y)+"_"+(float)Math.floor(vCamera.z+forward.z))) {
|
|
||||||
vCamera.z+=forward.z;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (sHeld) {
|
if (sHeld) {
|
||||||
if (!blockGrid.containsKey((float)Math.floor(vCamera.x-forward.x)+"_"+(float)Math.floor(vCamera.y)+"_"+(float)Math.floor(vCamera.z))) {
|
move(Vector.multiply(forward,-1));
|
||||||
vCamera.x-=forward.x;
|
|
||||||
}
|
|
||||||
if (!blockGrid.containsKey((float)Math.floor(vCamera.x)+"_"+(float)Math.floor(vCamera.y-forward.y)+"_"+(float)Math.floor(vCamera.z))) {
|
|
||||||
vCamera.y-=forward.y;
|
|
||||||
}
|
|
||||||
if (!blockGrid.containsKey((float)Math.floor(vCamera.x)+"_"+(float)Math.floor(vCamera.y)+"_"+(float)Math.floor(vCamera.z-forward.z))) {
|
|
||||||
vCamera.z-=forward.z;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
System.out.println(vCamera);
|
System.out.println(vCamera);
|
||||||
}
|
}
|
||||||
if (aHeld) {
|
if (aHeld) {
|
||||||
yaw-=TURNSPEED;
|
Vector leftStrafe = Vector.multiply(Matrix.MultiplyVector(Matrix.MakeRotationY((float)-Math.PI/2), vLookDir),MOVESPEED);
|
||||||
|
if (!FLYING_MODE) {
|
||||||
|
leftStrafe.y=0;
|
||||||
|
}
|
||||||
|
move(leftStrafe);
|
||||||
}
|
}
|
||||||
if (dHeld) {
|
if (dHeld) {
|
||||||
yaw+=TURNSPEED;
|
Vector rightStrafe = Vector.multiply(Matrix.MultiplyVector(Matrix.MakeRotationY((float)Math.PI/2), vLookDir),MOVESPEED);
|
||||||
|
if (!FLYING_MODE) {
|
||||||
|
rightStrafe.y=0;
|
||||||
|
}
|
||||||
|
move(rightStrafe);
|
||||||
}
|
}
|
||||||
if (answer!=null) {
|
if (answer!=null) {
|
||||||
if (answer.e.getButton()==MouseEvent.BUTTON1) {
|
if (answer.e.getButton()==MouseEvent.BUTTON1) {
|
||||||
@ -348,6 +357,12 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
|
|||||||
case KeyEvent.VK_S:{
|
case KeyEvent.VK_S:{
|
||||||
sHeld=true;
|
sHeld=true;
|
||||||
}break;
|
}break;
|
||||||
|
case KeyEvent.VK_E:{
|
||||||
|
eHeld=true;
|
||||||
|
}break;
|
||||||
|
case KeyEvent.VK_Q:{
|
||||||
|
qHeld=true;
|
||||||
|
}break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,6 +393,12 @@ public class SigRenderer implements KeyListener,MouseListener,MouseMotionListene
|
|||||||
case KeyEvent.VK_S:{
|
case KeyEvent.VK_S:{
|
||||||
sHeld=false;
|
sHeld=false;
|
||||||
}break;
|
}break;
|
||||||
|
case KeyEvent.VK_E:{
|
||||||
|
eHeld=false;
|
||||||
|
}break;
|
||||||
|
case KeyEvent.VK_Q:{
|
||||||
|
qHeld=false;
|
||||||
|
}break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user