diff --git a/.classpath b/.classpath index 3c22bac..9fea69d 100644 --- a/.classpath +++ b/.classpath @@ -1,20 +1,26 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pom.xml b/pom.xml index e07f740..5593d30 100644 --- a/pom.xml +++ b/pom.xml @@ -17,14 +17,6 @@ src - - - - src/launcher/ui - - - - diff --git a/src/engine/Engine.java b/src/engine/Engine.java index 0ce61be..657804e 100644 --- a/src/engine/Engine.java +++ b/src/engine/Engine.java @@ -5,7 +5,6 @@ import engine.math.*; import engine.object.*; import engine.sound.*; - import org.lwjgl.glfw.GLFWFramebufferSizeCallback; import org.lwjgl.glfw.GLFWVidMode; import org.lwjgl.opengl.GL; @@ -28,6 +27,8 @@ public class Engine { private final int width; private final int height; + private float viewXPos; + /** * Create the engine and initial attributes use .init() to start the engine */ @@ -38,6 +39,7 @@ public class Engine { this.height = height; ObjectGl.projection = Matrix4f.orthographic(-1000, 1000, -1000 * aspectRatio, 1000 * aspectRatio, 0.1f, 100.0f); ObjectGl.view = Matrix4f.translate(new Vector3f(0.0f, 0.0f, 1.0f)); + this.viewXPos = 0.0f; } /** @@ -62,7 +64,7 @@ public class Engine { assert getWindow() != NULL; boolean present = glfwJoystickPresent(GLFW_JOYSTICK_1); - System.out.println("Manette détectée : " + present); + System.out.println("Manette détectée : " + present); // On récupère les informations du moniteur principal GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); @@ -79,6 +81,8 @@ public class Engine { glfwShowWindow(getWindow()); GL.createCapabilities(); + correctViewport(this.width, this.height); + glfwSetFramebufferSizeCallback(getWindow(), resizeWindow); glEnable(GL_DEPTH_TEST); // Z-Buffer plus z est grand plus l'objet est proche de la camera limite à 100.0f au dela l'objet disparait @@ -102,6 +106,7 @@ public class Engine { */ public void render() { + glEnable(GL_SCISSOR_TEST); glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -117,7 +122,6 @@ public class Engine { /** * Add obj to the render queue - * * @param obj ObjectGl to render */ public void add_objectGl(ObjectGl obj) { @@ -128,6 +132,28 @@ public class Engine { objectsGl.remove(obj); } + public void translateView(Vector3f vec){ + ObjectGl.view = ObjectGl.view.multiply(Matrix4f.translate(vec)); + viewXPos += vec.x; + } + + public static void correctViewport(int width, int height){ + int heightViewport, widthViewport, x, y; + if (width >= height * 4.0f/3.0f){ + heightViewport = height; + widthViewport = (int) (height * 4.0f/3.0f); + y = 0; + x = (width - widthViewport)/2; + } else { + widthViewport = width; + heightViewport = (int) (width * 3.0f/4.0f); + y = (height - heightViewport)/2; + x = 0; + } + glScissor(x, y, widthViewport, heightViewport); + glViewport(x, y, widthViewport, heightViewport); + } + public boolean isRunning() { return running; } @@ -149,13 +175,13 @@ public class Engine { } /** - * Est appelé àa chaque modification de la taille de la fenêtre, et modifie la taille de la zone de rendu + * Est appelé à chaque modification de la taille de la fenêtre, et modifie la taille de la zone de rendu * pour quelle corresponde à la taille de la fenêtre */ private static final GLFWFramebufferSizeCallback resizeWindow = new GLFWFramebufferSizeCallback() { @Override public void invoke(long window, int width, int height) { - glViewport(0, 0, width, height); + correctViewport(width, height); } }; @@ -180,26 +206,29 @@ public class Engine { /* Engine Init */ - Engine engine = new Engine(1280, 720, 9.0f / 16.0f); - int speed = 10; //vitesse déplacement Object + Engine engine = new Engine(1280, 720, 3.0f / 4.0f); + int speed = 10; //vitesse d�placement Object engine.init(); // Add objects to render String path = "textures/zangief_sprite.png"; - String path2 = "textures/awesomeface.png"; + String pathToBG = "textures/background_beach.png"; - ObjectGl zangief = new ObjectGl(0f, 60f, 80f, 10f, path, null); - zangief.setTextureWrap(58, 0, 62, 84, ObjectGl.STICK_TOP); + ObjectGl zangief = new ObjectGl(10.0f, 1f, 1f, 10f, path, null); + zangief.setTextureWrap(58, 0, 62, 84, ObjectGl.DEFAULT); engine.add_objectGl(zangief); - zangief.translate(new Vector3f(-5000.0f, 500.0f, 10.0f)); - zangief.setColor(new Vector3f(1.0f, 1.0f, 1.0f)); - zangief.useTime = true; - zangief.setShader("shaders/StylishShaders/BasicVert.glsl", "shaders/StylishShaders/FlashFrag.glsl"); + zangief.translate(new Vector3f(-1000.0f, 200.0f, 0.0f)); ObjectGl smiley2 = new ObjectGl(0.0f, 500.0f, 500.0f, 1f, path2, null); engine.add_objectGl(smiley2); - smiley2.translate(new Vector3f(0.0f, 0.0f, 5.0f)); + smiley2.translate(new Vector3f(0.0f, 0.0f, 15.0f)); + + //Create background + ObjectGl background = new ObjectGl(0f,1f,1f,10f, pathToBG, null); + background.setTextureWrap(0,0,621, 224, ObjectGl.DEFAULT); + background.translate(new Vector3f(-3011.0f, 1400.0f, 1.0f)); + engine.add_objectGl(background); long timer = System.currentTimeMillis(); long lastFrame; @@ -208,7 +237,7 @@ public class Engine { boolean Joystick1Present = glfwJoystickPresent(GLFW_JOYSTICK_1); /* - * Création des manettes / action + * Cr�ation des manettes / action */ GamepadInput gamepad1 = null; @@ -220,9 +249,6 @@ public class Engine { List listJump = new ArrayList<>(); listJump.add(InputConst.buttonA); jump = new Button("jump", listJump, gamepad1); - - - } @@ -233,18 +259,17 @@ public class Engine { if (Joystick1Present) { gamepad1.inputRefresh(); - - System.out.println(gamepad1.getAxisDiscreet(GLFW_GAMEPAD_AXIS_LEFT_X)); - - // Check si le personnage a sauté + // Check si le personnage a sauté if (jump.isButtonPressed()){ // Le personnage saute System.out.println(" JE SAUTE "); } } -// Input.keyboardInput(zangief, speed); -// input(smiley2, speed); + KeyboardInput.keyboardInput(zangief, speed); + + Vector3f vecTransView = new Vector3f((-zangief.getXPos() - engine.viewXPos) - 250.0f,0.0f,0.0f); + engine.translateView(vecTransView); /* ******************** diff --git a/src/engine/input/KeyboardInput.java b/src/engine/input/KeyboardInput.java index 25fe04c..0bc484c 100644 --- a/src/engine/input/KeyboardInput.java +++ b/src/engine/input/KeyboardInput.java @@ -94,17 +94,20 @@ public class KeyboardInput extends GLFWKeyCallback { keyPressed = true; } else if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_W)) { keyPressed = true; + token.scale(new Vector3f(1.001f,1.001f,1.0f)); } if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_A)) { - token.translate(new Vector3f (speed * -5.0f, 0.0f, 0.0f)); + token.translate(new Vector3f (speed * -1.0f, 0.0f, 0.0f)); token.setTextureWrap(121,0,57,82, ObjectGl.STICK_TOP); keyPressed = true; } else if (KeyboardInput.isKeyDown(GLFW.GLFW_KEY_D)) { - token.translate(new Vector3f (speed * 5.0f, 0.0f, 0.0f)); + token.translate(new Vector3f (speed * 1.0f, 0.0f, 0.0f)); token.setTextureWrap(178,0,62,82, ObjectGl.STICK_TOP); keyPressed = true; } if (!keyPressed) token.setTextureWrap(58,0,62,82, ObjectGl.STICK_TOP); + + token.flipTextureWrapH(); } } diff --git a/src/engine/math/Vector3f.java b/src/engine/math/Vector3f.java index 4f81fee..37cf4de 100644 --- a/src/engine/math/Vector3f.java +++ b/src/engine/math/Vector3f.java @@ -13,6 +13,7 @@ public class Vector3f { public Vector3f(float x, float y){ this.x = x; this.y = y; + this.z = 0.0f; } public Vector3f(float x, float y, float z){ diff --git a/src/engine/object/ObjectGl.java b/src/engine/object/ObjectGl.java index 723cc2d..1abcef6 100644 --- a/src/engine/object/ObjectGl.java +++ b/src/engine/object/ObjectGl.java @@ -27,7 +27,15 @@ public class ObjectGl { public static Matrix4f projection; public static Matrix4f view; + /** + * xPos and yPos will stop to be relevant if you use rotate function + */ + private float xPos; + private float yPos; private float zPos; + private float xAngle; + private float yAngle; + private float zAngle; private float width; // To be used in setTextureWrap private float height; private float scalingFactor; @@ -35,6 +43,7 @@ public class ObjectGl { public boolean useTime; private Texture texture; + private float[] textureWrap; /** * Create a rectangle shape, use setTextureWrap to correctly align the texture with the model @@ -61,15 +70,18 @@ public class ObjectGl { this.texture = new Texture(tex, 0); } + this.xPos = 0.0f; + this.yPos = 0.0f; this.zPos = z; this.height = h; this.width = w; + this.textureWrap = Primitive.stdTexWrap; this.vertexArray = new VertexArray(Primitive.createRectangle(this.zPos, this.width, this.height), Primitive.rectangle_indices, colorBuffer, Primitive.stdTexWrap); - this.scalingFactor = size; + this.scalingFactor = 1; this.transform = Matrix4f.identity(); - this.scale(new Vector3f(size, size,1f)); + this.scale(new Vector3f(size, size,1.0f)); this.stick_state = DEFAULT; this.useTime = false; @@ -92,6 +104,9 @@ public class ObjectGl { public void resetTransform(){ this.transform = Matrix4f.identity(); this.scalingFactor = 1; + this.xPos = 0.0f; + this.yPos = 0.0f; + this.zPos = 0.0f; } /** @@ -99,9 +114,11 @@ public class ObjectGl { * @param vec Vector3f */ public void translate(Vector3f vec){ + this.xPos += vec.x; + this.yPos += vec.y; + this.zPos += vec.z; vec.divXY(this.scalingFactor); this.transform = this.transform.multiply(Matrix4f.translate(vec)); - this.zPos += vec.z; } /** @@ -183,6 +200,19 @@ public class ObjectGl { this.setTextureWrap(result); } + /** + * Reverse the textureWrap left to right + */ + public void flipTextureWrapH(){ + float[] textureWrapTemp = new float[] { + this.textureWrap[2], this.textureWrap[3], + this.textureWrap[0], this.textureWrap[1], + this.textureWrap[6], this.textureWrap[7], + this.textureWrap[4], this.textureWrap[5] + }; + setTextureWrap(textureWrapTemp); + } + /** * Set a new shader to be used by this object * @param vert path to glsl Vertex Shader @@ -207,9 +237,18 @@ public class ObjectGl { } private void setTextureWrap(float[] texture){ + this.textureWrap = texture; this.vertexArray.swapTextureBufferObject(texture); } + public float getXPos(){ + return xPos; + } + + public float getYPos(){ + return yPos; + } + public float getZPos(){ return zPos; } diff --git a/src/launcher/FXMLController.java b/src/launcher/FXMLController.java new file mode 100644 index 0000000..37efe09 --- /dev/null +++ b/src/launcher/FXMLController.java @@ -0,0 +1,25 @@ +package launcher; + +import javafx.fxml.FXML; + +public class FXMLController { + + public FXMLController() { + } + + @FXML + public void launch() { + Launcher.runGame(); + } + + @FXML + public void settings() { + + } + + @FXML + public void quit() { + System.exit(0); + } + +} diff --git a/src/launcher/Launcher.java b/src/launcher/Launcher.java index 5aa98bd..2a32a12 100644 --- a/src/launcher/Launcher.java +++ b/src/launcher/Launcher.java @@ -13,25 +13,54 @@ import javafx.application.Application; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; -import javafx.stage.StageStyle; import javafx.fxml.*; +import engine.Engine; + public class Launcher extends Application { + public static Launcher pointer; + private static Settings setter; + + public Launcher() { + pointer = this; + try { + setter = new Settings(); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } + /* * Start method is used by Launcher as an implementation of the Application class to create a JavaFX thread to display the GUI window */ public void start(Stage primaryStage) throws Exception { - Parent root = FXMLLoader.load(getClass().getResource("ui/launcher.fxml")); + Parent root = FXMLLoader.load(getClass().getResource("launcher.fxml")); Scene main = new Scene(root); - primaryStage.initStyle(StageStyle.UNDECORATED); + //primaryStage.initStyle(StageStyle.UNDECORATED); primaryStage.setTitle("Boulevard Combattant"); primaryStage.setScene(main); primaryStage.show(); + + } + + public static void runGame() { + try { + setter.setSettings(); + Engine.main(null); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } } + public static void openSettings() { + + } + } diff --git a/src/launcher/launcher.fxml b/src/launcher/launcher.fxml new file mode 100644 index 0000000..60d61b8 --- /dev/null +++ b/src/launcher/launcher.fxml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + +