1
0
Fork 0

Version jouable

This commit is contained in:
MrDev023 2017-01-21 15:45:43 +01:00
parent 6b55748eef
commit ec64df0eec
23 changed files with 332 additions and 138 deletions

BIN
res/textures/banane.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
res/textures/bonus1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
res/textures/bonus2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

BIN
res/textures/bonus3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
res/textures/dechets.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

BIN
res/textures/dechets1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 176 B

BIN
res/textures/murbas.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 224 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 703 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 129 B

After

Width:  |  Height:  |  Size: 562 B

BIN
res/textures/perso2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

BIN
res/textures/sand.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 718 KiB

View file

@ -80,7 +80,7 @@ public class Main {
while(!glfwWindowShouldClose(windowID)){ while(!glfwWindowShouldClose(windowID)){
if(System.currentTimeMillis() - previousTicks >= 1000/60){//Update TICKS if(System.currentTimeMillis() - previousTicks >= 1000/120){//Update TICKS
glfwPollEvents(); glfwPollEvents();
Input.update(); Input.update();
game.update(); game.update();

View file

@ -0,0 +1,25 @@
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);
private int points;
private String filename;
EObjetType(String filename,int points){
this.points = points;
this.filename = filename;
}
public int getPoints() {
return points;
}
public String getFilename() {
return filename;
}
}

View file

@ -12,6 +12,7 @@ import globalgamejam.world.MainWorld;
*/ */
public class MainGame extends Game{ public class MainGame extends Game{
public static final int MAX_SCORE = 1000;
private MainWorld world; private MainWorld world;
private MainInterfaces interfaces; private MainInterfaces interfaces;
public int[] scores; public int[] scores;
@ -20,9 +21,19 @@ public class MainGame extends Game{
@Override @Override
public void init() { public void init() {
this.scores = new int[2]; this.scores = new int[2];
this.scores[0] = MAX_SCORE;
this.scores[1] = MAX_SCORE;
world = new MainWorld(this); world = new MainWorld(this);
interfaces = new MainInterfaces(this); interfaces = new MainInterfaces(this);
} }
public void reset(){
this.scores[0] = MAX_SCORE;
this.scores[1] = MAX_SCORE;
world.destroy();
world = new MainWorld(this);
world.init();
}
@Override @Override
public void update() { public void update() {

View file

@ -0,0 +1,27 @@
package globalgamejam.game;
import globalgamejam.physics.PhysicalEntity;
import globalgamejam.tiles.MurTile;
import globalgamejam.tiles.Tile;
public class Mur extends PhysicalEntity {
private final Tile tile;
public Mur(float x, float y, String texturePath){
super(x, y, 0, 0, 5, 0, 0, 0);
this.tile = new MurTile(x, y, texturePath);
this.setSizeXY(this.tile.getTexture().width, this.tile.getTexture().height);
}
public Tile getTile(){
return this.tile;
}
@Override
public float getSpeed(){
return this.getSpeedFactor();
}
}

View file

@ -6,13 +6,16 @@ import globalgamejam.tiles.ObjetTile;
import globalgamejam.tiles.Tile; import globalgamejam.tiles.Tile;
public class Objet extends PhysicalEntity { public class Objet extends PhysicalEntity {
private EObjetType type;
private final Tile tile; private final Tile tile;
public Objet(String texturePath, float x, float y, float sizeRadius, float speed, float xVelocity, float yVelocity, float frictionFactor){ public Objet(String texturePath, float x, float y, float speed, float xVelocity, float yVelocity, float frictionFactor){
super(x, y, sizeRadius, speed, xVelocity, yVelocity, frictionFactor); super(x, y, 0, 0, speed, xVelocity, yVelocity, frictionFactor);
this.tile = new ObjetTile(texturePath, x, y); this.tile = new ObjetTile(texturePath, x, y);
this.setSizeXY(this.tile.getTexture().width, this.tile.getTexture().height);
} }
public Tile getTile(){ public Tile getTile(){
@ -29,4 +32,14 @@ public class Objet extends PhysicalEntity {
public String toString(){ public String toString(){
return "x : " + this.x + ", y : " + this.y; return "x : " + this.x + ", y : " + this.y;
} }
public EObjetType getType() {
return type;
}
public void setType(EObjetType type) {
this.type = type;
}
} }

View file

@ -16,18 +16,20 @@ public class Player extends PhysicalEntity {
private final Tile tile; private final Tile tile;
private float angle; private float angle;
private float speed = 3; private float speed = 15;
private final PhysicalEntity brosse; private final PhysicalEntity brosse;
private final float longueurBalai; private final float longueurBalai;
public Player(float x, float y){ public Player(float x, float y){
super(x, y, 100, 3, 0, 0, 10); super(x, y, 0, 0, 3, 0, 0, 10);
this.tile = new PlayerTile("res/textures/perso.png", x, y); this.tile = new PlayerTile("res/textures/perso.png", x, y);
this.longueurBalai = 80; this.setSizeXY(this.tile.getTexture().width, this.tile.getTexture().height);
this.brosse = new PhysicalEntity(x, y + this.longueurBalai, 2f, 3, 0, 0, 0){ this.longueurBalai = 82;
this.brosse = new PhysicalEntity(x, y + this.longueurBalai, 18f, 12f, 15, 0, 0, 0){
@Override @Override
public float getSpeed(){ public float getSpeed(){
return getSpeedFactor(); return getSpeedFactor();
@ -41,6 +43,7 @@ public class Player extends PhysicalEntity {
public void move(float x, float y){ public void move(float x, float y){
this.addPosition(x, y); this.addPosition(x, y);
this.tile.setPosition(new Vector2f(this.x, this.y)); this.tile.setPosition(new Vector2f(this.x, this.y));
this.tile.applyTransform(); this.tile.applyTransform();
@ -84,4 +87,10 @@ public class Player extends PhysicalEntity {
public String toString(){ public String toString(){
return this.brosse.toString(); return this.brosse.toString();
} }
public float getAngle() {
return angle;
}
} }

View file

@ -2,6 +2,7 @@ package globalgamejam.interfaces;
import globalgamejam.Main; import globalgamejam.Main;
import globalgamejam.game.MainGame; import globalgamejam.game.MainGame;
import globalgamejam.gui.ActionGUI;
import globalgamejam.gui.GUI; import globalgamejam.gui.GUI;
import globalgamejam.gui.GUILabel; import globalgamejam.gui.GUILabel;
import globalgamejam.input.Input; import globalgamejam.input.Input;
@ -25,12 +26,17 @@ public class MainInterfaces {
private ArrayList<GUI> guisHelp; private ArrayList<GUI> guisHelp;
private GUILabel helpLabel; private GUILabel helpLabel;
private ArrayList<GUI> guisPartieTerminer;
private GUILabel labelPartieTerminer;
private GUILabel recommencerPartie;
public MainInterfaces(MainGame game){ public MainInterfaces(MainGame game){
this.game = game; this.game = game;
guis = new ArrayList<GUI>(); guis = new ArrayList<GUI>();
guisHelp = new ArrayList<GUI>(); guisHelp = new ArrayList<GUI>();
guisPartieTerminer = new ArrayList<GUI>();
init(); init();
} }
@ -44,11 +50,35 @@ public class MainInterfaces {
helpLabel = new GUILabel("HELP",Main.WIDTH/2,10,Color.WHITE,"Arial",32); helpLabel = new GUILabel("HELP",Main.WIDTH/2,10,Color.WHITE,"Arial",32);
helpLabel.setX(Main.WIDTH/2 - helpLabel.getWitdh()/2); helpLabel.setX(Main.WIDTH/2 - helpLabel.getWitdh()/2);
guisHelp.add(helpLabel); guisHelp.add(helpLabel);
//Menu Partie Terminer
labelPartieTerminer = new GUILabel("PARTIE TERMINER",Main.WIDTH/2,10,Color.WHITE,"Arial",32);
labelPartieTerminer.setX(Main.WIDTH/2 - labelPartieTerminer.getWitdh()/2);
recommencerPartie = new GUILabel("RECOMMENCER",Main.WIDTH/2,100,Color.WHITE,"Arial",16);
recommencerPartie.setX(Main.WIDTH/2 - recommencerPartie.getWitdh()/2);
recommencerPartie.setAction(new ActionGUI(){
@Override
public void enter(float mouseX,float mouseY){
recommencerPartie.setColor(new Color(1, 1, 1, 0.5f));
}
@Override
public void leave(float mouseX,float mouseY){
recommencerPartie.setColor(Color.WHITE);
}
@Override
public void clicked(float mouseX,float mouseY,int buttonKey,int buttonState){
game.reset();
}
});
guisPartieTerminer.add(labelPartieTerminer);
guisPartieTerminer.add(recommencerPartie);
} }
public void update(){ public void update(){
if(Input.isKey(this.game.helpKey)){ if(Input.isKey(this.game.helpKey)){
for(GUI g : guisHelp)g.update(); for(GUI g : guisHelp)g.update();
}else if(this.game.scores[0] <= 0 || this.game.scores[1] <= 0){
for(GUI g : guisPartieTerminer)g.update();
}else{ }else{
p1.setText("Player 1 : " + this.game.scores[0]); p1.setText("Player 1 : " + this.game.scores[0]);
p1.setX((Main.WIDTH-SIZE_OF_DETAILS)/4 - p1.getWitdh()/2); p1.setX((Main.WIDTH-SIZE_OF_DETAILS)/4 - p1.getWitdh()/2);
@ -61,6 +91,15 @@ public class MainInterfaces {
public void render(){ public void render(){
if(Input.isKey(this.game.helpKey)){ if(Input.isKey(this.game.helpKey)){
for(GUI g : guisHelp)g.render(); for(GUI g : guisHelp)g.render();
}else if(this.game.scores[0] <= 0 || this.game.scores[1] <= 0){
if(this.game.scores[0] <= 0){
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{ }else{
for(GUI g : guis)g.render(); for(GUI g : guis)g.render();
} }
@ -71,6 +110,8 @@ public class MainInterfaces {
guis.clear(); guis.clear();
for(GUI g : guisHelp)g.destroy(); for(GUI g : guisHelp)g.destroy();
guisHelp.clear(); guisHelp.clear();
for(GUI g : guisPartieTerminer)g.destroy();
guisPartieTerminer.clear();
} }
} }

View file

@ -1,5 +1,7 @@
package globalgamejam.physics; package globalgamejam.physics;
import globalgamejam.game.Mur;
/** /**
* *
* @author Jean-Baptiste * @author Jean-Baptiste
@ -9,8 +11,10 @@ public class PhysicalEntity {
protected float x; protected float x;
protected float y; protected float y;
private float sizeRadius; // private float sizeRadius;
private float sizeX;
private float sizeY;
private float xVelocity; private float xVelocity;
private float yVelocity; private float yVelocity;
@ -20,41 +24,91 @@ public class PhysicalEntity {
private float frictionFactor; private float frictionFactor;
public PhysicalEntity(float x, float y, float sizeRadius, float speedFactor, float xVelocity, float yVelocity, float frictionFactor) { /* public PhysicalEntity(float x, float y, float sizeRadius, float speedFactor, float xVelocity, float yVelocity, float frictionFactor) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.sizeX = sizeRadius * 2;
this.sizeY = sizeRadius * 2;
this.sizeRadius = sizeRadius; this.sizeRadius = sizeRadius;
this.xVelocity = xVelocity; this.xVelocity = xVelocity;
this.yVelocity = yVelocity; this.yVelocity = yVelocity;
this.frictionFactor = frictionFactor; this.frictionFactor = frictionFactor;
this.speedFactor = speedFactor; this.speedFactor = speedFactor;
this.speed = 0; this.speed = 0;
}*/
public PhysicalEntity(float x, float y, float sizeX, float sizeY, float speedFactor, float xVelocity, float yVelocity, float frictionFactor) {
this.x = x;
this.y = y;
this.sizeX = sizeX;
this.sizeY = sizeY;
// this.sizeRadius = -1;
this.xVelocity = xVelocity;
this.yVelocity = yVelocity;
this.frictionFactor = frictionFactor;
this.speedFactor = speedFactor;
this.speed = 0;
} }
public boolean collideWith(PhysicalEntity entity){
// if(this.sizeRadius == -1 || entity.sizeRadius == -1){
return this.collideWithSquareHitBox(entity);
/* }
else{
return this.collideWithRoundHitBox(entity);
}*/
}
public boolean collideWithSquareHitBox(PhysicalEntity entity){ public boolean collideWithSquareHitBox(PhysicalEntity entity){
// on teste une collision avec une hitbox carré // on teste une collision avec une hitbox carré
return (this.x + this.sizeRadius >= entity.x - entity.sizeRadius return (this.x + this.sizeX / 2 >= entity.x - entity.sizeX / 2
&& this.x - this.sizeRadius <= entity.x + entity.sizeRadius && this.x - this.sizeX / 2 <= entity.x + entity.sizeX / 2
&& this.y + this.sizeRadius >= entity.y - entity.sizeRadius && this.y + this.sizeY / 2 >= entity.y - entity.sizeY / 2
&& this.y - this.sizeRadius <= entity.y + entity.sizeRadius); && this.y - this.sizeY / 2 <= entity.y + entity.sizeY / 2);
} }
/* /*
public boolean collideWithRoundHitBox(PhysicalEntity entity){ public boolean collideWithRoundHitBox(PhysicalEntity entity){
if(this.collideWithSquareHitBox(entity)){
float distX = this.x - entity.x;
// teste avec une hitbox ronde à venir ... float distY = this.y - entity.y;
return true;
} float dist = (float)Math.sqrt( distX * distX + distY * distY );
return false;
return dist <= this.sizeRadius + entity.sizeRadius;
} }
*/ */
public void resolveCollideWith(PhysicalEntity entity){ public void resolveCollideWith(PhysicalEntity entity){
float xVel = entity.getSpeed() * (this.getX() - entity.getX()) / this.getSizeRadius();
float yVel = entity.getSpeed() * (this.getY() - entity.getY()) / this.getSizeRadius();
this.addVelocity(xVel, yVel); if(entity instanceof Mur){
// on a touché le bas du Mur
if(this.y <= entity.y - entity.sizeY / 2){
this.yVelocity *= -1;
}
// on a touché le haut du Mur
if(this.y >= entity.y + entity.sizeY / 2){
this.yVelocity *= -1;
}
// on a touché le coté gauche du Mur
if(this.x <= entity.x - entity.sizeX / 2){
this.xVelocity *= -1;
}
// on a touché le coté droit du Mur
if(this.x >= entity.x + entity.sizeX / 2){
this.xVelocity *= -1;
}
}
else{
float xVel = entity.getSpeed() * (this.getX() - entity.getX()) / this.getSizeRadius();
float yVel = entity.getSpeed() * (this.getY() - entity.getY()) / this.getSizeRadius();
this.addVelocity(xVel, yVel);
}
} }
/** /**
@ -67,11 +121,11 @@ public class PhysicalEntity {
this.xVelocity *= 1 - this.frictionFactor; this.xVelocity *= 1 - this.frictionFactor;
this.yVelocity *= 1 - this.frictionFactor; this.yVelocity *= 1 - this.frictionFactor;
if(this.xVelocity < 0.001 && this.xVelocity > 0.001){ if(this.xVelocity < 0.01 && this.xVelocity > 0.01){
this.xVelocity = 0; this.xVelocity = 0;
} }
if(this.yVelocity < 0.001 && this.yVelocity > 0.001){ if(this.yVelocity < 0.01 && this.yVelocity > 0.01){
this.yVelocity = 0; this.yVelocity = 0;
} }
@ -136,7 +190,18 @@ public class PhysicalEntity {
* @return the sizeRadius * @return the sizeRadius
*/ */
public float getSizeRadius() { public float getSizeRadius() {
return sizeRadius; return (this.sizeX + this.sizeY) / 2;
}
/*
public void setSizeRadius(float size){
this.sizeRadius = size;
this.sizeX = size;
this.sizeY = size;
}*/
public void setSizeXY(float sizeX, float sizeY){
this.sizeX = sizeX;
this.sizeY = sizeY;
} }
@Override @Override

View file

@ -1,17 +1,15 @@
package globalgamejam.tiles; package globalgamejam.tiles;
import globalgamejam.math.Color4f;
import globalgamejam.math.Vector2f; import globalgamejam.math.Vector2f;
import globalgamejam.render.Texture; import globalgamejam.render.Texture;
public class Mur extends Tile{ public class MurTile extends Tile{
public Mur(int x,int y,int scaleX,int scaleY,String path){ public MurTile(float x, float y, String path){
super(); super();
//super.setColor(Color4f.BLACK);
super.setPosition(new Vector2f(x, y)); super.setPosition(new Vector2f(x, y));
super.setScale(new Vector2f(scaleX, scaleY));
super.setTexture(Texture.loadTexture(path)); super.setTexture(Texture.loadTexture(path));
super.setScale(new Vector2f(this.getTexture().width, this.getTexture().height));
super.applyTransform(); super.applyTransform();
} }

View file

@ -8,8 +8,7 @@ public class ObjetTile extends Tile {
public ObjetTile(String texturePath, float x, float y){ public ObjetTile(String texturePath, float x, float y){
super(); super();
super.setColor(Color4f.RED); this.setTexture(Texture.loadTexture(texturePath));
// this.setTexture(Texture.loadTexture(texturePath));
this.setPosition(new Vector2f(x, y)); this.setPosition(new Vector2f(x, y));

View file

@ -5,12 +5,15 @@ import java.util.ArrayList;
import org.lwjgl.glfw.GLFW; import org.lwjgl.glfw.GLFW;
import globalgamejam.Main; import globalgamejam.Main;
import globalgamejam.game.EObjetType;
import globalgamejam.game.MainGame; import globalgamejam.game.MainGame;
import globalgamejam.game.Mur;
import globalgamejam.game.Objet; import globalgamejam.game.Objet;
import globalgamejam.game.Player; import globalgamejam.game.Player;
import globalgamejam.input.Input; import globalgamejam.input.Input;
import globalgamejam.math.Mathf;
import globalgamejam.tiles.Fond; import globalgamejam.tiles.Fond;
import globalgamejam.tiles.Mur; import globalgamejam.tiles.MurTile;
import globalgamejam.tiles.ObjetTile; import globalgamejam.tiles.ObjetTile;
import globalgamejam.tiles.Tile; import globalgamejam.tiles.Tile;
import globalgamejam.tiles.VaguesTile; import globalgamejam.tiles.VaguesTile;
@ -25,54 +28,62 @@ public class MainWorld {
private MainGame game; private MainGame game;
private Player player1,player2; private Player player1,player2;
private Mur mur1,mur2,mur3,murGauche,murDroit,murHaut,murBas;
private VaguesTile vagues; private VaguesTile vagues;
private float vaguesValue; private float vaguesValue;
private ArrayList<Objet> listObjet; private ArrayList<Objet> listObjet;
private ArrayList<Mur> listMur;
private Mur mur1,mur2,mur3,murGauche,murDroit,murHaut,murBas;
public MainWorld(MainGame game){ public MainWorld(MainGame game){
this.game = game; this.game = game;
tiles = new ArrayList<>(); tiles = new ArrayList<>();
listObjet = new ArrayList<>(); listObjet = new ArrayList<>();
listMur = new ArrayList<>();
init(); init();
} }
public void init(){ public void init(){
player1 = new Player(200, 150); player1 = new Player(Main.WIDTH/4-20, 150);
player2 = new Player(400, 150); player2 = new Player(Main.WIDTH/4 * 3-20, 150);
Fond fond = new Fond("res/textures/sand.jpg");
Fond fond = new Fond("res/textures/fond.png");
fond.getTransform().translate(Main.WIDTH/2, Main.HEIGHT/2, 0); fond.getTransform().translate(Main.WIDTH/2, Main.HEIGHT/2, 0);
fond.getTransform().scale(Main.WIDTH,Main.HEIGHT, 0); fond.getTransform().scale(Main.WIDTH,Main.HEIGHT, 0);
vagues = new VaguesTile("res/textures/vagues.png"); vagues = new VaguesTile("res/textures/vagues.png");
vagues.getTransform().translate(Main.WIDTH/2, -Main.HEIGHT/2, 0); vagues.getTransform().translate(Main.WIDTH/2, -Main.HEIGHT/2, 0);
vagues.getTransform().scale(Main.WIDTH,Main.HEIGHT, 0); vagues.getTransform().scale(Main.WIDTH,Main.HEIGHT, 0);
this.mur1 = new Mur(Main.WIDTH/2-10, Main.HEIGHT - 50, 20, 150,"res/textures/mur.png"); this.murGauche = new Mur(0,Main.HEIGHT/2+40,"res/textures/murcoté.png");
this.mur2 = new Mur(Main.WIDTH/2-10, Main.HEIGHT - 250, 20, 50,"res/textures/mur.png"); this.murDroit = new Mur(Main.WIDTH,Main.HEIGHT/2+40,"res/textures/murcoté.png");
this.mur3 = new Mur(Main.WIDTH/2-10, Main.HEIGHT - 400, 20, 150,"res/textures/mur.png"); this.murHaut = new Mur(Main.WIDTH/2,Main.HEIGHT+10,"res/textures/murhauteur.png");
this.murGauche=new Mur(0,Main.HEIGHT/2+40,30,Main.HEIGHT-80,"res/textures/murcoté.png"); this.murBas = new Mur(Main.WIDTH/2,80,"res/textures/murbas.png");
this.murDroit=new Mur(Main.WIDTH,Main.HEIGHT/2+40,30,Main.HEIGHT-80,"res/textures/murcoté.png"); this.mur1 = new Mur(Main.WIDTH/2,Main.HEIGHT/2,"res/textures/mur.png");
this.murHaut=new Mur(Main.WIDTH/2,Main.HEIGHT,Main.WIDTH,70,"res/textures/murhauteur.png"); this.mur2 = new Mur(Main.WIDTH/2-10, Main.HEIGHT/2 - 250,"res/textures/mur.png");
this.murBas=new Mur(Main.WIDTH/2,80,Main.WIDTH,20,"res/textures/murhauteur.png"); this.mur3 = new Mur(Main.WIDTH/2-10, Main.HEIGHT - 400, "res/textures/mur.png");
tiles.add(fond); tiles.add(fond);
tiles.add(vagues); tiles.add(vagues);
tiles.add(murGauche); tiles.add(mur1.getTile());
tiles.add(murDroit); tiles.add(mur2.getTile());
tiles.add(murHaut); tiles.add(mur3.getTile());
tiles.add(murBas); tiles.add(murGauche.getTile());
tiles.add(this.mur1); tiles.add(murDroit.getTile());
tiles.add(this.mur2); tiles.add(murHaut.getTile());
tiles.add(this.mur3); tiles.add(murBas.getTile());
tiles.add(player1.getTile()); tiles.add(player1.getTile());
tiles.add(player2.getTile()); tiles.add(player2.getTile());
listMur.add(mur1);
listMur.add(mur2);
listMur.add(mur3);
listMur.add(murGauche);
listMur.add(murDroit);
listMur.add(murHaut);
listMur.add(murBas);
generateEntity(3); genererBonusMalus(3);
} }
public void update(){ public void update(){
@ -82,17 +93,21 @@ public class MainWorld {
if(!Input.isKey(this.game.helpKey)){ if(!Input.isKey(this.game.helpKey)){
//Player 1 //Player 1
float xDep = 0, yDep = 0; float xDep = 0, yDep = 0;
if(Input.isKey(GLFW.GLFW_KEY_W) && player1.getTile().getPosition().y + player1.getTile().getScale().y/2.0f <= Main.HEIGHT - murHaut.getScale().y/2.0f){ if(Input.isKey(GLFW.GLFW_KEY_W)){
yDep = player1.getSpeed(); 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) && player1.getTile().getPosition().y - player1.getTile().getScale().y/2.0f >= murBas.getScale().y/2.0f + murBas.getPosition().y){ if(Input.isKey(GLFW.GLFW_KEY_S)){
yDep = -player1.getSpeed(); 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) && player1.getTile().getPosition().x - player1.getTile().getScale().x/2.0f >= 0.0f + murGauche.getScale().getX()/2.0f){ if(Input.isKey(GLFW.GLFW_KEY_A)){
xDep = -player1.getSpeed(); 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) && player1.getTile().getPosition().x + player1.getTile().getScale().x/2.0f <= Main.WIDTH/2.0f){ if(Input.isKey(GLFW.GLFW_KEY_D)){
xDep = player1.getSpeed(); 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){ if(xDep != 0.0 && yDep != 0.0){
@ -103,54 +118,72 @@ public class MainWorld {
player1.move(xDep, yDep); player1.move(xDep, yDep);
if(Input.isKey(GLFW.GLFW_KEY_Q)){ if(Input.isKey(GLFW.GLFW_KEY_Q)){
player1.rotate(5); player1.rotate(player1.getSpeed());
} }
if(Input.isKey(GLFW.GLFW_KEY_E)){ if(Input.isKey(GLFW.GLFW_KEY_E)){
player1.rotate(-5); player1.rotate(-player1.getSpeed());
}
for(Objet o : this.listObjet){
if(player1.brosseCollideWith(o)){
o.resolveCollideWith(player1.getBrosse());
}
for(Objet o2 : this.listObjet){
if(!o.equals(o2) && o.collideWithSquareHitBox(o2)){
o.resolveCollideWith(o2);
}
}
} }
//Player 2 //Player 2
xDep = 0; xDep = 0;
yDep = 0; yDep = 0;
if(Input.isKey(GLFW.GLFW_KEY_I) && player2.getTile().getPosition().y + player2.getTile().getScale().y/2.0f <= Main.HEIGHT - murHaut.getScale().y/2.0f){ if(Input.isKey(GLFW.GLFW_KEY_I)){
yDep = player2.getSpeed(); 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) && player2.getTile().getPosition().y - player2.getTile().getScale().y/2.0f >= murBas.getScale().y/2.0f + murBas.getPosition().y){ }
yDep = -player2.getSpeed(); if(Input.isKey(GLFW.GLFW_KEY_K)){
} xDep = player2.getSpeed() * Mathf.cos(Mathf.toRadians(player2.getAngle() - 90));
if(Input.isKey(GLFW.GLFW_KEY_J ) && player2.getTile().getPosition().x - player2.getTile().getScale().x/2.0f >= Main.WIDTH/2.0f){ yDep = player2.getSpeed() * Mathf.sin(Mathf.toRadians(player2.getAngle() - 90));
xDep = -player2.getSpeed(); }
} if(Input.isKey(GLFW.GLFW_KEY_J)){
if(Input.isKey(GLFW.GLFW_KEY_L) && player2.getTile().getPosition().x + player2.getTile().getScale().x/2.0f <= Main.WIDTH - murDroit.getScale().getX()/2.0f){ xDep = player2.getSpeed() * Mathf.cos(Mathf.toRadians(player2.getAngle() - 180));
xDep = player2.getSpeed(); 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){ if(xDep != 0.0 && yDep != 0.0){
xDep *= Math.cos(Math.PI / 4); xDep *= Math.cos(Math.PI / 4);
yDep *= Math.cos(Math.PI / 4); yDep *= Math.cos(Math.PI / 4);
} }
player2.move(xDep, yDep); player2.move(xDep, yDep);
if(Input.isKey(GLFW.GLFW_KEY_U)){ if(Input.isKey(GLFW.GLFW_KEY_U)){
player2.rotate(5); player2.rotate(player2.getSpeed());
} }
if(Input.isKey(GLFW.GLFW_KEY_O)){ if(Input.isKey(GLFW.GLFW_KEY_O)){
player2.rotate(-5); player2.rotate(-player2.getSpeed());
} }
for(Objet o : this.listObjet){
if(player1.brosseCollideWith(o)){
o.resolveCollideWith(player1.getBrosse());
this.game.scores[0]-=10;
}
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);
}
}
for(Mur m : this.listMur){
if(o.collideWith(m)){
o.resolveCollideWith(m);
}
}
}
} }
vaguesValue += Main.delta * 2; vaguesValue += Main.delta * 2;
applyVaguesCoeff((Math.cos(vaguesValue)>0.5)? applyVaguesCoeff((Math.cos(vaguesValue)>0.5)?
((float)Math.cos(vaguesValue)-0.5f)*2:0,(int)Main.HEIGHT/8,Main.HEIGHT/4*3); ((float)Math.cos(vaguesValue)-0.5f)*2:0,(int)Main.HEIGHT/8,Main.HEIGHT/4*3);
@ -158,7 +191,7 @@ public class MainWorld {
} }
public void render(){ public void render(){
if(!Input.isKey(this.game.helpKey)){ if(!Input.isKey(this.game.helpKey) && this.game.scores[0] > 0 && this.game.scores[1] > 0){
for(Tile t : tiles)t.render(); for(Tile t : tiles)t.render();
} }
} }
@ -168,48 +201,17 @@ public class MainWorld {
tiles.clear(); tiles.clear();
} }
private void generateEntity(int nb){ public void genererBonusMalus(int nombre){
final int MIN_HAUTEUR_MAX=150;//gére la hauteur min de la hauteur maximum de la vague int minWidth = 50;
final int MIN_HAUTEUR=80;//hauteur min que doit monter la vague int minHeight = Main.WIDTH - minWidth;
final int MAX_HAUTEUR_MAX=Main.HEIGHT-80;//hauteur maximum que peut monter la vague au max EObjetType[] types = EObjetType.values();
for(int i = 0;i < nombre;i++){
EObjetType type = types[(int)(Math.random() * types.length)];
int hauteurMax = (int) (MIN_HAUTEUR_MAX +Math.random()* MAX_HAUTEUR_MAX); Objet o = new Objet(type.getFilename(), (float)(Math.random() * (minHeight - minWidth)), 150, 0, 0, 5, 0.02f);
int nbMin = 1; o.setType(type);
int nbMax = 1; tiles.add(o.getTile());
listObjet.add(o);
if(hauteurMax<=MIN_HAUTEUR_MAX){ }
nbMin=nb-1;
nbMax=1;
}
if(hauteurMax>MIN_HAUTEUR_MAX && hauteurMax<Main.HEIGHT/2){
nbMin=nb-1;
nbMax=nb+1;
}
if(hauteurMax>=Main.HEIGHT/2){
nbMin=1;
nbMax=nb+1;
}
int countJ1=(int)(nbMin + Math.random()*nbMax);
int countJ2=(int)(nbMin + Math.random()*nbMax);
for(int i =0;i<countJ1;i++){
Objet o = new Objet("",(float)(Math.random()* Main.WIDTH/2),(float) (MIN_HAUTEUR+Math.random()* hauteurMax), 50, 0, 0, 0f, 0.1f);
listObjet.add(o);
tiles.add(o.getTile());
}
for(int i =0;i<countJ2;i++){
Objet o = new Objet("",(float)(Main.WIDTH/2+Math.random()* Main.WIDTH),(float) (MIN_HAUTEUR +Math.random()* hauteurMax), 50, 0, 0, 0f, 0.1f);
listObjet.add(o);
tiles.add(o.getTile());
}
} }
private void applyVaguesCoeff(float coeff,int offset,int height){ private void applyVaguesCoeff(float coeff,int offset,int height){
@ -223,4 +225,8 @@ public class MainWorld {
o.move(); o.move();
} }
} }
public void degenererObjet(int hauteur){
}
} }