Update GameState
This commit is contained in:
parent
1e19b37301
commit
be325c87c6
15 changed files with 580 additions and 267 deletions
36
VBO/src/mrdev023/game/AboutMenu.java
Normal file
36
VBO/src/mrdev023/game/AboutMenu.java
Normal file
|
@ -0,0 +1,36 @@
|
|||
package mrdev023.game;
|
||||
|
||||
import mrdev023.game.gamestate.*;
|
||||
import mrdev023.world.*;
|
||||
|
||||
public class AboutMenu implements GameInterface{
|
||||
|
||||
public void render() {
|
||||
|
||||
}
|
||||
|
||||
public void update() {
|
||||
|
||||
}
|
||||
|
||||
public void renderGUI() {
|
||||
|
||||
}
|
||||
|
||||
public void destroyGameState() {
|
||||
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void updateMouse() {
|
||||
|
||||
}
|
||||
|
||||
public void updateKeyboard() {
|
||||
|
||||
}
|
||||
|
||||
}
|
36
VBO/src/mrdev023/game/MainMenu.java
Normal file
36
VBO/src/mrdev023/game/MainMenu.java
Normal file
|
@ -0,0 +1,36 @@
|
|||
package mrdev023.game;
|
||||
|
||||
import mrdev023.game.gamestate.*;
|
||||
import mrdev023.world.*;
|
||||
|
||||
public class MainMenu implements GameInterface{
|
||||
|
||||
public void render() {
|
||||
|
||||
}
|
||||
|
||||
public void update() {
|
||||
|
||||
}
|
||||
|
||||
public void renderGUI() {
|
||||
|
||||
}
|
||||
|
||||
public void destroyGameState() {
|
||||
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void updateMouse() {
|
||||
|
||||
}
|
||||
|
||||
public void updateKeyboard() {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,18 +1,50 @@
|
|||
package mrdev023.game;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
import org.lwjgl.input.*;
|
||||
import org.lwjgl.opengl.*;
|
||||
|
||||
import mrdev023.blocks.*;
|
||||
import mrdev023.game.gamestate.*;
|
||||
import mrdev023.gameEngine.*;
|
||||
import mrdev023.math.*;
|
||||
import mrdev023.rendering.*;
|
||||
import mrdev023.update.*;
|
||||
import mrdev023.world.*;
|
||||
|
||||
public class MultiGame extends Game{
|
||||
public class MultiGame extends Game implements GameInterface{
|
||||
|
||||
public MultiGame(long seed) {
|
||||
super(new MultiWorld(seed,120,50));
|
||||
private static Block selectedBlock = null;
|
||||
private static Vector3f selectedVector = new Vector3f(0,0,0);
|
||||
|
||||
public MultiGame() {
|
||||
super(new MultiWorld(0,120,50));
|
||||
}
|
||||
|
||||
public void render(){
|
||||
Camera.renderCamera();
|
||||
this.world.render();
|
||||
if(selectedVector != null && selectedVector !=null){
|
||||
renderBlock((int)selectedVector.x,(int)selectedVector.y,(int)selectedVector.z);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(){
|
||||
Camera.getPlayerRaycast().update();
|
||||
if(GameEngine.getGameState().getWorld() != null){
|
||||
if(Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()) != null){
|
||||
boolean nx = false, ny = false, nz = false;
|
||||
if(Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()).x < 0)nx = true;
|
||||
if(Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()).y < 0)ny = true;
|
||||
if(Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()).z < 0)nz = true;
|
||||
selectedBlock = GameEngine.getGameState().getWorld().getBlock((int)Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()).getX(), (int)Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()).getY(), (int)Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()).getZ(),nx,ny,nz);
|
||||
selectedVector = new Vector3f(Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()).getX(), Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()).getY(), Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()).getZ());
|
||||
}else{
|
||||
selectedBlock = null;
|
||||
selectedVector = null;
|
||||
}
|
||||
}
|
||||
if(update >= 2){
|
||||
world.update();
|
||||
update = 0;
|
||||
|
@ -24,4 +56,146 @@ public class MultiGame extends Game{
|
|||
|
||||
}
|
||||
|
||||
public void destroyGameState() {
|
||||
destroyGame();
|
||||
}
|
||||
|
||||
private static void renderBlock(int x,int y ,int z){
|
||||
float s = 1;
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glLineWidth(2);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex3f(x,y,z);
|
||||
glVertex3f(x + s,y,z);
|
||||
glVertex3f(x + s, y + s, z);
|
||||
glVertex3f(x,y + s,z);
|
||||
|
||||
glVertex3f(x + s,y,z + s);
|
||||
glVertex3f(x,y,z + s);
|
||||
glVertex3f(x,y + s,z + s);
|
||||
glVertex3f(x + s, y + s, z + s);
|
||||
|
||||
glVertex3f(x + s,y,z);
|
||||
glVertex3f(x,y,z);
|
||||
glVertex3f(x,y,z + s);
|
||||
glVertex3f(x + s,y,z + s);
|
||||
|
||||
glVertex3f(x,y + s,z);
|
||||
glVertex3f(x + s,y + s,z);
|
||||
glVertex3f(x + s,y + s,z + s);
|
||||
glVertex3f(x,y + s,z + s);
|
||||
|
||||
glVertex3f(x,y,z);
|
||||
glVertex3f(x,y + s,z);
|
||||
glVertex3f(x,y + s,z + s);
|
||||
glVertex3f(x,y,z + s);
|
||||
|
||||
glVertex3f(x + s,y + s,z);
|
||||
glVertex3f(x + s,y,z);
|
||||
glVertex3f(x + s,y,z + s);
|
||||
glVertex3f(x + s,y + s,z + s);
|
||||
glEnd();
|
||||
glEnable(GL_CULL_FACE);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
}
|
||||
|
||||
private static float xDir,yDir,zDir;
|
||||
private static float speed = 0.02f;
|
||||
private static float xa = 0,ya = 0,za = 0;
|
||||
|
||||
public void updateMouse() {
|
||||
if(Mouse.isGrabbed()){
|
||||
|
||||
Camera.getRotation().x -= Mouse.getDY() * 0.5;
|
||||
Camera.getRotation().y += Mouse.getDX() * 0.5;
|
||||
|
||||
while(Mouse.next()){
|
||||
if(Mouse.getEventButtonState()){
|
||||
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void updateKeyboard() {
|
||||
xDir = 0;
|
||||
yDir = 0;
|
||||
zDir = 0;
|
||||
while(Keyboard.next()){
|
||||
if(Keyboard.getEventKeyState()){
|
||||
if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE){
|
||||
GameEngine.setRunning(false);
|
||||
}
|
||||
if(Keyboard.getEventKey() == Keyboard.KEY_F2){
|
||||
Mouse.setGrabbed(!Mouse.isGrabbed());
|
||||
}
|
||||
if(Keyboard.getEventKey() == Keyboard.KEY_F5){
|
||||
Camera.setPosition(new Vector3f(0,2,0));
|
||||
}
|
||||
if(Keyboard.getEventKey() == Keyboard.KEY_X){
|
||||
Camera.noClip = !Camera.noClip;
|
||||
}
|
||||
}else{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(Mouse.isGrabbed()){
|
||||
if(Camera.getRotation().x < -90) Camera.getRotation().x = -90;
|
||||
if(Camera.getRotation().x > 90) Camera.getRotation().x = 90;
|
||||
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_Z)){
|
||||
zDir = -speed;
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_S)){
|
||||
zDir = speed;
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_Q)){
|
||||
xDir = -speed;
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_D)){
|
||||
xDir = speed;
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_SPACE)){
|
||||
if(Camera.grounded)yDir = 0.3f;
|
||||
if(!Camera.gravity)yDir = speed;
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)){
|
||||
speed = 0.01f;
|
||||
}else{
|
||||
speed = 0.02f;
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)){
|
||||
if(!Camera.gravity)yDir = -speed;
|
||||
}
|
||||
}
|
||||
|
||||
xa += xDir * Math.cos(Math.toRadians(Camera.getRotation().y)) - zDir * Math.sin(Math.toRadians(Camera.getRotation().y));
|
||||
ya += yDir;
|
||||
za += zDir * Math.cos(Math.toRadians(Camera.getRotation().y)) + xDir * Math.sin(Math.toRadians(Camera.getRotation().y));
|
||||
|
||||
Camera.move(xa,ya,za);
|
||||
|
||||
xa *= 0.9f;
|
||||
ya *= 0.9f;
|
||||
za *= 0.9f;
|
||||
|
||||
if(Display.isCloseRequested()){
|
||||
GameEngine.setRunning(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
36
VBO/src/mrdev023/game/OptionMenu.java
Normal file
36
VBO/src/mrdev023/game/OptionMenu.java
Normal file
|
@ -0,0 +1,36 @@
|
|||
package mrdev023.game;
|
||||
|
||||
import mrdev023.game.gamestate.*;
|
||||
import mrdev023.world.*;
|
||||
|
||||
public class OptionMenu implements GameInterface{
|
||||
|
||||
public void render() {
|
||||
|
||||
}
|
||||
|
||||
public void update() {
|
||||
|
||||
}
|
||||
|
||||
public void renderGUI() {
|
||||
|
||||
}
|
||||
|
||||
public void destroyGameState() {
|
||||
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void updateMouse() {
|
||||
|
||||
}
|
||||
|
||||
public void updateKeyboard() {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,19 +1,51 @@
|
|||
package mrdev023.game;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
import org.lwjgl.input.*;
|
||||
import org.lwjgl.opengl.*;
|
||||
|
||||
import mrdev023.blocks.*;
|
||||
import mrdev023.game.gamestate.*;
|
||||
import mrdev023.gameEngine.*;
|
||||
import mrdev023.math.*;
|
||||
import mrdev023.rendering.*;
|
||||
import mrdev023.update.*;
|
||||
import mrdev023.world.*;
|
||||
|
||||
|
||||
public class SoloGame extends Game{
|
||||
public class SoloGame extends Game implements GameInterface{
|
||||
|
||||
private static Block selectedBlock = null;
|
||||
private static Vector3f selectedVector = new Vector3f(0,0,0);
|
||||
|
||||
public SoloGame() {
|
||||
super(new SoloWorld(0,120,50));
|
||||
super(new MultiWorld(0,120,50));
|
||||
}
|
||||
|
||||
public void render(){
|
||||
Camera.renderCamera();
|
||||
this.world.render();
|
||||
if(selectedVector != null && selectedVector !=null){
|
||||
renderBlock((int)selectedVector.x,(int)selectedVector.y,(int)selectedVector.z);
|
||||
}
|
||||
}
|
||||
|
||||
public void update(){
|
||||
Camera.getPlayerRaycast().update();
|
||||
if(GameEngine.getGameState().getWorld() != null){
|
||||
if(Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()) != null){
|
||||
boolean nx = false, ny = false, nz = false;
|
||||
if(Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()).x < 0)nx = true;
|
||||
if(Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()).y < 0)ny = true;
|
||||
if(Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()).z < 0)nz = true;
|
||||
selectedBlock = GameEngine.getGameState().getWorld().getBlock((int)Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()).getX(), (int)Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()).getY(), (int)Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()).getZ(),nx,ny,nz);
|
||||
selectedVector = new Vector3f(Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()).getX(), Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()).getY(), Camera.getPlayerRaycast().getBlock(GameEngine.getGameState().getWorld()).getZ());
|
||||
}else{
|
||||
selectedBlock = null;
|
||||
selectedVector = null;
|
||||
}
|
||||
}
|
||||
if(update >= 2){
|
||||
world.update();
|
||||
update = 0;
|
||||
|
@ -24,4 +56,146 @@ public class SoloGame extends Game{
|
|||
public void renderGUI() {
|
||||
|
||||
}
|
||||
|
||||
public void destroyGameState() {
|
||||
destroyGame();
|
||||
}
|
||||
|
||||
private static void renderBlock(int x,int y ,int z){
|
||||
float s = 1;
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glLineWidth(2);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex3f(x,y,z);
|
||||
glVertex3f(x + s,y,z);
|
||||
glVertex3f(x + s, y + s, z);
|
||||
glVertex3f(x,y + s,z);
|
||||
|
||||
glVertex3f(x + s,y,z + s);
|
||||
glVertex3f(x,y,z + s);
|
||||
glVertex3f(x,y + s,z + s);
|
||||
glVertex3f(x + s, y + s, z + s);
|
||||
|
||||
glVertex3f(x + s,y,z);
|
||||
glVertex3f(x,y,z);
|
||||
glVertex3f(x,y,z + s);
|
||||
glVertex3f(x + s,y,z + s);
|
||||
|
||||
glVertex3f(x,y + s,z);
|
||||
glVertex3f(x + s,y + s,z);
|
||||
glVertex3f(x + s,y + s,z + s);
|
||||
glVertex3f(x,y + s,z + s);
|
||||
|
||||
glVertex3f(x,y,z);
|
||||
glVertex3f(x,y + s,z);
|
||||
glVertex3f(x,y + s,z + s);
|
||||
glVertex3f(x,y,z + s);
|
||||
|
||||
glVertex3f(x + s,y + s,z);
|
||||
glVertex3f(x + s,y,z);
|
||||
glVertex3f(x + s,y,z + s);
|
||||
glVertex3f(x + s,y + s,z + s);
|
||||
glEnd();
|
||||
glEnable(GL_CULL_FACE);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
}
|
||||
|
||||
private static float xDir,yDir,zDir;
|
||||
private static float speed = 0.02f;
|
||||
private static float xa = 0,ya = 0,za = 0;
|
||||
|
||||
public void updateMouse() {
|
||||
if(Mouse.isGrabbed()){
|
||||
|
||||
Camera.getRotation().x -= Mouse.getDY() * 0.5;
|
||||
Camera.getRotation().y += Mouse.getDX() * 0.5;
|
||||
|
||||
while(Mouse.next()){
|
||||
if(Mouse.getEventButtonState()){
|
||||
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void updateKeyboard() {
|
||||
xDir = 0;
|
||||
yDir = 0;
|
||||
zDir = 0;
|
||||
while(Keyboard.next()){
|
||||
if(Keyboard.getEventKeyState()){
|
||||
if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE){
|
||||
GameEngine.setRunning(false);
|
||||
}
|
||||
if(Keyboard.getEventKey() == Keyboard.KEY_F2){
|
||||
Mouse.setGrabbed(!Mouse.isGrabbed());
|
||||
}
|
||||
if(Keyboard.getEventKey() == Keyboard.KEY_F5){
|
||||
Camera.setPosition(new Vector3f(0,2,0));
|
||||
}
|
||||
if(Keyboard.getEventKey() == Keyboard.KEY_X){
|
||||
Camera.noClip = !Camera.noClip;
|
||||
}
|
||||
}else{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(Mouse.isGrabbed()){
|
||||
if(Camera.getRotation().x < -90) Camera.getRotation().x = -90;
|
||||
if(Camera.getRotation().x > 90) Camera.getRotation().x = 90;
|
||||
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_Z)){
|
||||
zDir = -speed;
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_S)){
|
||||
zDir = speed;
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_Q)){
|
||||
xDir = -speed;
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_D)){
|
||||
xDir = speed;
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_SPACE)){
|
||||
if(Camera.grounded)yDir = 0.3f;
|
||||
if(!Camera.gravity)yDir = speed;
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)){
|
||||
speed = 0.01f;
|
||||
}else{
|
||||
speed = 0.02f;
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)){
|
||||
if(!Camera.gravity)yDir = -speed;
|
||||
}
|
||||
}
|
||||
|
||||
xa += xDir * Math.cos(Math.toRadians(Camera.getRotation().y)) - zDir * Math.sin(Math.toRadians(Camera.getRotation().y));
|
||||
ya += yDir;
|
||||
za += zDir * Math.cos(Math.toRadians(Camera.getRotation().y)) + xDir * Math.sin(Math.toRadians(Camera.getRotation().y));
|
||||
|
||||
Camera.move(xa,ya,za);
|
||||
|
||||
xa *= 0.9f;
|
||||
ya *= 0.9f;
|
||||
za *= 0.9f;
|
||||
|
||||
if(Display.isCloseRequested()){
|
||||
GameEngine.setRunning(false);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
15
VBO/src/mrdev023/game/gamestate/GameInterface.java
Normal file
15
VBO/src/mrdev023/game/gamestate/GameInterface.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package mrdev023.game.gamestate;
|
||||
|
||||
import mrdev023.world.*;
|
||||
|
||||
public interface GameInterface {
|
||||
|
||||
public void render();
|
||||
public void update();
|
||||
public void renderGUI();
|
||||
public void destroyGameState();
|
||||
public World getWorld();
|
||||
public void updateMouse();
|
||||
public void updateKeyboard();
|
||||
|
||||
}
|
|
@ -1,13 +1,43 @@
|
|||
package mrdev023.game.gamestate;
|
||||
|
||||
import mrdev023.game.*;
|
||||
import mrdev023.world.*;
|
||||
|
||||
public enum GameState {
|
||||
|
||||
MAIN_MENU,SOLO_GAME,MULTI_GAME,OPTION_GAME,ABOUT_GAME;
|
||||
MAIN_MENU(new MainMenu()),SOLO_GAME(new SoloGame()),MULTI_GAME(new MultiGame()),OPTION_MENU(new OptionMenu()),ABOUT_MENU(new AboutMenu());
|
||||
|
||||
GameState(){
|
||||
|
||||
GameInterface gameInterface;
|
||||
|
||||
GameState(GameInterface gameInterface){
|
||||
this.gameInterface = gameInterface;
|
||||
}
|
||||
|
||||
public void render(){
|
||||
this.gameInterface.render();
|
||||
}
|
||||
|
||||
public void update(){
|
||||
this.gameInterface.update();
|
||||
}
|
||||
|
||||
public void renderGUI(){
|
||||
this.gameInterface.renderGUI();
|
||||
}
|
||||
|
||||
public void destroyGameState(){
|
||||
this.gameInterface.destroyGameState();
|
||||
}
|
||||
|
||||
public World getWorld(){
|
||||
return this.gameInterface.getWorld();
|
||||
}
|
||||
|
||||
public void updateMouse() {
|
||||
this.gameInterface.updateMouse();
|
||||
}
|
||||
|
||||
public void updateKeyboard() {
|
||||
this.gameInterface.updateKeyboard();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.lwjgl.input.*;
|
|||
import org.lwjgl.opengl.*;
|
||||
|
||||
import mrdev023.game.*;
|
||||
import mrdev023.game.gamestate.*;
|
||||
import mrdev023.main.*;
|
||||
import mrdev023.rendering.*;
|
||||
import mrdev023.update.*;
|
||||
|
@ -22,7 +23,7 @@ public class GameEngine {
|
|||
private static final String TITLE = "Test VBO";
|
||||
private static final int width = 1280, height = 720;
|
||||
|
||||
private static Game game;
|
||||
public static GameState gameState;
|
||||
|
||||
public static void initWindow(){
|
||||
Main.mainPool = Executors.newWorkStealingPool();
|
||||
|
@ -32,8 +33,8 @@ public class GameEngine {
|
|||
Display.setResizable(true);
|
||||
Display.create();
|
||||
Camera.initCamera();
|
||||
game = new SoloGame();
|
||||
Mouse.setGrabbed(true);
|
||||
gameState = GameState.MAIN_MENU;
|
||||
loop();
|
||||
} catch (Exception e) {
|
||||
|
||||
|
@ -67,7 +68,6 @@ public class GameEngine {
|
|||
} else {
|
||||
DisplayManager.clearScreen();
|
||||
DisplayManager.preRender3D();
|
||||
Camera.renderCamera();
|
||||
DisplayManager.render3D();
|
||||
DisplayManager.preRender2D();
|
||||
DisplayManager.render2D();
|
||||
|
@ -85,7 +85,7 @@ public class GameEngine {
|
|||
+ Camera.getPosition().getY() + " PZ:"
|
||||
+ Camera.getPosition().getZ() + " | "
|
||||
+ World.updateWorldTime + " " + DisplayManager.getDelta()
|
||||
+ " " + Update.getSelectedBlock() + " | "
|
||||
+ " | "
|
||||
+ Runtime.getRuntime().totalMemory()/1024);
|
||||
FPS = 0;
|
||||
TICKS = 0;
|
||||
|
@ -97,8 +97,13 @@ public class GameEngine {
|
|||
destroy();
|
||||
}
|
||||
|
||||
public static void changeGameState(GameState newGameState){
|
||||
gameState.destroyGameState();
|
||||
gameState = newGameState;
|
||||
}
|
||||
|
||||
public static void destroy(){
|
||||
game.destroyGame();
|
||||
gameState.destroyGameState();
|
||||
Display.destroy();
|
||||
}
|
||||
|
||||
|
@ -168,8 +173,8 @@ public class GameEngine {
|
|||
return height;
|
||||
}
|
||||
|
||||
public static Game getGame() {
|
||||
return game;
|
||||
public static GameState getGameState() {
|
||||
return gameState;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3,15 +3,8 @@ package mrdev023.main;
|
|||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import mrdev023.game.*;
|
||||
import mrdev023.gameEngine.*;
|
||||
import mrdev023.rendering.*;
|
||||
import mrdev023.server.*;
|
||||
import mrdev023.update.*;
|
||||
import mrdev023.world.*;
|
||||
|
||||
import org.lwjgl.input.*;
|
||||
import org.lwjgl.opengl.*;
|
||||
import mrdev023.network.*;
|
||||
|
||||
public class Main {
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package mrdev023.server;
|
||||
package mrdev023.network;
|
||||
|
||||
public class Server {
|
||||
|
|
@ -25,14 +25,14 @@ public class Camera {
|
|||
}
|
||||
|
||||
public static void renderCamera() {
|
||||
if (position.getY() < (int)((new Noise(GameEngine.getGame().getWorld().seed, GameEngine
|
||||
.getGame().getWorld().octave,
|
||||
GameEngine.getGame().getWorld().amplitude).getNoise(position.getX(),
|
||||
if (position.getY() < (int)((new Noise(GameEngine.getGameState().getWorld().seed, GameEngine
|
||||
.getGameState().getWorld().octave,
|
||||
GameEngine.getGameState().getWorld().amplitude).getNoise(position.getX(),
|
||||
position.getZ())) + 1)) {
|
||||
|
||||
position.setY((int)((new Noise(GameEngine.getGame().getWorld().seed, GameEngine
|
||||
.getGame().getWorld().octave,
|
||||
GameEngine.getGame().getWorld().amplitude).getNoise(position.getX(),
|
||||
position.setY((int)((new Noise(GameEngine.getGameState().getWorld().seed, GameEngine
|
||||
.getGameState().getWorld().octave,
|
||||
GameEngine.getGameState().getWorld().amplitude).getNoise(position.getX(),
|
||||
position.getZ())) + 2));
|
||||
}
|
||||
glLoadIdentity();
|
||||
|
@ -119,7 +119,7 @@ public class Camera {
|
|||
}
|
||||
|
||||
public static boolean isColliding(float xa, float ya, float za) {
|
||||
World world = GameEngine.getGame().getWorld();
|
||||
World world = GameEngine.getGameState().getWorld();
|
||||
float r = 0.3f;
|
||||
|
||||
boolean nx = false, ny = false, nz = false;
|
||||
|
|
|
@ -40,10 +40,7 @@ public class DisplayManager {
|
|||
* @Info Fait le rendu 3d
|
||||
*/
|
||||
public static void render3D(){
|
||||
GameEngine.getGame().render();
|
||||
if(Update.getSelectedBlock() != null && Update.getSelectedVector() !=null){
|
||||
renderBlock((int)Update.getSelectedVector().x,(int)Update.getSelectedVector().y,(int)Update.getSelectedVector().z);
|
||||
}
|
||||
GameEngine.getGameState().render();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -62,7 +59,7 @@ public class DisplayManager {
|
|||
* @Info Fait le rendu 2d
|
||||
*/
|
||||
public static void render2D(){
|
||||
GameEngine.getGame().renderGUI();
|
||||
GameEngine.getGameState().renderGUI();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -88,43 +85,4 @@ public class DisplayManager {
|
|||
DisplayManager.fov = fov;
|
||||
}
|
||||
|
||||
private static void renderBlock(int x,int y ,int z){
|
||||
float s = 1;
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glLineWidth(2);
|
||||
glBegin(GL_QUADS);
|
||||
glVertex3f(x,y,z);
|
||||
glVertex3f(x + s,y,z);
|
||||
glVertex3f(x + s, y + s, z);
|
||||
glVertex3f(x,y + s,z);
|
||||
|
||||
glVertex3f(x + s,y,z + s);
|
||||
glVertex3f(x,y,z + s);
|
||||
glVertex3f(x,y + s,z + s);
|
||||
glVertex3f(x + s, y + s, z + s);
|
||||
|
||||
glVertex3f(x + s,y,z);
|
||||
glVertex3f(x,y,z);
|
||||
glVertex3f(x,y,z + s);
|
||||
glVertex3f(x + s,y,z + s);
|
||||
|
||||
glVertex3f(x,y + s,z);
|
||||
glVertex3f(x + s,y + s,z);
|
||||
glVertex3f(x + s,y + s,z + s);
|
||||
glVertex3f(x,y + s,z + s);
|
||||
|
||||
glVertex3f(x,y,z);
|
||||
glVertex3f(x,y + s,z);
|
||||
glVertex3f(x,y + s,z + s);
|
||||
glVertex3f(x,y,z + s);
|
||||
|
||||
glVertex3f(x + s,y + s,z);
|
||||
glVertex3f(x + s,y,z);
|
||||
glVertex3f(x + s,y,z + s);
|
||||
glVertex3f(x + s,y + s,z + s);
|
||||
glEnd();
|
||||
glEnable(GL_CULL_FACE);
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,211 +1,29 @@
|
|||
package mrdev023.update;
|
||||
import mrdev023.blocks.*;
|
||||
import mrdev023.gameEngine.*;
|
||||
import mrdev023.main.*;
|
||||
import mrdev023.math.*;
|
||||
import mrdev023.rendering.*;
|
||||
|
||||
import org.lwjgl.input.*;
|
||||
import org.lwjgl.opengl.*;
|
||||
|
||||
|
||||
public class Update {
|
||||
|
||||
private static float xDir,yDir,zDir;
|
||||
private static float speed = 0.02f;
|
||||
private static float xa = 0,ya = 0,za = 0;
|
||||
private static Block selectedBlock = null;
|
||||
private static Vector3f selectedVector = new Vector3f(0,0,0);
|
||||
|
||||
/**
|
||||
* @Info Fonction permettant de gerer les action de la souris
|
||||
*/
|
||||
public static void updateMouse(){
|
||||
if(Mouse.isGrabbed()){
|
||||
|
||||
Camera.getRotation().x -= Mouse.getDY() * 0.5;
|
||||
Camera.getRotation().y += Mouse.getDX() * 0.5;
|
||||
|
||||
while(Mouse.next()){
|
||||
if(Mouse.getEventButtonState()){
|
||||
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
GameEngine.getGameState().updateMouse();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Info Fonction permettant de gerer les action du clavier
|
||||
*/
|
||||
public static void updateKeyboard(){
|
||||
xDir = 0;
|
||||
yDir = 0;
|
||||
zDir = 0;
|
||||
while(Keyboard.next()){
|
||||
if(Keyboard.getEventKeyState()){
|
||||
if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE){
|
||||
GameEngine.setRunning(false);
|
||||
}
|
||||
if(Keyboard.getEventKey() == Keyboard.KEY_F2){
|
||||
Mouse.setGrabbed(!Mouse.isGrabbed());
|
||||
}
|
||||
if(Keyboard.getEventKey() == Keyboard.KEY_F5){
|
||||
Camera.setPosition(new Vector3f(0,2,0));
|
||||
}
|
||||
if(Keyboard.getEventKey() == Keyboard.KEY_X){
|
||||
Camera.noClip = !Camera.noClip;
|
||||
}
|
||||
}else{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(Mouse.isGrabbed()){
|
||||
if(Camera.getRotation().x < -90) Camera.getRotation().x = -90;
|
||||
if(Camera.getRotation().x > 90) Camera.getRotation().x = 90;
|
||||
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_Z)){
|
||||
zDir = -speed;
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_S)){
|
||||
zDir = speed;
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_Q)){
|
||||
xDir = -speed;
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_D)){
|
||||
xDir = speed;
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_SPACE)){
|
||||
if(Camera.grounded)yDir = 0.3f;
|
||||
if(!Camera.gravity)yDir = speed;
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT)){
|
||||
speed = 0.01f;
|
||||
}else{
|
||||
speed = 0.02f;
|
||||
}
|
||||
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_LCONTROL)){
|
||||
if(!Camera.gravity)yDir = -speed;
|
||||
}
|
||||
}
|
||||
|
||||
xa += xDir * Math.cos(Math.toRadians(Camera.getRotation().y)) - zDir * Math.sin(Math.toRadians(Camera.getRotation().y));
|
||||
ya += yDir;
|
||||
za += zDir * Math.cos(Math.toRadians(Camera.getRotation().y)) + xDir * Math.sin(Math.toRadians(Camera.getRotation().y));
|
||||
|
||||
Camera.move(xa,ya,za);
|
||||
|
||||
xa *= 0.9f;
|
||||
ya *= 0.9f;
|
||||
za *= 0.9f;
|
||||
|
||||
if(Display.isCloseRequested()){
|
||||
GameEngine.setRunning(false);
|
||||
}
|
||||
GameEngine.getGameState().updateKeyboard();
|
||||
}
|
||||
|
||||
/**
|
||||
* @Info Fonction de mettre a jour le display et d'autre choses predefinie
|
||||
*/
|
||||
public static void update(){
|
||||
GameEngine.getGame().update();
|
||||
Camera.getPlayerRaycast().update();
|
||||
if(Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()) != null){
|
||||
boolean nx = false, ny = false, nz = false;
|
||||
if(Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).x < 0)nx = true;
|
||||
if(Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).y < 0)ny = true;
|
||||
if(Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).z < 0)nz = true;
|
||||
selectedBlock = GameEngine.getGame().getWorld().getBlock((int)Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).getX(), (int)Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).getY(), (int)Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).getZ(),nx,ny,nz);
|
||||
selectedVector = new Vector3f(Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).getX(), Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).getY(), Camera.getPlayerRaycast().getBlock(GameEngine.getGame().getWorld()).getZ());
|
||||
}else{
|
||||
selectedBlock = null;
|
||||
selectedVector = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static float getxDir() {
|
||||
return xDir;
|
||||
}
|
||||
|
||||
public static void setxDir(float xDir) {
|
||||
Update.xDir = xDir;
|
||||
}
|
||||
|
||||
public static float getyDir() {
|
||||
return yDir;
|
||||
}
|
||||
|
||||
public static void setyDir(float yDir) {
|
||||
Update.yDir = yDir;
|
||||
}
|
||||
|
||||
public static float getzDir() {
|
||||
return zDir;
|
||||
}
|
||||
|
||||
public static void setzDir(float zDir) {
|
||||
Update.zDir = zDir;
|
||||
}
|
||||
|
||||
public static float getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public static void setSpeed(float speed) {
|
||||
Update.speed = speed;
|
||||
}
|
||||
|
||||
public static float getXa() {
|
||||
return xa;
|
||||
}
|
||||
|
||||
public static void setXa(float xa) {
|
||||
Update.xa = xa;
|
||||
}
|
||||
|
||||
public static float getYa() {
|
||||
return ya;
|
||||
}
|
||||
|
||||
public static void setYa(float ya) {
|
||||
Update.ya = ya;
|
||||
}
|
||||
|
||||
public static float getZa() {
|
||||
return za;
|
||||
}
|
||||
|
||||
public static void setZa(float za) {
|
||||
Update.za = za;
|
||||
}
|
||||
|
||||
public static Block getSelectedBlock() {
|
||||
return selectedBlock;
|
||||
}
|
||||
|
||||
public static void setSelectedBlock(Block selectedBlock) {
|
||||
Update.selectedBlock = selectedBlock;
|
||||
}
|
||||
|
||||
public static Vector3f getSelectedVector() {
|
||||
return selectedVector;
|
||||
}
|
||||
|
||||
public static void setSelectedVector(Vector3f selectedVector) {
|
||||
Update.selectedVector = selectedVector;
|
||||
}
|
||||
|
||||
GameEngine.getGameState().update();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,21 +1,59 @@
|
|||
package mrdev023.world;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import mrdev023.rendering.*;
|
||||
import mrdev023.world.chunk.*;
|
||||
|
||||
public class MultiWorld extends World{
|
||||
|
||||
public MultiWorld(long seed, int octave, int amplitude) {
|
||||
super(seed, octave, amplitude);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
// TODO Auto-generated method stub
|
||||
long current = System.currentTimeMillis();
|
||||
int xa = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - VIEW_CHUNK;
|
||||
int xb = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) + VIEW_CHUNK;
|
||||
int za = (int)((Camera.getPosition().getZ()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - VIEW_CHUNK;
|
||||
int zb = (int)((Camera.getPosition().getZ()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) + VIEW_CHUNK;
|
||||
|
||||
int delta_x = xb - xa;
|
||||
int delta_z = zb - za;
|
||||
for(int i = 0; i <= delta_x;i++){
|
||||
for(int k = 0;k <= delta_z;k++){
|
||||
// for(int j = 0; j < HEIGHT; j++){
|
||||
if(getChunk((xa + i), 0, (za + k)) != null)continue;
|
||||
Chunk ch = new Chunk((xa + i),0,(za + k),this);
|
||||
chunks.add(ch);
|
||||
// }
|
||||
}
|
||||
}
|
||||
ArrayList<Chunk> removeList = new ArrayList<Chunk>();
|
||||
for(int i = 0; i < chunks.size();i++){
|
||||
Chunk c = chunks.get(i);
|
||||
if(c.getPosition().getX() < xa || c.getPosition().getX() > xb || c.getPosition().getZ() < za || c.getPosition().getZ() > zb){
|
||||
c.destroyChunk();
|
||||
removeList.add(c);
|
||||
}else{
|
||||
if(!c.isLoaded() && !c.isGenerated() && !c.isCurrentGenerate() && !c.isDestroy())c.createChunk(this);
|
||||
if(!c.isLoaded() && c.isGenerated() && !c.isDestroy())c.loadBufferData();
|
||||
if(!c.isDestroy())c.update();
|
||||
}
|
||||
}
|
||||
for(Chunk c: removeList){
|
||||
removeByChunk(c);
|
||||
}
|
||||
removeList.clear();
|
||||
updateWorldTime = System.currentTimeMillis() - current;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
for(Chunk c : chunks){
|
||||
if(c.isLoaded()){
|
||||
c.render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ public class Chunk {
|
|||
}
|
||||
|
||||
public void loopChunk(int x, int y, int z) {
|
||||
world = GameEngine.getGame().getWorld();
|
||||
if(GameEngine.getGameState().getWorld() != null)world = GameEngine.getGameState().getWorld();
|
||||
int xx = this.x * SIZE + x;
|
||||
int yy = this.y * SIZE + y;
|
||||
int zz = this.z * SIZE + z;
|
||||
|
|
Reference in a new issue