jeu-de-combat/src/engine/TestEngine.java

167 lines
5.7 KiB
Java
Raw Blame History

package engine;
import engine.gui.UIElementText;
import engine.input.*;
import engine.math.Vector3f;
import engine.object.ObjectGl;
import engine.object.Sprite;
import engine.sound.*;
import java.util.ArrayList;
import java.util.List;
import static org.lwjgl.glfw.GLFW.*;
public class TestEngine {
public static void main(String[] args) throws Exception {
/*
OpenAl TEST
*/
SoundManager soundManager = new SoundManager();
soundManager.init();
SoundListener soundListener = new SoundListener();
soundManager.setListener(soundListener);
SoundBuffer jumpSoundBuffer = new SoundBuffer("sound/jump.ogg");
SoundSource soundSource = new SoundSource(false, false);
soundSource.setBuffer(jumpSoundBuffer.getBufferId());
soundManager.addSoundSource("jump", soundSource);
// soundManager.playSoundSource("jump");
/*
Engine Init
*/
Engine engine = new Engine(1280, 720, new Vector3f(4.0f, 3.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";
String pathToText = "textures/dejavu10x10_gs_tc.png";
ObjectGl zangief = new Sprite(10.0f, 10f, path, null);
zangief.setTextureWrap(58, 0, 62, 84, ObjectGl.DEFAULT);
engine.add_objectGl(zangief);
zangief.translate(new Vector3f(-1000.0f, 200.0f, 0.0f));
zangief.setColor(new Vector3f(1.0f, 1.0f, 1.0f));
zangief.setShader("shaders/StylishShaders/BasicVert.glsl", "shaders/StylishShaders/FlashFrag.glsl");
zangief.useTime = true;
ObjectGl zangief2 = new Sprite(9.0f, 10f, path, null);
zangief2.setTextureWrap(58, 0, 62, 84, ObjectGl.DEFAULT);
engine.add_objectGl(zangief2);
zangief2.translate(new Vector3f(1000.0f, 200.0f, 0.0f));
zangief2.flipTextureWrapH();
engine.setCameraTrackingBetweenTwoObjectGl(zangief, zangief2, 1000.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);
// ObjectGl smiley = new Sprite(15.0f, 500.0f, path2, null);
// UIElement uiElement = new UIElement(smiley, 0.0f, 1.0f, engine);
// engine.add_uiElement(uiElement);
UIElementText uiTextTest = new UIElementText("Boulevard Combattant", 5.0f, 0.0f,1.0f, 25.0f, engine);
engine.add_uiElement(uiTextTest);
UIElementText uiTextCoordP1 = new UIElementText("Boulevard Combattant", 7.0f, 0.0f,0.05f, 25.0f, engine);
engine.add_uiElement(uiTextCoordP1);
// Text texTest = new Text("ABCDEFGHIJKLMNOPQRSTUVWYZ",20.0f, 10, engine);
// texTest.show();
// texTest.translate(new Vector3f(-1000.0f, (float) (-1000.0f * (3.0 / 4.0f) + 100.0f)));
long timer = System.currentTimeMillis();
long lastFrame;
int frame = 0;
boolean nextFrame = false;
boolean Joystick1Present = glfwJoystickPresent(GLFW_JOYSTICK_1);
/*
* Cr<43>ation des manettes / action
*/
GamepadInput gamepad1 = null;
Button zoom = null;
Button dezoom = null;
if (Joystick1Present){
gamepad1 = new GamepadInput(GLFW_JOYSTICK_1);
gamepad1.inputRefresh();
}
List<Integer> listZoomPlus = new ArrayList<>();
listZoomPlus.add(InputConst.buttonA);
List<Integer> listZoomMinusKeyboard = new ArrayList<>();
listZoomMinusKeyboard.add(GLFW_KEY_R);
List<Integer> listZoomMinus = new ArrayList<>();
listZoomMinus.add(InputConst.buttonB);
List<Integer> listZoomPlusKeyboard = new ArrayList<>();
listZoomPlusKeyboard.add(GLFW_KEY_F);
zoom = new Button("zoom", listZoomPlus, listZoomPlusKeyboard, gamepad1);
dezoom = new Button("dezoom", listZoomMinus, listZoomMinusKeyboard, gamepad1);
engine.translateView(new Vector3f(0.0f, -125.0f, 0.0f));
while (engine.getRunning()) {
lastFrame = System.currentTimeMillis();
// Game logic should fit here
if (Joystick1Present) {
gamepad1.inputRefresh();
}
// Check si le personnage a sauté
if (zoom.isButtonPressed()){
// Le personnage saute
engine.getCamera().zoom(1.001f);
}if(dezoom.isButtonPressed()){
engine.getCamera().zoom(0.999f);
}
// engine.cameraTrackingObjectGl(zangief, -250.0f);
engine.cameraTrackingBetweenTwoObjectGl();
uiTextCoordP1.setText("X: " + zangief.getXPos() + " Y: " + zangief.getYPos());
KeyboardInput.keyboardInput(zangief, speed);
/*
********************
* essential part v *
********************
*/
engine.update();
engine.render();
frame++;
if (System.currentTimeMillis() - timer > 1000) {
timer += 1000;
System.out.println("FPS: " + frame);
uiTextTest.setText("FPS: " + frame);
frame = 0;
}
// while (!nextFrame) {
// nextFrame = System.currentTimeMillis() - lastFrame >= 16.66f;
// }
nextFrame = false;
if (engine.shouldClose()) engine.setRunning(false);
}
soundManager.cleanup();
}
}