Skip to content

Commit

Permalink
Hahahaha, it's partially finished !
Browse files Browse the repository at this point in the history
  • Loading branch information
adamaq01 committed Apr 23, 2017
1 parent f3d54db commit 6ff4384
Show file tree
Hide file tree
Showing 9 changed files with 336 additions and 25 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
29 changes: 26 additions & 3 deletions src/main/java/fr/adamaq01/gravirush/GraviRush.java
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -15,13 +18,33 @@
*/
public class GraviRush extends Game<GLWindow> {

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();
}
}
4 changes: 2 additions & 2 deletions src/main/java/fr/adamaq01/gravirush/Screens.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
79 changes: 79 additions & 0 deletions src/main/java/fr/adamaq01/gravirush/Stage.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
7 changes: 6 additions & 1 deletion src/main/java/fr/adamaq01/gravirush/screens/Credits.java
Original file line number Diff line number Diff line change
@@ -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;

/**
Expand Down Expand Up @@ -41,7 +46,7 @@ public void render(Game<GLWindow> 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);
}
}
115 changes: 115 additions & 0 deletions src/main/java/fr/adamaq01/gravirush/screens/InGame.java
Original file line number Diff line number Diff line change
@@ -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<GLWindow, GLGraphics> {

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<GLWindow> 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<GLWindow> game) {

}

@Override
public void update(Game<GLWindow> 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<GLWindow> 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);
}

}
45 changes: 45 additions & 0 deletions src/main/java/fr/adamaq01/gravirush/screens/Llaw.java
Original file line number Diff line number Diff line change
@@ -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<GLWindow, GLGraphics> {

private IImage lellaw;

@Override
public void onEnable(Game<GLWindow> game) {
this.lellaw = new GLImage(SuplgeEngine.getResourceWithoutBaseURL("https://lellaw.adamaq01.fr/"));
}

@Override
public void onDisable(Game<GLWindow> game) {
}

@Override
public void update(Game<GLWindow> 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<GLWindow> game, GLGraphics glGraphics) {
glGraphics.drawImage(this.lellaw, 0, 0, game.getWindow().getWidth(), game.getWindow().getHeight(), false);
}
}
Loading

0 comments on commit 6ff4384

Please sign in to comment.