Add Physics alpha
Before Width: | Height: | Size: 700 KiB After Width: | Height: | Size: 531 KiB |
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 1.6 KiB |
BIN
res/textures/contour.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
Before Width: | Height: | Size: 700 KiB After Width: | Height: | Size: 531 KiB |
BIN
res/textures/mur.png
Normal file
After Width: | Height: | Size: 2.1 KiB |
BIN
res/textures/murcoté.png
Normal file
After Width: | Height: | Size: 1.8 KiB |
BIN
res/textures/murhauteur.png
Normal file
After Width: | Height: | Size: 129 B |
Before Width: | Height: | Size: 2.3 KiB After Width: | Height: | Size: 1.6 KiB |
BIN
res/textures/vagues.png
Normal file
After Width: | Height: | Size: 58 KiB |
|
@ -2,30 +2,11 @@ package globalgamejam.game;
|
|||
|
||||
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
import com.sun.xml.internal.bind.v2.schemagen.xmlschema.List;
|
||||
|
||||
import globalgamejam.Main;
|
||||
import globalgamejam.gui.ActionGUI;
|
||||
import globalgamejam.gui.GUI;
|
||||
import globalgamejam.gui.GUILabel;
|
||||
import globalgamejam.render.Camera;
|
||||
import globalgamejam.tiles.Fond;
|
||||
import globalgamejam.tiles.Objet;
|
||||
import globalgamejam.tiles.Tile;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
import globalgamejam.interfaces.MainInterfaces;
|
||||
|
||||
import globalgamejam.world.MainWorld;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.lwjgl.glfw.GLFW;
|
||||
|
||||
/**
|
||||
* Class created by MrDev023 (Florian RICHER) on 14/01/2017
|
||||
*/
|
||||
|
|
32
src/globalgamejam/game/Objet.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package globalgamejam.game;
|
||||
|
||||
import globalgamejam.math.Vector2f;
|
||||
import globalgamejam.physics.PhysicalEntity;
|
||||
import globalgamejam.tiles.ObjetTile;
|
||||
import globalgamejam.tiles.Tile;
|
||||
|
||||
public class Objet extends PhysicalEntity {
|
||||
|
||||
private final Tile tile;
|
||||
|
||||
public Objet(String texturePath, float x, float y, float sizeRadius, float speed, float xVelocity, float yVelocity, float frictionFactor){
|
||||
super(x, y, sizeRadius, speed, xVelocity, yVelocity, frictionFactor);
|
||||
|
||||
this.tile = new ObjetTile(texturePath, x, y);
|
||||
}
|
||||
|
||||
public Tile getTile(){
|
||||
return this.tile;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void moveTile(){
|
||||
this.tile.setPosition(new Vector2f(this.x, this.y));
|
||||
this.tile.applyTransform();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return "x : " + this.x + ", y : " + this.y;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package globalgamejam.game;
|
|||
import globalgamejam.math.Vector2f;
|
||||
import globalgamejam.physics.PhysicalEntity;
|
||||
import globalgamejam.render.Texture;
|
||||
import globalgamejam.tiles.PlayerTile;
|
||||
import globalgamejam.tiles.Tile;
|
||||
|
||||
/**
|
||||
|
@ -15,15 +16,23 @@ public class Player extends PhysicalEntity {
|
|||
private final Tile tile;
|
||||
private float angle;
|
||||
|
||||
private float speed = 3;
|
||||
|
||||
private final PhysicalEntity brosse;
|
||||
private final float longueurBalai;
|
||||
|
||||
public Player(float x, float y){
|
||||
super(x, y, 100, 0, 0, 10);
|
||||
super(x, y, 100, 3, 0, 0, 10);
|
||||
this.tile = new PlayerTile("res/textures/perso.png", x, y);
|
||||
|
||||
this.longueurBalai = 100;
|
||||
this.brosse = new PhysicalEntity(x, y + this.longueurBalai, 20, 0, 0, 0);
|
||||
this.longueurBalai = 80;
|
||||
|
||||
this.brosse = new PhysicalEntity(x, y + this.longueurBalai, 2f, 3, 0, 0, 0){
|
||||
@Override
|
||||
public float getSpeed(){
|
||||
return getSpeedFactor();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public Tile getTile(){
|
||||
|
@ -50,8 +59,8 @@ public class Player extends PhysicalEntity {
|
|||
|
||||
float angleRad = (float)(this.angle * (Math.PI / 180));
|
||||
|
||||
float xBrosse = this.x + this.longueurBalai * (float)Math.cos(angleRad);
|
||||
float yBrosse = this.y + this.longueurBalai * (float)Math.sin(angleRad);
|
||||
float xBrosse = this.x + this.longueurBalai * -(float)Math.sin(angleRad);
|
||||
float yBrosse = this.y + this.longueurBalai * (float)Math.cos(angleRad);
|
||||
|
||||
this.brosse.setPosition(xBrosse, yBrosse);
|
||||
}
|
||||
|
@ -60,23 +69,19 @@ public class Player extends PhysicalEntity {
|
|||
return this.brosse.collideWithSquareHitBox(entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the velocity
|
||||
*/
|
||||
public float getSpeed() {
|
||||
return this.speed;
|
||||
}
|
||||
|
||||
public PhysicalEntity getBrosse(){
|
||||
return this.brosse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return this.brosse.toString();
|
||||
}
|
||||
|
||||
private class PlayerTile extends Tile {
|
||||
|
||||
public PlayerTile(String texturePath, float x, float y){
|
||||
super();
|
||||
|
||||
this.setTexture(Texture.loadTexture(texturePath));
|
||||
|
||||
this.setPosition(new Vector2f(x, y));
|
||||
|
||||
this.setScale(new Vector2f(this.getTexture().width, this.getTexture().height));
|
||||
|
||||
this.applyTransform();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class MainInterfaces {
|
|||
guis.add(p2);
|
||||
|
||||
//Menu Help
|
||||
helpLabel = new GUILabel("HELP",Main.WIDTH/2,10,Color.WHITE,"Arial",16);
|
||||
helpLabel = new GUILabel("HELP",Main.WIDTH/2,10,Color.WHITE,"Arial",32);
|
||||
helpLabel.setX(Main.WIDTH/2 - helpLabel.getWitdh()/2);
|
||||
guisHelp.add(helpLabel);
|
||||
}
|
||||
|
|
|
@ -14,16 +14,21 @@ public class PhysicalEntity {
|
|||
|
||||
private float xVelocity;
|
||||
private float yVelocity;
|
||||
private float speedFactor;
|
||||
|
||||
private float speed;
|
||||
|
||||
private float frictionFactor;
|
||||
|
||||
public PhysicalEntity(float x, float y, float sizeRadius, 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.y = y;
|
||||
this.sizeRadius = sizeRadius;
|
||||
this.xVelocity = xVelocity;
|
||||
this.yVelocity = yVelocity;
|
||||
this.frictionFactor = frictionFactor;
|
||||
this.speedFactor = speedFactor;
|
||||
this.speed = 0;
|
||||
}
|
||||
|
||||
public boolean collideWithSquareHitBox(PhysicalEntity entity){
|
||||
|
@ -44,6 +49,14 @@ public class PhysicalEntity {
|
|||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Déplace l'entity et actualise ça vélocité
|
||||
*/
|
||||
|
@ -51,18 +64,24 @@ public class PhysicalEntity {
|
|||
this.x += this.xVelocity;
|
||||
this.y += this.yVelocity;
|
||||
|
||||
this.xVelocity *= -this.frictionFactor;
|
||||
this.yVelocity *= -this.frictionFactor;
|
||||
this.xVelocity *= 1 - this.frictionFactor;
|
||||
this.yVelocity *= 1 - this.frictionFactor;
|
||||
|
||||
if(this.xVelocity <= 0.1){
|
||||
if(this.xVelocity < 0.001 && this.xVelocity > 0.001){
|
||||
this.xVelocity = 0;
|
||||
}
|
||||
|
||||
if(this.yVelocity <= 0.1){
|
||||
if(this.yVelocity < 0.001 && this.yVelocity > 0.001){
|
||||
this.yVelocity = 0;
|
||||
}
|
||||
|
||||
this.speed = (float)Math.sqrt( this.xVelocity * this.xVelocity + this.yVelocity * this.yVelocity );
|
||||
|
||||
this.moveTile();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setPosition(float x, float y){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
@ -73,6 +92,53 @@ public class PhysicalEntity {
|
|||
this.y += y;
|
||||
}
|
||||
|
||||
public void setVelocity(float x, float y){
|
||||
this.xVelocity = x;
|
||||
this.yVelocity = y;
|
||||
}
|
||||
|
||||
public void addVelocity(float x, float y){
|
||||
this.xVelocity += x;
|
||||
this.yVelocity += y;
|
||||
}
|
||||
|
||||
protected void moveTile(){
|
||||
|
||||
}
|
||||
|
||||
public float getX(){
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public float getY(){
|
||||
return this.y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the speed
|
||||
*/
|
||||
public float getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param speed the speed to set
|
||||
*/
|
||||
public void setSpeed(float speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public float getSpeedFactor() {
|
||||
return speedFactor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the sizeRadius
|
||||
*/
|
||||
public float getSizeRadius() {
|
||||
return sizeRadius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return this.x + " " + this.y;
|
||||
|
|
|
@ -2,15 +2,17 @@ package globalgamejam.tiles;
|
|||
|
||||
import globalgamejam.math.Color4f;
|
||||
import globalgamejam.math.Vector2f;
|
||||
import globalgamejam.render.Texture;
|
||||
|
||||
public class Mur extends Tile{
|
||||
|
||||
public Mur(int x,int y,int scaleX,int scaleY){
|
||||
public Mur(int x,int y,int scaleX,int scaleY,String path){
|
||||
super();
|
||||
super.setColor(Color4f.BLACK);
|
||||
//super.setColor(Color4f.BLACK);
|
||||
super.setPosition(new Vector2f(x, y));
|
||||
super.setScale(new Vector2f(scaleX, scaleY));
|
||||
super.setTexture(Texture.loadTexture(path));
|
||||
|
||||
super.applyTransform();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package globalgamejam.tiles;
|
||||
|
||||
import globalgamejam.math.Color4f;
|
||||
import globalgamejam.math.Vector2f;
|
||||
|
||||
public class Objet extends Tile {
|
||||
public Objet(int x,int y){
|
||||
super();
|
||||
super.setColor(Color4f.RED);
|
||||
super.setPosition(new Vector2f(x, y));
|
||||
super.setScale(new Vector2f(10, 10));
|
||||
super.applyTransform();
|
||||
}
|
||||
}
|
20
src/globalgamejam/tiles/ObjetTile.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package globalgamejam.tiles;
|
||||
|
||||
import globalgamejam.math.Color4f;
|
||||
import globalgamejam.math.Vector2f;
|
||||
import globalgamejam.render.Texture;
|
||||
|
||||
public class ObjetTile extends Tile {
|
||||
|
||||
public ObjetTile(String texturePath, float x, float y){
|
||||
super();
|
||||
super.setColor(Color4f.RED);
|
||||
// this.setTexture(Texture.loadTexture(texturePath));
|
||||
|
||||
this.setPosition(new Vector2f(x, y));
|
||||
|
||||
this.setScale(new Vector2f(this.getTexture().width, this.getTexture().height));
|
||||
|
||||
this.applyTransform();
|
||||
}
|
||||
}
|
24
src/globalgamejam/tiles/PlayerTile.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
package globalgamejam.tiles;
|
||||
|
||||
import globalgamejam.math.Vector2f;
|
||||
import globalgamejam.render.Texture;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jean-Baptiste
|
||||
*
|
||||
*/
|
||||
public class PlayerTile extends Tile {
|
||||
|
||||
public PlayerTile(String texturePath, float x, float y){
|
||||
super();
|
||||
|
||||
this.setTexture(Texture.loadTexture(texturePath));
|
||||
|
||||
this.setPosition(new Vector2f(x, y));
|
||||
|
||||
this.setScale(new Vector2f(this.getTexture().width, this.getTexture().height));
|
||||
|
||||
this.applyTransform();
|
||||
}
|
||||
}
|
12
src/globalgamejam/tiles/VaguesTile.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package globalgamejam.tiles;
|
||||
|
||||
import globalgamejam.render.Texture;
|
||||
|
||||
public class VaguesTile extends Tile {
|
||||
|
||||
public VaguesTile(String path){
|
||||
super();
|
||||
super.setTexture(Texture.loadTexture(path));
|
||||
}
|
||||
|
||||
}
|
|
@ -6,12 +6,14 @@ import org.lwjgl.glfw.GLFW;
|
|||
|
||||
import globalgamejam.Main;
|
||||
import globalgamejam.game.MainGame;
|
||||
import globalgamejam.game.Objet;
|
||||
import globalgamejam.game.Player;
|
||||
import globalgamejam.input.Input;
|
||||
import globalgamejam.tiles.Fond;
|
||||
import globalgamejam.tiles.Mur;
|
||||
import globalgamejam.tiles.Objet;
|
||||
import globalgamejam.tiles.ObjetTile;
|
||||
import globalgamejam.tiles.Tile;
|
||||
import globalgamejam.tiles.VaguesTile;
|
||||
|
||||
/**
|
||||
* Created by trexr on 20/01/2017.
|
||||
|
@ -23,11 +25,16 @@ public class MainWorld {
|
|||
private MainGame game;
|
||||
|
||||
private Player player1,player2;
|
||||
private Mur mur1,mur2,mur3;
|
||||
private Mur mur1,mur2,mur3,murGauche,murDroit,murHaut,murBas;
|
||||
private VaguesTile vagues;
|
||||
private float vaguesValue;
|
||||
|
||||
private ArrayList<Objet> listObjet;
|
||||
|
||||
public MainWorld(MainGame game){
|
||||
this.game = game;
|
||||
tiles = new ArrayList<Tile>();
|
||||
tiles = new ArrayList<>();
|
||||
listObjet = new ArrayList<>();
|
||||
init();
|
||||
}
|
||||
|
||||
|
@ -40,65 +47,94 @@ public class MainWorld {
|
|||
fond.getTransform().translate(Main.WIDTH/2, Main.HEIGHT/2, 0);
|
||||
fond.getTransform().scale(Main.WIDTH,Main.HEIGHT, 0);
|
||||
|
||||
this.mur1 = new Mur(Main.WIDTH/2-10, Main.HEIGHT - 50, 20, 150);
|
||||
this.mur2 = new Mur(Main.WIDTH/2-10, Main.HEIGHT - 250, 20, 50);
|
||||
this.mur3 = new Mur(Main.WIDTH/2-10, Main.HEIGHT - 400, 20, 150);
|
||||
|
||||
vagues = new VaguesTile("res/textures/vagues.png");
|
||||
vagues.getTransform().translate(Main.WIDTH/2, -Main.HEIGHT/2, 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.mur2 = new Mur(Main.WIDTH/2-10, Main.HEIGHT - 250, 20, 50,"res/textures/mur.png");
|
||||
this.mur3 = new Mur(Main.WIDTH/2-10, Main.HEIGHT - 400, 20, 150,"res/textures/mur.png");
|
||||
this.murGauche=new Mur(0,Main.HEIGHT/2+40,30,Main.HEIGHT-80,"res/textures/murcoté.png");
|
||||
this.murDroit=new Mur(Main.WIDTH,Main.HEIGHT/2+40,30,Main.HEIGHT-80,"res/textures/murcoté.png");
|
||||
this.murHaut=new Mur(Main.WIDTH/2,Main.HEIGHT,Main.WIDTH,70,"res/textures/murhauteur.png");
|
||||
this.murBas=new Mur(Main.WIDTH/2,80,Main.WIDTH,20,"res/textures/murhauteur.png");
|
||||
tiles.add(fond);
|
||||
tiles.add(player1.getTile());
|
||||
tiles.add(player2.getTile());
|
||||
tiles.add(vagues);
|
||||
tiles.add(murGauche);
|
||||
tiles.add(murDroit);
|
||||
tiles.add(murHaut);
|
||||
tiles.add(murBas);
|
||||
tiles.add(this.mur1);
|
||||
tiles.add(this.mur2);
|
||||
tiles.add(this.mur3);
|
||||
tiles.add(player1.getTile());
|
||||
tiles.add(player2.getTile());
|
||||
|
||||
|
||||
|
||||
generateEntity(3);
|
||||
}
|
||||
|
||||
public void update(){
|
||||
|
||||
this.moveObjets();
|
||||
|
||||
if(!Input.isKey(this.game.helpKey)){
|
||||
//Player 1
|
||||
float xDep = 0, yDep = 0;
|
||||
if(Input.isKey(GLFW.GLFW_KEY_W)){
|
||||
yDep = 10;
|
||||
if(Input.isKey(GLFW.GLFW_KEY_W) && player1.getTile().getPosition().y + player1.getTile().getScale().y/2.0f <= Main.HEIGHT - murHaut.getScale().y/2.0f){
|
||||
yDep = player1.getSpeed();
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_S)){
|
||||
yDep = -10;
|
||||
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){
|
||||
yDep = -player1.getSpeed();
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_A)){
|
||||
xDep = -10;
|
||||
if(Input.isKey(GLFW.GLFW_KEY_A) && player1.getTile().getPosition().x - player1.getTile().getScale().x/2.0f >= 0.0f + murGauche.getScale().getX()/2.0f){
|
||||
xDep = -player1.getSpeed();
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_D)){
|
||||
xDep = 10;
|
||||
if(Input.isKey(GLFW.GLFW_KEY_D) && player1.getTile().getPosition().x + player1.getTile().getScale().x/2.0f <= Main.WIDTH/2.0f){
|
||||
xDep = 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);
|
||||
|
||||
if(Input.isKey(GLFW.GLFW_KEY_Q)){
|
||||
player1.rotate(-5);
|
||||
player1.rotate(5);
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_E)){
|
||||
player1.rotate(5);
|
||||
player1.rotate(-5);
|
||||
}
|
||||
|
||||
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
|
||||
xDep = 0;
|
||||
yDep = 0;
|
||||
if(Input.isKey(GLFW.GLFW_KEY_I)){
|
||||
yDep = 10;
|
||||
if(Input.isKey(GLFW.GLFW_KEY_I) && player2.getTile().getPosition().y + player2.getTile().getScale().y/2.0f <= Main.HEIGHT - murHaut.getScale().y/2.0f){
|
||||
yDep = player2.getSpeed();
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_K)){
|
||||
yDep = -10;
|
||||
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_J)){
|
||||
xDep = -10;
|
||||
if(Input.isKey(GLFW.GLFW_KEY_J ) && player2.getTile().getPosition().x - player2.getTile().getScale().x/2.0f >= Main.WIDTH/2.0f){
|
||||
xDep = -player2.getSpeed();
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_L)){
|
||||
xDep = 10;
|
||||
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();
|
||||
}
|
||||
|
||||
if(xDep != 0.0 && yDep != 0.0){
|
||||
|
@ -109,12 +145,16 @@ public class MainWorld {
|
|||
player2.move(xDep, yDep);
|
||||
|
||||
if(Input.isKey(GLFW.GLFW_KEY_U)){
|
||||
player2.rotate(-5);
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_O)){
|
||||
player2.rotate(5);
|
||||
}
|
||||
if(Input.isKey(GLFW.GLFW_KEY_O)){
|
||||
player2.rotate(-5);
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
public void render(){
|
||||
|
@ -128,43 +168,59 @@ public class MainWorld {
|
|||
tiles.clear();
|
||||
}
|
||||
|
||||
public void generateEntity(int nb){
|
||||
final int MIN_HAUTEUR_MAX=150;
|
||||
final int MIN_HAUTEUR=80;
|
||||
private void generateEntity(int nb){
|
||||
final int MIN_HAUTEUR_MAX=150;//gére la hauteur min de la hauteur maximum de la vague
|
||||
final int MIN_HAUTEUR=80;//hauteur min que doit monter la vague
|
||||
final int MAX_HAUTEUR_MAX=Main.HEIGHT-80;//hauteur maximum que peut monter la vague au max
|
||||
|
||||
|
||||
int hauteurMax = (int) (MIN_HAUTEUR_MAX +Math.random()* Main.HEIGHT-80);
|
||||
int nbMin = 0;
|
||||
int nbMax = 0;
|
||||
ArrayList<Tile> list = new ArrayList<>();
|
||||
if(hauteurMax<MIN_HAUTEUR_MAX){
|
||||
nbMin=nb-2;
|
||||
nbMax=0;
|
||||
int hauteurMax = (int) (MIN_HAUTEUR_MAX +Math.random()* MAX_HAUTEUR_MAX);
|
||||
int nbMin = 1;
|
||||
int nbMax = 1;
|
||||
|
||||
if(hauteurMax<=MIN_HAUTEUR_MAX){
|
||||
nbMin=nb-1;
|
||||
nbMax=1;
|
||||
}
|
||||
if(hauteurMax>MIN_HAUTEUR_MAX && hauteurMax<Main.HEIGHT/2){
|
||||
nbMin=nb-2;
|
||||
nbMax=nb+2;
|
||||
nbMin=nb-1;
|
||||
nbMax=nb+1;
|
||||
}
|
||||
if(hauteurMax>Main.HEIGHT/2){
|
||||
nbMin=0;
|
||||
nbMax=nb+2;
|
||||
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++){
|
||||
|
||||
list.add(new Objet((int)(Math.random()* Main.WIDTH/2),(int) (MIN_HAUTEUR+Math.random()* hauteurMax)));
|
||||
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++){
|
||||
|
||||
list.add(new Objet((int)(Main.WIDTH/2+Math.random()* Main.WIDTH),(int) (MIN_HAUTEUR +Math.random()* hauteurMax)));
|
||||
}
|
||||
|
||||
for(Tile t : list){
|
||||
tiles.add(t);
|
||||
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){
|
||||
vagues.getTransform().loadIdentity();
|
||||
vagues.getTransform().translate(Main.WIDTH/2, -Main.HEIGHT/2 + height*coeff + offset,0);
|
||||
vagues.getTransform().scale(Main.WIDTH,Main.HEIGHT, 0);
|
||||
}
|
||||
|
||||
private void moveObjets(){
|
||||
for(Objet o : this.listObjet){
|
||||
o.move();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|