diff --git a/build.gradle b/build.gradle index 8ded79c..b04d703 100644 --- a/build.gradle +++ b/build.gradle @@ -26,8 +26,9 @@ repositories { dependencies { compile 'Suplge:suplge:1.0' compile 'Suplge:suplge-opengl:1.0' + compile 'io.socket:socket.io-client:0.8.3' } shadowJar { baseName = 'GraviRush' -} \ No newline at end of file +} diff --git a/src/main/java/fr/adamaq01/gravirush/GraviRush.java b/src/main/java/fr/adamaq01/gravirush/GraviRush.java index 3389571..d2f76a7 100644 --- a/src/main/java/fr/adamaq01/gravirush/GraviRush.java +++ b/src/main/java/fr/adamaq01/gravirush/GraviRush.java @@ -1,12 +1,15 @@ package fr.adamaq01.gravirush; -import fr.adamaq01.gravirush.screens.Credits; -import fr.adamaq01.gravirush.screens.MainMenu; +import fr.adamaq01.gravirush.screens.*; import fr.adamaq01.suplge.SuplgeEngine; import fr.adamaq01.suplge.api.Game; import fr.adamaq01.suplge.input.ControllerManager; +import fr.adamaq01.suplge.input.KeyboardManager; import fr.adamaq01.suplge.input.glfw.GLFWController; +import fr.adamaq01.suplge.input.glfw.GLFWKeyboard; import fr.adamaq01.suplge.opengl.GLWindow; +import io.socket.client.IO; +import io.socket.client.Socket; import java.net.URISyntaxException; @@ -15,13 +18,33 @@ */ public class GraviRush extends Game { + private static Socket socket; + public static void main(String[] args) throws URISyntaxException { SuplgeEngine.setResourcesURL("https://www.adamaq01.fr/files/test/"); new GraviRush().start(); } + public static Socket getSocket() { + return socket; + } + public GraviRush() { - super(new GLWindow("GraviRush", null/*new GLImage(SuplgeEngine.getResource("test.png"))*/, 640, 480, false, 60, 128, SuplgeEngine.getResource("Prototype.ttf"), 48), new MainMenu(), new Credits()); + super(new GLWindow("GraviRush", null/*new GLImage(SuplgeEngine.getResource("test.png"))*/, 640, 480, false, 60, 128, SuplgeEngine.getResource("Prototype.ttf"), 48), new MainMenu(), new InGame(), new Options(), new Credits(), new Llaw()); ControllerManager.MANAGER.add(new GLFWController()); + KeyboardManager.MANAGER.add(new GLFWKeyboard(getWindow().getWindowHandle())); + + try { + GraviRush.socket = IO.socket("https://lellaw.adamaq01.fr/"); + } catch (URISyntaxException e) { + e.printStackTrace(); + } + GraviRush.socket.connect(); + } + + @Override + public void stop() { + super.stop(); + GraviRush.socket.disconnect(); } } diff --git a/src/main/java/fr/adamaq01/gravirush/Screens.java b/src/main/java/fr/adamaq01/gravirush/Screens.java index 1b50d5c..3d02d74 100644 --- a/src/main/java/fr/adamaq01/gravirush/Screens.java +++ b/src/main/java/fr/adamaq01/gravirush/Screens.java @@ -8,6 +8,6 @@ public class Screens { public static final int MAIN_MENU = 0; public static final int GAME = 1; public static final int OPTIONS = 2; - public static final int CREDITS = 1; // 3 - + public static final int CREDITS = 3; + public static final int LLAW = 4; } diff --git a/src/main/java/fr/adamaq01/gravirush/Stage.java b/src/main/java/fr/adamaq01/gravirush/Stage.java new file mode 100644 index 0000000..353666d --- /dev/null +++ b/src/main/java/fr/adamaq01/gravirush/Stage.java @@ -0,0 +1,79 @@ +package fr.adamaq01.gravirush; + +import fr.adamaq01.suplge.api.Game; +import fr.adamaq01.suplge.api.graphics.Color; +import fr.adamaq01.suplge.api.graphics.IGraphics; +import fr.adamaq01.suplge.opengl.graphics.shapes.Rectangle; + +import java.util.Random; + +/** + * Created by Adamaq01 on 22/04/2017. + */ +public class Stage { + + private Random random; + private boolean level[][]; + + private int doorX, doorY; + + public void init(Game game) { + random = new Random(); + level = new boolean[1000][1000]; + + for(int x = 0; x < 1000; x++) { + for(int y = 0; y < 1000; y++) { + boolean draw = random.nextInt(100) > 30; + level[x][y] = !draw; + } + } + + generateDoor(game); + + } + + public void generateDoor(Game game) { + int doorX = random.nextInt(game.getWindow().getWidth() / 24); + int doorY = random.nextInt(game.getWindow().getWidth() / 24); + + if(level[doorX][doorY] && !level[doorX][doorY + (32 / 24)]) { + this.doorX = doorX; + this.doorY = doorY + (32 / 24); + } else { + generateDoor(game); + } + } + + public void update(Game game, int playerX, int playerY, double delta) { + if(new Rectangle(16, 32).collides(playerX, playerY, doorX * 24, doorY * 24)) { + GraviRush.getSocket().emit("changepixel"); + game.setCurrentScreen(Screens.MAIN_MENU); + } + } + + public void drawStage(IGraphics graphics) { + for(int x = 0; x < graphics.getWindow().getWidth() / 24; x++) { + for (int y = 0; y < graphics.getWindow().getHeight() / 24; y++) { + if(level[x][y]) { + graphics.setColor(new Color(77, 51, 25)); + graphics.fillShape(new Rectangle(32, 32), x * 24, y * 24); + graphics.setColor(new Color(0, 153, 51)); + graphics.fillShape(new Rectangle(32, 4), x * 24, y * 24 + 28); + } + } + } + graphics.drawShape(new Rectangle(16, 32), doorX * 24, doorY * 24); + } + + public boolean collides(Game game, int x, int y) { + for(int rectx = 0; rectx < game.getWindow().getWidth() / 24; rectx++) { + for (int recty = 0; recty < game.getWindow().getHeight() / 24; recty++) { + if(level[rectx][recty]) { + new Rectangle(32, 32).collides(x, y, rectx * 24, recty * 24); + } + } + } + return false; + } + +} diff --git a/src/main/java/fr/adamaq01/gravirush/screens/Credits.java b/src/main/java/fr/adamaq01/gravirush/screens/Credits.java index 884256c..d443e1a 100644 --- a/src/main/java/fr/adamaq01/gravirush/screens/Credits.java +++ b/src/main/java/fr/adamaq01/gravirush/screens/Credits.java @@ -1,14 +1,19 @@ package fr.adamaq01.gravirush.screens; import fr.adamaq01.gravirush.Screens; +import fr.adamaq01.suplge.SuplgeEngine; import fr.adamaq01.suplge.api.Game; +import fr.adamaq01.suplge.api.IImage; import fr.adamaq01.suplge.api.IScreen; import fr.adamaq01.suplge.api.graphics.Color; import fr.adamaq01.suplge.api.input.controllers.IController; import fr.adamaq01.suplge.input.ControllerManager; import fr.adamaq01.suplge.opengl.GLWindow; import fr.adamaq01.suplge.opengl.graphics.GLGraphics; +import fr.adamaq01.suplge.opengl.utils.GLImage; +import javax.imageio.ImageIO; +import java.io.IOException; import java.util.Random; /** @@ -41,7 +46,7 @@ public void render(Game game, GLGraphics glGraphics) { glGraphics.drawString("Jeu cree par:", game.getWindow().getWidth() / 2 - ("Jeu cree par:".length() * "Jeu cree par:".length()), game.getWindow().getHeight() / 2, 1); glGraphics.setRotation(random.nextInt(22) - 11); glGraphics.setColor(new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256))); - glGraphics.drawString("Adamaq01", game.getWindow().getWidth() / 2 - ("Adamaq01".length() * "Adamaq01".length()), game.getWindow().getHeight() / 2 + 48, 1); + glGraphics.drawString("Adamaq01", game.getWindow().getWidth() / 2 - ("Adamaq01".length() * "Adamaq01".length()), game.getWindow().getHeight() / 2 - 48, 1); glGraphics.setRotation(0); } } diff --git a/src/main/java/fr/adamaq01/gravirush/screens/InGame.java b/src/main/java/fr/adamaq01/gravirush/screens/InGame.java new file mode 100644 index 0000000..e5278ed --- /dev/null +++ b/src/main/java/fr/adamaq01/gravirush/screens/InGame.java @@ -0,0 +1,115 @@ +package fr.adamaq01.gravirush.screens; + +import fr.adamaq01.gravirush.Stage; +import fr.adamaq01.suplge.SuplgeEngine; +import fr.adamaq01.suplge.api.Game; +import fr.adamaq01.suplge.api.IImage; +import fr.adamaq01.suplge.api.IScreen; +import fr.adamaq01.suplge.api.graphics.Color; +import fr.adamaq01.suplge.api.graphics.IGraphics; +import fr.adamaq01.suplge.api.input.controllers.IController; +import fr.adamaq01.suplge.api.input.keyboards.IKeyboard; +import fr.adamaq01.suplge.input.ControllerManager; +import fr.adamaq01.suplge.input.KeyboardManager; +import fr.adamaq01.suplge.opengl.GLWindow; +import fr.adamaq01.suplge.opengl.graphics.GLGraphics; +import fr.adamaq01.suplge.opengl.graphics.shapes.Rectangle; +import fr.adamaq01.suplge.opengl.utils.GLImage; + +/** + * Created by Adamaq01 on 22/04/2017. + */ +public class InGame implements IScreen { + + private int x, y; + private long lastInput; + + // Animation + private IImage tutter; + private int index; + private long lastAnimationChange; + + // Stage + private Stage stage; + private boolean inStage; + + @Override + public void onEnable(Game game) { + this.stage = new Stage(); + this.tutter = new GLImage(SuplgeEngine.getResource("tutter.png")); + this.index = 0; + this.lastAnimationChange = System.currentTimeMillis(); + this.x = 0; + this.y = 0; + this.stage.init(game); + this.inStage = false; + } + + @Override + public void onDisable(Game game) { + + } + + @Override + public void update(Game game, double delta) { + IController controller = ControllerManager.MANAGER.get(0); + IKeyboard keyboard = KeyboardManager.MANAGER.get(0); + + if(inStage) { + + + if (controller.getJoyStickValue(IController.JoyStick.JOY_STICK_1, IController.ControllerAxe.AXE_JOY_STICK_VERTICAL) < -0.3 || controller.isButtonPressed(IController.Button.BUTTON_CROSSPAD_DOWN) || keyboard.isKeyPressed(IKeyboard.Key.KEY_S)) + y -= 1 * delta; + if (controller.getJoyStickValue(IController.JoyStick.JOY_STICK_1, IController.ControllerAxe.AXE_JOY_STICK_VERTICAL) > 0.3 || controller.isButtonPressed(IController.Button.BUTTON_CROSSPAD_UP) || keyboard.isKeyPressed(IKeyboard.Key.KEY_Z)) + y += 1 * delta; + if (controller.getJoyStickValue(IController.JoyStick.JOY_STICK_1, IController.ControllerAxe.AXE_JOY_STICK_HORIZONTAL) < -0.3 || controller.isButtonPressed(IController.Button.BUTTON_CROSSPAD_LEFT) || keyboard.isKeyPressed(IKeyboard.Key.KEY_Q)) + x -= 1 * delta; + if (controller.getJoyStickValue(IController.JoyStick.JOY_STICK_1, IController.ControllerAxe.AXE_JOY_STICK_HORIZONTAL) > 0.3 || controller.isButtonPressed(IController.Button.BUTTON_CROSSPAD_RIGHT) || keyboard.isKeyPressed(IKeyboard.Key.KEY_D)) + x += 1 * delta; + + + stage.update(game, x, y, delta); + if (System.currentTimeMillis() - this.lastAnimationChange > 83) { + this.lastAnimationChange = System.currentTimeMillis(); + if (this.index == 10) + this.index = 0; + else + this.index++; + } + } else { + if(System.currentTimeMillis() - lastInput > 1200) { + lastInput = System.currentTimeMillis(); + if (controller.isButtonPressed(IController.Button.BUTTON_ACTION_DOWN)) { + this.stage = new Stage(); + this.stage.init(game); + }else if (controller.isButtonPressed(IController.Button.BUTTON_ACTION_RIGHT)) { + inStage = true; + } + } + } + } + + @Override + public void render(Game game, GLGraphics glGraphics) { + if(inStage) { + renderStage(game, glGraphics); + } else { + renderStageChooser(game, glGraphics); + } + } + + public void renderStage(Game game, IGraphics graphics) { + stage.drawStage(graphics); + graphics.drawImage(tutter.sub(0, 256 * index, 256, 256), x, y, 24, 24, false); + } + + public void renderStageChooser(Game game, IGraphics graphics) { + stage.drawStage(graphics); + graphics.setColor(Color.SILVER); + graphics.fillShape(new Rectangle(game.getWindow().getWidth(), game.getWindow().getHeight() / 40), 0, 0); + graphics.fillShape(new Rectangle(game.getWindow().getWidth(), game.getWindow().getHeight() / 40), 0, game.getWindow().getHeight() - game.getWindow().getHeight() / 40); + graphics.fillShape(new Rectangle(game.getWindow().getWidth() / 40, game.getWindow().getHeight()), 0, 0); + graphics.fillShape(new Rectangle(game.getWindow().getWidth() / 40, game.getWindow().getHeight()), game.getWindow().getWidth() - game.getWindow().getWidth() / 40, 0); + } + +} diff --git a/src/main/java/fr/adamaq01/gravirush/screens/Llaw.java b/src/main/java/fr/adamaq01/gravirush/screens/Llaw.java new file mode 100644 index 0000000..bb973fc --- /dev/null +++ b/src/main/java/fr/adamaq01/gravirush/screens/Llaw.java @@ -0,0 +1,45 @@ +package fr.adamaq01.gravirush.screens; + +import fr.adamaq01.gravirush.Screens; +import fr.adamaq01.suplge.SuplgeEngine; +import fr.adamaq01.suplge.api.Game; +import fr.adamaq01.suplge.api.IImage; +import fr.adamaq01.suplge.api.IScreen; +import fr.adamaq01.suplge.api.graphics.Color; +import fr.adamaq01.suplge.api.input.controllers.IController; +import fr.adamaq01.suplge.input.ControllerManager; +import fr.adamaq01.suplge.opengl.GLWindow; +import fr.adamaq01.suplge.opengl.graphics.GLGraphics; +import fr.adamaq01.suplge.opengl.utils.GLImage; + +import java.util.Random; + +/** + * Created by Adamaq01 on 22/04/2017. + */ +public class Llaw implements IScreen { + + private IImage lellaw; + + @Override + public void onEnable(Game game) { + this.lellaw = new GLImage(SuplgeEngine.getResourceWithoutBaseURL("https://lellaw.adamaq01.fr/")); + } + + @Override + public void onDisable(Game game) { + } + + @Override + public void update(Game game, double v) { + IController controller = ControllerManager.MANAGER.get(0); + if(controller.isButtonPressed(IController.Button.BUTTON_ACTION_DOWN)) { + game.setCurrentScreen(Screens.MAIN_MENU); + } + } + + @Override + public void render(Game game, GLGraphics glGraphics) { + glGraphics.drawImage(this.lellaw, 0, 0, game.getWindow().getWidth(), game.getWindow().getHeight(), false); + } +} diff --git a/src/main/java/fr/adamaq01/gravirush/screens/MainMenu.java b/src/main/java/fr/adamaq01/gravirush/screens/MainMenu.java index bae2b42..497049a 100644 --- a/src/main/java/fr/adamaq01/gravirush/screens/MainMenu.java +++ b/src/main/java/fr/adamaq01/gravirush/screens/MainMenu.java @@ -7,7 +7,9 @@ import fr.adamaq01.suplge.api.IScreen; import fr.adamaq01.suplge.api.graphics.Color; import fr.adamaq01.suplge.api.input.controllers.IController; +import fr.adamaq01.suplge.api.input.keyboards.IKeyboard; import fr.adamaq01.suplge.input.ControllerManager; +import fr.adamaq01.suplge.input.KeyboardManager; import fr.adamaq01.suplge.input.glfw.GLFWController; import fr.adamaq01.suplge.opengl.GLWindow; import fr.adamaq01.suplge.opengl.graphics.GLGraphics; @@ -16,6 +18,7 @@ import fr.adamaq01.suplge.opengl.utils.GLImage; import java.nio.file.Paths; +import java.util.HashMap; /** * Created by Adamaq01 on 22/04/2017. @@ -24,11 +27,16 @@ public class MainMenu implements IScreen { private int selection; private IImage background; + private HashMap yCoordinates = new HashMap<>(); @Override public void onEnable(Game game) { this.selection = 0; this.background = new GLImage(SuplgeEngine.getResource("background.jpg")); + this.yCoordinates.put(0, 400); + this.yCoordinates.put(1, 300); + this.yCoordinates.put(2, 200); + this.yCoordinates.put(3, 100); } @Override @@ -41,29 +49,29 @@ public void onDisable(Game game) { @Override public void update(Game game, double delta) { IController controller = ControllerManager.MANAGER.get(0); + IKeyboard keyboard = KeyboardManager.MANAGER.get(0); if(!game.isPaused()) { - handleSelection(game, controller); + handleSelection(game, controller, keyboard); } } @Override public void render(Game game, GLGraphics glGraphics) { - if(!game.isPaused()) { - if(!glGraphics.isOrtho()) { - glGraphics.setOrtho(true); - } - glGraphics.setRotation(0); - glGraphics.drawImage(background, 0, 0, game.getWindow().getWidth(), game.getWindow().getHeight(), false); - glGraphics.setColor(Color.WHITE); - glGraphics.drawString("Commencer", 100, 100, 1); - glGraphics.drawString("Options", 100, 200, 1); - glGraphics.drawString("Credits", 100, 300, 1); - glGraphics.fillShape(new Circle(20), (100 / 2) - (30 / 2), this.selection * (100 / 2) + (100 / 2) - (20 / 2)); + if(!glGraphics.isOrtho()) { + glGraphics.setOrtho(true); } + glGraphics.setRotation(0); + glGraphics.drawImage(background, 0, 0, game.getWindow().getWidth(), game.getWindow().getHeight(), false); + glGraphics.setColor(Color.WHITE); + glGraphics.drawString("Commencer", 100, 400, 1); + glGraphics.drawString("Options", 100, 300, 1); + glGraphics.drawString("Credits", 100, 200, 1); + glGraphics.drawString("Le Llaw", 100, 100, 1); + glGraphics.fillShape(new Circle(20), (100 / 2) + (100 / 4), yCoordinates.get(this.selection) - 10); } - private void handleSelection(Game game, IController controller) { - if(controller.isButtonPressed(IController.Button.BUTTON_ACTION_RIGHT)) { + private void handleSelection(Game game, IController controller, IKeyboard keyboard) { + if(controller.isButtonPressed(IController.Button.BUTTON_ACTION_RIGHT) || keyboard.isKeyPressed(IKeyboard.Key.KEY_A)) { switch(this.selection) { case 0: game.setCurrentScreen(Screens.GAME); @@ -74,19 +82,22 @@ private void handleSelection(Game game, IController controller) { case 2: game.setCurrentScreen(Screens.CREDITS); break; + case 3: + game.setCurrentScreen(Screens.LLAW); + break; } } if(System.currentTimeMillis() - lastChange > 125) { lastChange = System.currentTimeMillis(); - if (controller.getJoyStickValue(IController.JoyStick.JOY_STICK_1, IController.ControllerAxe.AXE_JOY_STICK_VERTICAL) < -0.1 || controller.isButtonPressed(IController.Button.BUTTON_CROSSPAD_DOWN)) - if (this.selection == 2) + if (controller.getJoyStickValue(IController.JoyStick.JOY_STICK_1, IController.ControllerAxe.AXE_JOY_STICK_VERTICAL) < -0.3 || controller.isButtonPressed(IController.Button.BUTTON_CROSSPAD_DOWN) || keyboard.isKeyPressed(IKeyboard.Key.KEY_S)) + if (this.selection == 3) this.selection = 0; else this.selection++; - else if (controller.getJoyStickValue(IController.JoyStick.JOY_STICK_1, IController.ControllerAxe.AXE_JOY_STICK_VERTICAL) > 0.1 || controller.isButtonPressed(IController.Button.BUTTON_CROSSPAD_UP)) + else if (controller.getJoyStickValue(IController.JoyStick.JOY_STICK_1, IController.ControllerAxe.AXE_JOY_STICK_VERTICAL) > 0.3 || controller.isButtonPressed(IController.Button.BUTTON_CROSSPAD_UP) || keyboard.isKeyPressed(IKeyboard.Key.KEY_Z)) if (this.selection == 0) - this.selection = 2; + this.selection = 3; else this.selection--; } diff --git a/src/main/java/fr/adamaq01/gravirush/screens/Options.java b/src/main/java/fr/adamaq01/gravirush/screens/Options.java new file mode 100644 index 0000000..590b430 --- /dev/null +++ b/src/main/java/fr/adamaq01/gravirush/screens/Options.java @@ -0,0 +1,32 @@ +package fr.adamaq01.gravirush.screens; + +import fr.adamaq01.suplge.api.Game; +import fr.adamaq01.suplge.api.IScreen; +import fr.adamaq01.suplge.opengl.GLWindow; +import fr.adamaq01.suplge.opengl.graphics.GLGraphics; + +/** + * Created by Adamaq01 on 22/04/2017. + */ +public class Options implements IScreen { + + @Override + public void onEnable(Game game) { + + } + + @Override + public void onDisable(Game game) { + + } + + @Override + public void update(Game game, double v) { + + } + + @Override + public void render(Game game, GLGraphics glGraphics) { + + } +}