V1
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 4 KiB |
Before Width: | Height: | Size: 30 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 8.8 KiB After Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 5.1 KiB |
BIN
res/textures/murmilieubas.png
Normal file
After Width: | Height: | Size: 160 B |
Before Width: | Height: | Size: 176 B After Width: | Height: | Size: 176 B |
BIN
res/textures/murmilieumilieu.png
Normal file
After Width: | Height: | Size: 160 B |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 1.6 KiB |
|
@ -2,16 +2,18 @@ package globalgamejam.game;
|
|||
|
||||
public enum EObjetType {
|
||||
|
||||
POISSON("res/textures/dechets1.png",-20),POMME("res/textures/dechets.png",-30),
|
||||
ETOILE_DE_MER("res/textures/bonus1.png",20),COQUILLAGE("res/textures/bonus2.png",30),
|
||||
COQUILLAGE2("res/textures/bonus3.png",40),BANANE("res/textures/banane.png",50);
|
||||
POISSON("res/textures/dechets1.png",-2, 0.5f),POMME("res/textures/dechets.png",-3, 0.5f),
|
||||
ETOILE_DE_MER("res/textures/bonus1.png",2, 0.5f),COQUILLAGE("res/textures/bonus2.png",3, 0.5f),
|
||||
COQUILLAGE2("res/textures/bonus3.png",4, 0.5f),BANANE("res/textures/banane.png",-5, 0.5f);
|
||||
|
||||
private int points;
|
||||
private String filename;
|
||||
private float despawnRate;
|
||||
|
||||
EObjetType(String filename,int points){
|
||||
EObjetType(String filename, int points, float despawnRate){
|
||||
this.points = points;
|
||||
this.filename = filename;
|
||||
this.despawnRate = despawnRate;
|
||||
}
|
||||
|
||||
public int getPoints() {
|
||||
|
@ -22,4 +24,7 @@ public enum EObjetType {
|
|||
return filename;
|
||||
}
|
||||
|
||||
public float getDespawnRate(){
|
||||
return this.despawnRate;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,24 +12,28 @@ import globalgamejam.world.MainWorld;
|
|||
*/
|
||||
public class MainGame extends Game{
|
||||
|
||||
public static final int MAX_SCORE = 1000;
|
||||
public static final int SCORE_INIT = 200;
|
||||
public static final float START_TIMER = 300;
|
||||
public static float time_in_sec = 0;
|
||||
private MainWorld world;
|
||||
private MainInterfaces interfaces;
|
||||
public int[] scores;
|
||||
public float[] scores;
|
||||
public final int helpKey = GLFW.GLFW_KEY_H;
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
this.scores = new int[2];
|
||||
this.scores[0] = MAX_SCORE;
|
||||
this.scores[1] = MAX_SCORE;
|
||||
this.scores = new float[2];
|
||||
this.scores[0] = SCORE_INIT;
|
||||
this.scores[1] = SCORE_INIT;
|
||||
time_in_sec = START_TIMER;
|
||||
world = new MainWorld(this);
|
||||
interfaces = new MainInterfaces(this);
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
this.scores[0] = MAX_SCORE;
|
||||
this.scores[1] = MAX_SCORE;
|
||||
this.scores[0] = SCORE_INIT;
|
||||
this.scores[1] = SCORE_INIT;
|
||||
time_in_sec = START_TIMER;
|
||||
world.destroy();
|
||||
world = new MainWorld(this);
|
||||
world.init();
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package globalgamejam.game;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import globalgamejam.Main;
|
||||
import globalgamejam.math.Color4f;
|
||||
import globalgamejam.math.Vector2f;
|
||||
import globalgamejam.physics.PhysicalEntity;
|
||||
import globalgamejam.tiles.ObjetTile;
|
||||
|
@ -7,7 +11,11 @@ import globalgamejam.tiles.Tile;
|
|||
|
||||
public class Objet extends PhysicalEntity {
|
||||
|
||||
private static final int TIME_IN_SEC = 5;
|
||||
|
||||
private EObjetType type;
|
||||
private float inactiveDelay = 0;
|
||||
private float despawnRate;
|
||||
private final Tile tile;
|
||||
|
||||
public Objet(String texturePath, float x, float y, float speed, float xVelocity, float yVelocity, float frictionFactor){
|
||||
|
@ -39,7 +47,22 @@ public class Objet extends PhysicalEntity {
|
|||
|
||||
public void setType(EObjetType type) {
|
||||
this.type = type;
|
||||
this.despawnRate = this.type.getDespawnRate();
|
||||
}
|
||||
|
||||
public float getInactiveDelay() {
|
||||
return inactiveDelay;
|
||||
}
|
||||
|
||||
public boolean underWave(float yWave){
|
||||
return yWave >= this.y + this.getSizeRadius();
|
||||
}
|
||||
|
||||
public boolean shouldDespawn(){
|
||||
if(this.despawnRate >= Math.random()){
|
||||
return true;
|
||||
}
|
||||
this.despawnRate *= 1.05f;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,9 @@ public class Player extends PhysicalEntity {
|
|||
private final PhysicalEntity brosse;
|
||||
private final float longueurBalai;
|
||||
|
||||
public Player(float x, float y){
|
||||
public Player(String path, float x, float y){
|
||||
super(x, y, 0, 0, 3, 0, 0, 10);
|
||||
this.tile = new PlayerTile("res/textures/perso.png", x, y);
|
||||
this.tile = new PlayerTile(path, x, y);
|
||||
|
||||
this.setSizeXY(this.tile.getTexture().width, this.tile.getTexture().height);
|
||||
|
||||
|
|
|
@ -3,13 +3,18 @@ package globalgamejam.input;
|
|||
|
||||
import static org.lwjgl.glfw.GLFW.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.*;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.lwjgl.glfw.*;
|
||||
import org.lwjgl.glfw.GLFWCursorPosCallback;
|
||||
import org.lwjgl.glfw.GLFWJoystickCallback;
|
||||
import org.lwjgl.glfw.GLFWScrollCallback;
|
||||
|
||||
import globalgamejam.*;
|
||||
import globalgamejam.math.*;
|
||||
import globalgamejam.Main;
|
||||
import globalgamejam.math.Vector2f;
|
||||
|
||||
/**
|
||||
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
|
||||
|
@ -18,6 +23,9 @@ public class Input{
|
|||
|
||||
public static GLFWScrollCallback scroll;
|
||||
public static GLFWCursorPosCallback mousePos;
|
||||
public static GLFWJoystickCallback joyCall;
|
||||
|
||||
private static ArrayList<Integer> joysticks = new ArrayList<Integer>();
|
||||
|
||||
private static Vector2f mousePosition = new Vector2f();
|
||||
private static Vector2f dMouse = new Vector2f();
|
||||
|
@ -25,13 +33,33 @@ public class Input{
|
|||
|
||||
public static final int NONE = 0,PRESSED = 1,RELEASED = 2,REPEATED = 3,UP = 4,DOWN = 5,
|
||||
NBRE_KEY = 0x15D,NBRE_BUTTON = 10,
|
||||
MOUSE_OFFSET = NBRE_KEY + 1,MOUSE_WHEEL_OFFSET = MOUSE_OFFSET + 1;
|
||||
MOUSE_OFFSET = NBRE_KEY + 1,MOUSE_WHEEL_OFFSET = MOUSE_OFFSET + 1,
|
||||
NBRE_MAX_JOYSTICK = 16;
|
||||
|
||||
private static HashMap<Integer,Integer> state = new HashMap<Integer,Integer>();
|
||||
|
||||
private static double ywheel = 0;
|
||||
|
||||
public static void init(){
|
||||
for(int i = 0;i < NBRE_MAX_JOYSTICK;i++){
|
||||
if(glfwJoystickPresent(GLFW_JOYSTICK_1 + i))joysticks.add(GLFW_JOYSTICK_1 + i);
|
||||
}
|
||||
glfwSetJoystickCallback(joyCall = new GLFWJoystickCallback() {
|
||||
|
||||
@Override
|
||||
public void invoke(int id, int event) {
|
||||
if (event == GLFW_CONNECTED)
|
||||
{
|
||||
joysticks.add(id);
|
||||
System.out.println(glfwGetJoystickName(id) + " connecter");
|
||||
}
|
||||
else if (event == GLFW_DISCONNECTED)
|
||||
{
|
||||
joysticks.remove(id);
|
||||
System.out.println("Manettes #" + id + " deconnecter");
|
||||
}
|
||||
}
|
||||
});
|
||||
glfwSetScrollCallback(Main.windowID, scroll = new GLFWScrollCallback() {
|
||||
public void invoke(long window, double xoffset, double yoffset) {
|
||||
scroll(window, xoffset, yoffset);
|
||||
|
@ -243,6 +271,16 @@ public class Input{
|
|||
return MOUSE_WHEEL_OFFSET;
|
||||
}
|
||||
|
||||
public static FloatBuffer getJoysticksAxis(int i){
|
||||
return glfwGetJoystickAxes(joysticks.get(i));
|
||||
}
|
||||
|
||||
public static ByteBuffer getJoysticksButton(int i){
|
||||
return glfwGetJoystickButtons(joysticks.get(i));
|
||||
}
|
||||
|
||||
public static ArrayList<Integer> getJoysticks() {
|
||||
return joysticks;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,15 +17,30 @@ import org.lwjgl.glfw.GLFW;
|
|||
*/
|
||||
public class MainInterfaces {
|
||||
|
||||
private final int SIZE_OF_DETAILS = 100;
|
||||
|
||||
private MainGame game;
|
||||
|
||||
private ArrayList<GUI> guis;
|
||||
|
||||
private GUILabel p1,p2;
|
||||
private GUILabel p1,p2,timer;
|
||||
|
||||
private ArrayList<GUI> guisHelp;
|
||||
private GUILabel helpLabel;
|
||||
private GUILabel joueur1Help;
|
||||
private GUILabel joueur1HelpRotationG;
|
||||
private GUILabel joueur1HelpRotationD;
|
||||
private GUILabel joueur1HelpDeplacementVerticaleH;
|
||||
private GUILabel joueur1HelpDeplacementVerticaleB;
|
||||
private GUILabel joueur1HelpDeplacementHorizontaleG;
|
||||
private GUILabel joueur1HelpDeplacementHorizontaleD;
|
||||
private GUILabel joueur2Help;
|
||||
private GUILabel joueur2HelpRotationG;
|
||||
private GUILabel joueur2HelpRotationD;
|
||||
private GUILabel joueur2HelpDeplacementVerticaleH;
|
||||
private GUILabel joueur2HelpDeplacementVerticaleB;
|
||||
private GUILabel joueur2HelpDeplacementHorizontaleG;
|
||||
private GUILabel joueur2HelpDeplacementHorizontaleD;
|
||||
private GUILabel manetteHelp;
|
||||
private GUILabel manetteHelpDirection;
|
||||
private GUILabel manetteHelpRotation;
|
||||
|
||||
private ArrayList<GUI> guisPartieTerminer;
|
||||
private GUILabel labelPartieTerminer;
|
||||
|
@ -41,15 +56,71 @@ public class MainInterfaces {
|
|||
}
|
||||
|
||||
public void init(){
|
||||
p1 = new GUILabel("Player 1 : ", Main.WIDTH/4 - 50,10, Color.BLACK,"Arial",16);
|
||||
p2 = new GUILabel("Player 2 : ", Main.WIDTH/4 * 3 - 50,10, Color.BLACK,"Arial",16);
|
||||
p1 = new GUILabel("Player 1 : ", Main.WIDTH/4,10, Color.BLACK,"Arial",16);
|
||||
p2 = new GUILabel("Player 2 : ", Main.WIDTH/4 * 3,10, Color.BLACK,"Arial",16);
|
||||
timer = new GUILabel(" ", Main.WIDTH/4 * 2,10, Color.BLACK,"Arial",16);
|
||||
guis.add(p1);
|
||||
guis.add(p2);
|
||||
guis.add(timer);
|
||||
|
||||
//Menu Help
|
||||
helpLabel = new GUILabel("HELP",Main.WIDTH/2,10,Color.WHITE,"Arial",32);
|
||||
helpLabel = new GUILabel("HELP",Main.WIDTH/2,10,Color.WHITE,"Arial",64);
|
||||
helpLabel.setX(Main.WIDTH/2 - helpLabel.getWitdh()/2);
|
||||
guisHelp.add(helpLabel);
|
||||
//Joueur 1
|
||||
joueur1Help = new GUILabel("JOUEUR 1",Main.WIDTH/4,100,Color.WHITE,"Arial",32);
|
||||
joueur1Help.setX(Main.WIDTH/4 - joueur1Help.getWitdh()/2);
|
||||
joueur1HelpRotationG = new GUILabel("A = rotation a gauche",Main.WIDTH/4,140,Color.WHITE,"Arial",16);
|
||||
joueur1HelpRotationG.setX(Main.WIDTH/4 - joueur1HelpRotationG.getWitdh()/2);
|
||||
joueur1HelpRotationD = new GUILabel("E = rotation a droite",Main.WIDTH/4,160,Color.WHITE,"Arial",16);
|
||||
joueur1HelpRotationD.setX(Main.WIDTH/4 - joueur1HelpRotationD.getWitdh()/2);
|
||||
joueur1HelpDeplacementVerticaleH = new GUILabel("Z = Haut",Main.WIDTH/4,180,Color.WHITE,"Arial",16);
|
||||
joueur1HelpDeplacementVerticaleH.setX(Main.WIDTH/4 - joueur1HelpDeplacementVerticaleH.getWitdh()/2);
|
||||
joueur1HelpDeplacementVerticaleB = new GUILabel("S = Bas",Main.WIDTH/4,200,Color.WHITE,"Arial",16);
|
||||
joueur1HelpDeplacementVerticaleB.setX(Main.WIDTH/4 - joueur1HelpDeplacementVerticaleB.getWitdh()/2);
|
||||
joueur1HelpDeplacementHorizontaleG = new GUILabel("A = Gauche",Main.WIDTH/4,220,Color.WHITE,"Arial",16);
|
||||
joueur1HelpDeplacementHorizontaleG.setX(Main.WIDTH/4 - joueur1HelpDeplacementHorizontaleG.getWitdh()/2);
|
||||
joueur1HelpDeplacementHorizontaleD = new GUILabel("D = Droite",Main.WIDTH/4,240,Color.WHITE,"Arial",16);
|
||||
joueur1HelpDeplacementHorizontaleD.setX(Main.WIDTH/4 - joueur1HelpDeplacementHorizontaleD.getWitdh()/2);
|
||||
guisHelp.add(joueur1Help);
|
||||
guisHelp.add(joueur1HelpRotationG);
|
||||
guisHelp.add(joueur1HelpRotationD);
|
||||
guisHelp.add(joueur1HelpDeplacementVerticaleH);
|
||||
guisHelp.add(joueur1HelpDeplacementVerticaleB);
|
||||
guisHelp.add(joueur1HelpDeplacementHorizontaleG);
|
||||
guisHelp.add(joueur1HelpDeplacementHorizontaleD);
|
||||
//Joueur 2
|
||||
joueur2Help = new GUILabel("JOUEUR 2",Main.WIDTH/4,100,Color.WHITE,"Arial",32);
|
||||
joueur2Help.setX(Main.WIDTH/4 * 3 - joueur2Help.getWitdh()/2);
|
||||
joueur2HelpRotationG = new GUILabel("U = rotation a gauche",Main.WIDTH/4,140,Color.WHITE,"Arial",16);
|
||||
joueur2HelpRotationG.setX(Main.WIDTH/4 * 3 - joueur1HelpRotationG.getWitdh()/2);
|
||||
joueur2HelpRotationD = new GUILabel("O = rotation a droite",Main.WIDTH/4,160,Color.WHITE,"Arial",16);
|
||||
joueur2HelpRotationD.setX(Main.WIDTH/4 * 3 - joueur1HelpRotationD.getWitdh()/2);
|
||||
joueur2HelpDeplacementVerticaleH = new GUILabel("I = Haut",Main.WIDTH/4,180,Color.WHITE,"Arial",16);
|
||||
joueur2HelpDeplacementVerticaleH.setX(Main.WIDTH/4 * 3 - joueur1HelpDeplacementVerticaleH.getWitdh()/2);
|
||||
joueur2HelpDeplacementVerticaleB = new GUILabel("K = Bas",Main.WIDTH/4,200,Color.WHITE,"Arial",16);
|
||||
joueur2HelpDeplacementVerticaleB.setX(Main.WIDTH/4 * 3 - joueur1HelpDeplacementVerticaleB.getWitdh()/2);
|
||||
joueur2HelpDeplacementHorizontaleG = new GUILabel("J = Gauche",Main.WIDTH/4,220,Color.WHITE,"Arial",16);
|
||||
joueur2HelpDeplacementHorizontaleG.setX(Main.WIDTH/4 * 3 - joueur1HelpDeplacementHorizontaleG.getWitdh()/2);
|
||||
joueur2HelpDeplacementHorizontaleD = new GUILabel("L = Droite",Main.WIDTH/4,240,Color.WHITE,"Arial",16);
|
||||
joueur2HelpDeplacementHorizontaleD.setX(Main.WIDTH/4 * 3 - joueur1HelpDeplacementHorizontaleD.getWitdh()/2);
|
||||
guisHelp.add(joueur2Help);
|
||||
guisHelp.add(joueur2HelpRotationG);
|
||||
guisHelp.add(joueur2HelpRotationD);
|
||||
guisHelp.add(joueur2HelpDeplacementVerticaleH);
|
||||
guisHelp.add(joueur2HelpDeplacementVerticaleB);
|
||||
guisHelp.add(joueur2HelpDeplacementHorizontaleG);
|
||||
guisHelp.add(joueur2HelpDeplacementHorizontaleD);
|
||||
//Manette
|
||||
manetteHelp = new GUILabel("Manettes",Main.WIDTH/2,270,Color.WHITE,"Arial",32);
|
||||
manetteHelp.setX(Main.WIDTH/2 - manetteHelp.getWitdh()/2);
|
||||
manetteHelpDirection = new GUILabel("Stick Gauche = Direction",Main.WIDTH/2,310,Color.WHITE,"Arial",16);
|
||||
manetteHelpDirection.setX(Main.WIDTH/2 - manetteHelpDirection.getWitdh()/2);
|
||||
manetteHelpRotation = new GUILabel("Stick Droit = Rotation",Main.WIDTH/2,330,Color.WHITE,"Arial",16);
|
||||
manetteHelpRotation.setX(Main.WIDTH/2 - manetteHelpRotation.getWitdh()/2);
|
||||
guisHelp.add(manetteHelp);
|
||||
guisHelp.add(manetteHelpDirection);
|
||||
guisHelp.add(manetteHelpRotation);
|
||||
|
||||
//Menu Partie Terminer
|
||||
labelPartieTerminer = new GUILabel("PARTIE TERMINER",Main.WIDTH/2,10,Color.WHITE,"Arial",32);
|
||||
|
@ -77,13 +148,19 @@ public class MainInterfaces {
|
|||
public void update(){
|
||||
if(Input.isKey(this.game.helpKey)){
|
||||
for(GUI g : guisHelp)g.update();
|
||||
}else if(this.game.scores[0] <= 0 || this.game.scores[1] <= 0){
|
||||
}else if(this.game.scores[0] <= 0 || this.game.scores[1] <= 0 || MainGame.time_in_sec <= 0){
|
||||
for(GUI g : guisPartieTerminer)g.update();
|
||||
}else{
|
||||
p1.setText("Player 1 : " + this.game.scores[0]);
|
||||
p1.setX((Main.WIDTH-SIZE_OF_DETAILS)/4 - p1.getWitdh()/2);
|
||||
p2.setText("Player 2 : " + this.game.scores[1]);
|
||||
p2.setX((Main.WIDTH-SIZE_OF_DETAILS)/4*3 - p2.getWitdh()/2);
|
||||
p1.setText("Player 1 : " + (int)this.game.scores[0]);
|
||||
p1.setX((Main.WIDTH)/4 - p1.getWitdh()/2);
|
||||
p2.setText("Player 2 : " + (int)this.game.scores[1]);
|
||||
p2.setX((Main.WIDTH)/4*3 - p2.getWitdh()/2);
|
||||
int sec = (int)MainGame.time_in_sec;
|
||||
int min = sec/60;
|
||||
sec -= min * 60;
|
||||
timer.setText(min + ":" + sec);
|
||||
timer.setX((Main.WIDTH)/4*2 - timer.getWitdh()/2);
|
||||
MainGame.time_in_sec -= Main.delta;
|
||||
for(GUI g : guis)g.update();
|
||||
}
|
||||
}
|
||||
|
@ -100,6 +177,15 @@ public class MainInterfaces {
|
|||
labelPartieTerminer.setX(Main.WIDTH/2 - labelPartieTerminer.getWitdh()/2);
|
||||
}
|
||||
for(GUI g : guisPartieTerminer)g.render();
|
||||
}else if(MainGame.time_in_sec <= 0){
|
||||
if(this.game.scores[0] < this.game.scores[1]){
|
||||
labelPartieTerminer.setText("PARTIE TERMINER (GAGNANT : JOUEUR 2)");
|
||||
labelPartieTerminer.setX(Main.WIDTH/2 - labelPartieTerminer.getWitdh()/2);
|
||||
}else{
|
||||
labelPartieTerminer.setText("PARTIE TERMINER (GAGNANT : JOUEUR 1)");
|
||||
labelPartieTerminer.setX(Main.WIDTH/2 - labelPartieTerminer.getWitdh()/2);
|
||||
}
|
||||
for(GUI g : guisPartieTerminer)g.render();
|
||||
}else{
|
||||
for(GUI g : guis)g.render();
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ import globalgamejam.game.Mur;
|
|||
*/
|
||||
public class PhysicalEntity {
|
||||
|
||||
private final static float MAX_SPEED = 15f;
|
||||
|
||||
protected float x;
|
||||
protected float y;
|
||||
|
||||
|
@ -83,22 +85,22 @@ public class PhysicalEntity {
|
|||
if(entity instanceof Mur){
|
||||
|
||||
// on a touché le bas du Mur
|
||||
if(this.y <= entity.y - entity.sizeY / 2){
|
||||
if(this.y <= entity.y - entity.sizeY / 2 && this.yVelocity > 0){
|
||||
this.yVelocity *= -1;
|
||||
}
|
||||
|
||||
// on a touché le haut du Mur
|
||||
if(this.y >= entity.y + entity.sizeY / 2){
|
||||
if(this.y >= entity.y + entity.sizeY / 2 && this.yVelocity < 0){
|
||||
this.yVelocity *= -1;
|
||||
}
|
||||
|
||||
// on a touché le coté gauche du Mur
|
||||
if(this.x <= entity.x - entity.sizeX / 2){
|
||||
if(this.x <= entity.x - entity.sizeX / 2 && this.xVelocity > 0){
|
||||
this.xVelocity *= -1;
|
||||
}
|
||||
|
||||
// on a touché le coté droit du Mur
|
||||
if(this.x >= entity.x + entity.sizeX / 2){
|
||||
if(this.x >= entity.x + entity.sizeX / 2 && this.xVelocity < 0){
|
||||
this.xVelocity *= -1;
|
||||
}
|
||||
|
||||
|
@ -121,16 +123,23 @@ public class PhysicalEntity {
|
|||
this.xVelocity *= 1 - this.frictionFactor;
|
||||
this.yVelocity *= 1 - this.frictionFactor;
|
||||
|
||||
if(this.xVelocity < 0.01 && this.xVelocity > 0.01){
|
||||
if(this.xVelocity < 0.01 && this.xVelocity > -0.01){
|
||||
this.xVelocity = 0;
|
||||
}
|
||||
|
||||
if(this.yVelocity < 0.01 && this.yVelocity > 0.01){
|
||||
if(this.yVelocity < 0.01 && this.yVelocity > -0.01){
|
||||
this.yVelocity = 0;
|
||||
}
|
||||
|
||||
this.speed = (float)Math.sqrt( this.xVelocity * this.xVelocity + this.yVelocity * this.yVelocity );
|
||||
|
||||
if(this.speed >= PhysicalEntity.MAX_SPEED){
|
||||
this.xVelocity = (this.xVelocity * PhysicalEntity.MAX_SPEED) / this.speed;
|
||||
this.yVelocity = (this.yVelocity * PhysicalEntity.MAX_SPEED) / this.speed;
|
||||
|
||||
this.speed = PhysicalEntity.MAX_SPEED;
|
||||
}
|
||||
|
||||
this.moveTile();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package globalgamejam.world;
|
||||
|
||||
import java.nio.FloatBuffer;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
@ -12,9 +13,8 @@ import globalgamejam.game.Objet;
|
|||
import globalgamejam.game.Player;
|
||||
import globalgamejam.input.Input;
|
||||
import globalgamejam.math.Mathf;
|
||||
import globalgamejam.math.Vector2f;
|
||||
import globalgamejam.tiles.Fond;
|
||||
import globalgamejam.tiles.MurTile;
|
||||
import globalgamejam.tiles.ObjetTile;
|
||||
import globalgamejam.tiles.Tile;
|
||||
import globalgamejam.tiles.VaguesTile;
|
||||
|
||||
|
@ -34,6 +34,14 @@ public class MainWorld {
|
|||
private ArrayList<Objet> listObjet;
|
||||
private ArrayList<Mur> listMur;
|
||||
private Mur mur1,mur2,mur3,murGauche,murDroit,murHaut,murBas;
|
||||
private long tempsEntreVague,TempsAncienneVague;
|
||||
private boolean etatVague;
|
||||
|
||||
private float maxVague = 0;
|
||||
private boolean maxVagueAtteint = false;
|
||||
private boolean despawnVagueACalculer = false;
|
||||
|
||||
private int nextVagueHeight;
|
||||
|
||||
public MainWorld(MainGame game){
|
||||
this.game = game;
|
||||
|
@ -44,8 +52,8 @@ public class MainWorld {
|
|||
}
|
||||
|
||||
public void init(){
|
||||
player1 = new Player(Main.WIDTH/4-20, 150);
|
||||
player2 = new Player(Main.WIDTH/4 * 3-20, 150);
|
||||
player1 = new Player("res/textures/perso.png", Main.WIDTH/4-20, 150);
|
||||
player2 = new Player("res/textures/perso2.png", Main.WIDTH/4 * 3-20, 150);
|
||||
|
||||
Fond fond = new Fond("res/textures/sand.jpg");
|
||||
fond.getTransform().translate(Main.WIDTH/2, Main.HEIGHT/2, 0);
|
||||
|
@ -59,11 +67,11 @@ public class MainWorld {
|
|||
this.murDroit = new Mur(Main.WIDTH,Main.HEIGHT/2+40,"res/textures/murcoté.png");
|
||||
this.murHaut = new Mur(Main.WIDTH/2,Main.HEIGHT+10,"res/textures/murhauteur.png");
|
||||
this.murBas = new Mur(Main.WIDTH/2,80,"res/textures/murbas.png");
|
||||
this.mur1 = new Mur(Main.WIDTH/2,Main.HEIGHT/2,"res/textures/mur.png");
|
||||
this.mur2 = new Mur(Main.WIDTH/2-10, Main.HEIGHT/2 - 250,"res/textures/mur.png");
|
||||
this.mur3 = new Mur(Main.WIDTH/2-10, Main.HEIGHT - 400, "res/textures/mur.png");
|
||||
this.mur1 = new Mur(Main.WIDTH/2,Main.HEIGHT-20,"res/textures/murmilieuhaut.png");
|
||||
this.mur2 = new Mur(Main.WIDTH/2, Main.HEIGHT/2+30 ,"res/textures/murmilieumilieu.png");
|
||||
this.mur3 = new Mur(Main.WIDTH/2, 100, "res/textures/murmilieubas.png");
|
||||
tiles.add(fond);
|
||||
tiles.add(vagues);
|
||||
|
||||
tiles.add(mur1.getTile());
|
||||
tiles.add(mur2.getTile());
|
||||
tiles.add(mur3.getTile());
|
||||
|
@ -72,9 +80,10 @@ public class MainWorld {
|
|||
tiles.add(murHaut.getTile());
|
||||
tiles.add(murBas.getTile());
|
||||
|
||||
tiles.add(player1.getTile());
|
||||
tiles.add(player2.getTile());
|
||||
|
||||
|
||||
|
||||
|
||||
listMur.add(mur1);
|
||||
listMur.add(mur2);
|
||||
listMur.add(mur3);
|
||||
|
@ -82,8 +91,22 @@ public class MainWorld {
|
|||
listMur.add(murDroit);
|
||||
listMur.add(murHaut);
|
||||
listMur.add(murBas);
|
||||
|
||||
|
||||
tiles.add(vagues);
|
||||
|
||||
tiles.add(player1.getTile());
|
||||
tiles.add(player2.getTile());
|
||||
|
||||
tempsEntreVague=0;
|
||||
TempsAncienneVague=System.currentTimeMillis();
|
||||
etatVague =false;
|
||||
|
||||
maxVague = 0;
|
||||
maxVagueAtteint = false;
|
||||
despawnVagueACalculer = false;
|
||||
|
||||
genererBonusMalus(3);
|
||||
|
||||
}
|
||||
|
||||
public void update(){
|
||||
|
@ -92,106 +115,203 @@ public class MainWorld {
|
|||
|
||||
if(!Input.isKey(this.game.helpKey)){
|
||||
//Player 1
|
||||
boolean keyBoard1Enable = false;
|
||||
float xDep = 0, yDep = 0;
|
||||
if(Input.isKey(GLFW.GLFW_KEY_W)){
|
||||
xDep = player1.getSpeed() * Mathf.cos(Mathf.toRadians(player1.getAngle() + 90));
|
||||
yDep = player1.getSpeed() * Mathf.sin(Mathf.toRadians(player1.getAngle() + 90));
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_S)){
|
||||
xDep = player1.getSpeed() * Mathf.cos(Mathf.toRadians(player1.getAngle() - 90));
|
||||
yDep = player1.getSpeed() * Mathf.sin(Mathf.toRadians(player1.getAngle() - 90));
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_A)){
|
||||
xDep = player1.getSpeed() * Mathf.cos(Mathf.toRadians(player1.getAngle() - 180));
|
||||
yDep = player1.getSpeed() * Mathf.sin(Mathf.toRadians(player1.getAngle() - 180));
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_D)){
|
||||
xDep = player1.getSpeed() * Mathf.cos(Mathf.toRadians(player1.getAngle()));
|
||||
yDep = player1.getSpeed() * Mathf.sin(Mathf.toRadians(player1.getAngle()));
|
||||
}
|
||||
|
||||
if(xDep != 0.0 && yDep != 0.0){
|
||||
xDep *= Math.cos(Math.PI / 4);
|
||||
yDep *= Math.cos(Math.PI / 4);
|
||||
}
|
||||
|
||||
player1.move(xDep, yDep);
|
||||
|
||||
if(Input.isKey(GLFW.GLFW_KEY_Q)){
|
||||
player1.rotate(player1.getSpeed());
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_E)){
|
||||
player1.rotate(-player1.getSpeed());
|
||||
}
|
||||
if(Input.getJoysticks().size() > 0){
|
||||
try{
|
||||
FloatBuffer bufferAxis = Input.getJoysticksAxis(0);
|
||||
xDep = bufferAxis.get(0) * player1.getSpeed();
|
||||
yDep = bufferAxis.get(1) * player1.getSpeed();
|
||||
|
||||
if(xDep != 0.0 && yDep != 0.0){
|
||||
xDep *= Math.cos(Math.PI / 4);
|
||||
yDep *= Math.cos(Math.PI / 4);
|
||||
}
|
||||
|
||||
player1.move(xDep, yDep);
|
||||
|
||||
player1.rotate(player1.getSpeed() * -bufferAxis.get(2) / 2.0f);
|
||||
}catch(Exception e){
|
||||
keyBoard1Enable = true;
|
||||
}
|
||||
}else{
|
||||
keyBoard1Enable = true;
|
||||
}
|
||||
|
||||
if(keyBoard1Enable){
|
||||
if(Input.isKey(GLFW.GLFW_KEY_W)){
|
||||
xDep = player1.getSpeed() * Mathf.cos(Mathf.toRadians(player1.getAngle() + 90));
|
||||
yDep = player1.getSpeed() * Mathf.sin(Mathf.toRadians(player1.getAngle() + 90));
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_S)){
|
||||
xDep = player1.getSpeed() * Mathf.cos(Mathf.toRadians(player1.getAngle() - 90));
|
||||
yDep = player1.getSpeed() * Mathf.sin(Mathf.toRadians(player1.getAngle() - 90));
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_A)){
|
||||
xDep = player1.getSpeed() * Mathf.cos(Mathf.toRadians(player1.getAngle() - 180));
|
||||
yDep = player1.getSpeed() * Mathf.sin(Mathf.toRadians(player1.getAngle() - 180));
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_D)){
|
||||
xDep = player1.getSpeed() * Mathf.cos(Mathf.toRadians(player1.getAngle()));
|
||||
yDep = player1.getSpeed() * Mathf.sin(Mathf.toRadians(player1.getAngle()));
|
||||
}
|
||||
|
||||
if(xDep != 0.0 && yDep != 0.0){
|
||||
xDep *= Math.cos(Math.PI / 4);
|
||||
yDep *= Math.cos(Math.PI / 4);
|
||||
}
|
||||
|
||||
player1.move(xDep, yDep);
|
||||
|
||||
if(Input.isKey(GLFW.GLFW_KEY_Q)){
|
||||
player1.rotate(player1.getSpeed());
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_E)){
|
||||
player1.rotate(-player1.getSpeed());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Player 2
|
||||
boolean keyBoard2Enable = false;
|
||||
xDep = 0;
|
||||
yDep = 0;
|
||||
if(Input.isKey(GLFW.GLFW_KEY_I)){
|
||||
xDep = player2.getSpeed() * Mathf.cos(Mathf.toRadians(player2.getAngle() + 90));
|
||||
yDep = player2.getSpeed() * Mathf.sin(Mathf.toRadians(player2.getAngle() + 90));
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_K)){
|
||||
xDep = player2.getSpeed() * Mathf.cos(Mathf.toRadians(player2.getAngle() - 90));
|
||||
yDep = player2.getSpeed() * Mathf.sin(Mathf.toRadians(player2.getAngle() - 90));
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_J)){
|
||||
xDep = player2.getSpeed() * Mathf.cos(Mathf.toRadians(player2.getAngle() - 180));
|
||||
yDep = player2.getSpeed() * Mathf.sin(Mathf.toRadians(player2.getAngle() - 180));
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_L)){
|
||||
xDep = player2.getSpeed() * Mathf.cos(Mathf.toRadians(player2.getAngle()));
|
||||
yDep = player2.getSpeed() * Mathf.sin(Mathf.toRadians(player2.getAngle()));
|
||||
}
|
||||
|
||||
if(xDep != 0.0 && yDep != 0.0){
|
||||
xDep *= Math.cos(Math.PI / 4);
|
||||
yDep *= Math.cos(Math.PI / 4);
|
||||
}
|
||||
|
||||
|
||||
player2.move(xDep, yDep);
|
||||
|
||||
if(Input.isKey(GLFW.GLFW_KEY_U)){
|
||||
player2.rotate(player2.getSpeed());
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_O)){
|
||||
player2.rotate(-player2.getSpeed());
|
||||
}
|
||||
if(Input.getJoysticks().size() > 1){
|
||||
try{
|
||||
FloatBuffer bufferAxis = Input.getJoysticksAxis(1);
|
||||
xDep = bufferAxis.get(0) * player2.getSpeed();
|
||||
yDep = bufferAxis.get(1) * player2.getSpeed();
|
||||
|
||||
if(xDep != 0.0 && yDep != 0.0){
|
||||
xDep *= Math.cos(Math.PI / 4);
|
||||
yDep *= Math.cos(Math.PI / 4);
|
||||
}
|
||||
|
||||
player2.move(xDep, yDep);
|
||||
|
||||
player2.rotate(player2.getSpeed() * -bufferAxis.get(2) / 2.0f);
|
||||
}catch(Exception e){
|
||||
keyBoard2Enable = true;
|
||||
}
|
||||
}else{
|
||||
keyBoard2Enable = true;
|
||||
}
|
||||
|
||||
for(Objet o : this.listObjet){
|
||||
if(player1.brosseCollideWith(o)){
|
||||
o.resolveCollideWith(player1.getBrosse());
|
||||
this.game.scores[0]-=10;
|
||||
}
|
||||
if(keyBoard2Enable){
|
||||
if(Input.isKey(GLFW.GLFW_KEY_I)){
|
||||
xDep = player2.getSpeed() * Mathf.cos(Mathf.toRadians(player2.getAngle() + 90));
|
||||
yDep = player2.getSpeed() * Mathf.sin(Mathf.toRadians(player2.getAngle() + 90));
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_K)){
|
||||
xDep = player2.getSpeed() * Mathf.cos(Mathf.toRadians(player2.getAngle() - 90));
|
||||
yDep = player2.getSpeed() * Mathf.sin(Mathf.toRadians(player2.getAngle() - 90));
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_J)){
|
||||
xDep = player2.getSpeed() * Mathf.cos(Mathf.toRadians(player2.getAngle() - 180));
|
||||
yDep = player2.getSpeed() * Mathf.sin(Mathf.toRadians(player2.getAngle() - 180));
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_L)){
|
||||
xDep = player2.getSpeed() * Mathf.cos(Mathf.toRadians(player2.getAngle()));
|
||||
yDep = player2.getSpeed() * Mathf.sin(Mathf.toRadians(player2.getAngle()));
|
||||
}
|
||||
|
||||
if(xDep != 0.0 && yDep != 0.0){
|
||||
xDep *= Math.cos(Math.PI / 4);
|
||||
yDep *= Math.cos(Math.PI / 4);
|
||||
}
|
||||
|
||||
|
||||
player2.move(xDep, yDep);
|
||||
|
||||
if(Input.isKey(GLFW.GLFW_KEY_U)){
|
||||
player2.rotate(player2.getSpeed());
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_O)){
|
||||
player2.rotate(-player2.getSpeed());
|
||||
}
|
||||
}
|
||||
|
||||
for(Objet o : this.listObjet){
|
||||
|
||||
if(o.getTile().getPosition().x < Main.WIDTH/2.0f){
|
||||
this.game.scores[0] += o.getType().getPoints() * Main.delta;
|
||||
}else{
|
||||
this.game.scores[1] += o.getType().getPoints() * Main.delta;
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<Objet> listObjetADespawn = new ArrayList<>();
|
||||
|
||||
if(despawnVagueACalculer){
|
||||
despawnVagueACalculer = false;
|
||||
|
||||
for(Objet o : this.listObjet){
|
||||
if(o.underWave(this.vagues.getPosition().y + this.vagues.getTexture().height / 2)){
|
||||
if(o.shouldDespawn()){
|
||||
listObjetADespawn.add(o);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(Objet o : listObjetADespawn){
|
||||
this.tiles.remove(o.getTile());
|
||||
this.listObjet.remove(o);
|
||||
}
|
||||
|
||||
genererBonusMalus((int)(Math.random() * 4) + 2);
|
||||
}
|
||||
|
||||
for(Objet o : this.listObjet){
|
||||
|
||||
if(player2.brosseCollideWith(o)){
|
||||
o.resolveCollideWith(player2.getBrosse());
|
||||
this.game.scores[1]-=10;
|
||||
}
|
||||
|
||||
for(Objet o2 : this.listObjet){
|
||||
if(!o.equals(o2) && o.collideWith(o2)){
|
||||
o.resolveCollideWith(o2);
|
||||
if(o.underWave(this.vagues.getPosition().y + this.vagues.getTexture().height / 2)){
|
||||
if(o.shouldDespawn()){
|
||||
listObjetADespawn.add(o);
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
for(Mur m : this.listMur){
|
||||
if(o.collideWith(m)){
|
||||
o.resolveCollideWith(m);
|
||||
}
|
||||
if(player1.brosseCollideWith(o)){
|
||||
o.resolveCollideWith(player1.getBrosse());
|
||||
}
|
||||
|
||||
if(player2.brosseCollideWith(o)){
|
||||
o.resolveCollideWith(player2.getBrosse());
|
||||
}
|
||||
|
||||
for(Objet o2 : this.listObjet){
|
||||
if(!o.equals(o2) && o.collideWith(o2)){
|
||||
o.resolveCollideWith(o2);
|
||||
}
|
||||
}
|
||||
|
||||
for(Mur m : this.listMur){
|
||||
if(o.collideWith(m)){
|
||||
o.resolveCollideWith(m);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vaguesValue += Main.delta * 2;
|
||||
applyVaguesCoeff((Math.cos(vaguesValue)>0.5)?
|
||||
((float)Math.cos(vaguesValue)-0.5f)*2:0,(int)Main.HEIGHT/8,Main.HEIGHT/4*3);
|
||||
if(System.currentTimeMillis()-TempsAncienneVague>=tempsEntreVague){
|
||||
etatVague = vagues.getPosition().y>-224.0f;
|
||||
vaguesValue += Main.delta * 2;
|
||||
applyVaguesCoeff((Math.cos(vaguesValue)>0.5)?
|
||||
((float)Math.cos(vaguesValue)-0.5f)*2:0,(int)Main.HEIGHT/8,nextVagueHeight);
|
||||
if(vagues.getPosition().y==-225.0f && etatVague){
|
||||
System.out.println("aaaaaaa");
|
||||
tempsEntreVague = (long) (Math.random() * 5000 + 5000);
|
||||
TempsAncienneVague=System.currentTimeMillis();
|
||||
etatVague =false;
|
||||
nextVagueHeight = (int)(Math.random() * (Main.HEIGHT/4f*3f - 160f) + 160f);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void render(){
|
||||
if(!Input.isKey(this.game.helpKey) && this.game.scores[0] > 0 && this.game.scores[1] > 0){
|
||||
if(!Input.isKey(this.game.helpKey) && this.game.scores[0] > 0 && this.game.scores[1] > 0 && MainGame.time_in_sec > 0){
|
||||
for(Tile t : tiles)t.render();
|
||||
}
|
||||
}
|
||||
|
@ -216,8 +336,23 @@ public class MainWorld {
|
|||
|
||||
private void applyVaguesCoeff(float coeff,int offset,int height){
|
||||
vagues.getTransform().loadIdentity();
|
||||
vagues.getTransform().translate(Main.WIDTH/2, -Main.HEIGHT/2 + height*coeff + offset,0);
|
||||
vagues.getTransform().scale(Main.WIDTH,Main.HEIGHT, 0);
|
||||
vagues.setPosition(new Vector2f(Main.WIDTH/2, -Main.HEIGHT/2 + height*coeff + offset));
|
||||
vagues.setScale(new Vector2f(Main.WIDTH,Main.HEIGHT));
|
||||
vagues.applyTransform();
|
||||
|
||||
if(vagues.getPosition().y >= this.maxVague){
|
||||
this.maxVague = vagues.getPosition().y;
|
||||
}
|
||||
else if(!this.maxVagueAtteint){
|
||||
this.maxVagueAtteint = true;
|
||||
|
||||
this.despawnVagueACalculer = true;
|
||||
}
|
||||
else if(vagues.getPosition().y == -225.0){
|
||||
this.maxVague = -225.0f;
|
||||
this.maxVagueAtteint = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void moveObjets(){
|
||||
|
@ -226,7 +361,5 @@ public class MainWorld {
|
|||
}
|
||||
}
|
||||
|
||||
public void degenererObjet(int hauteur){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|