diff --git a/out/production/Global-Gam-Jam-2017/textures/fond.png b/out/production/Global-Gam-Jam-2017/textures/fond.png index 26fac78..71a3059 100644 Binary files a/out/production/Global-Gam-Jam-2017/textures/fond.png and b/out/production/Global-Gam-Jam-2017/textures/fond.png differ diff --git a/out/production/Global-Gam-Jam-2017/textures/perso.png b/out/production/Global-Gam-Jam-2017/textures/perso.png index 052aac0..dea56b8 100644 Binary files a/out/production/Global-Gam-Jam-2017/textures/perso.png and b/out/production/Global-Gam-Jam-2017/textures/perso.png differ diff --git a/res/textures/contour.png b/res/textures/contour.png new file mode 100644 index 0000000..d0cb528 Binary files /dev/null and b/res/textures/contour.png differ diff --git a/res/textures/fond.png b/res/textures/fond.png index 26fac78..71a3059 100644 Binary files a/res/textures/fond.png and b/res/textures/fond.png differ diff --git a/res/textures/mur.png b/res/textures/mur.png new file mode 100644 index 0000000..c93a68a Binary files /dev/null and b/res/textures/mur.png differ diff --git a/res/textures/murcoté.png b/res/textures/murcoté.png new file mode 100644 index 0000000..282dbe0 Binary files /dev/null and b/res/textures/murcoté.png differ diff --git a/res/textures/murhauteur.png b/res/textures/murhauteur.png new file mode 100644 index 0000000..f2bb0aa Binary files /dev/null and b/res/textures/murhauteur.png differ diff --git a/res/textures/perso.png b/res/textures/perso.png index 052aac0..dea56b8 100644 Binary files a/res/textures/perso.png and b/res/textures/perso.png differ diff --git a/res/textures/vagues.png b/res/textures/vagues.png new file mode 100644 index 0000000..6bffabf Binary files /dev/null and b/res/textures/vagues.png differ diff --git a/src/globalgamejam/game/MainGame.java b/src/globalgamejam/game/MainGame.java index 9ffb48c..0724bf6 100644 --- a/src/globalgamejam/game/MainGame.java +++ b/src/globalgamejam/game/MainGame.java @@ -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 */ diff --git a/src/globalgamejam/game/Objet.java b/src/globalgamejam/game/Objet.java new file mode 100644 index 0000000..077e67a --- /dev/null +++ b/src/globalgamejam/game/Objet.java @@ -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; + } +} diff --git a/src/globalgamejam/game/Player.java b/src/globalgamejam/game/Player.java index fe8c093..6b33475 100644 --- a/src/globalgamejam/game/Player.java +++ b/src/globalgamejam/game/Player.java @@ -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(); - } - } } diff --git a/src/globalgamejam/interfaces/MainInterfaces.java b/src/globalgamejam/interfaces/MainInterfaces.java index 8c82d3e..c67475e 100644 --- a/src/globalgamejam/interfaces/MainInterfaces.java +++ b/src/globalgamejam/interfaces/MainInterfaces.java @@ -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); } diff --git a/src/globalgamejam/physics/PhysicalEntity.java b/src/globalgamejam/physics/PhysicalEntity.java index 87d8b54..8845ff7 100644 --- a/src/globalgamejam/physics/PhysicalEntity.java +++ b/src/globalgamejam/physics/PhysicalEntity.java @@ -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; diff --git a/src/globalgamejam/tiles/Mur.java b/src/globalgamejam/tiles/Mur.java index ea10fdf..83427fb 100644 --- a/src/globalgamejam/tiles/Mur.java +++ b/src/globalgamejam/tiles/Mur.java @@ -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(); } - -} +} \ No newline at end of file diff --git a/src/globalgamejam/tiles/Objet.java b/src/globalgamejam/tiles/Objet.java deleted file mode 100644 index c799361..0000000 --- a/src/globalgamejam/tiles/Objet.java +++ /dev/null @@ -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(); - } -} diff --git a/src/globalgamejam/tiles/ObjetTile.java b/src/globalgamejam/tiles/ObjetTile.java new file mode 100644 index 0000000..94890dc --- /dev/null +++ b/src/globalgamejam/tiles/ObjetTile.java @@ -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(); + } +} diff --git a/src/globalgamejam/tiles/PlayerTile.java b/src/globalgamejam/tiles/PlayerTile.java new file mode 100644 index 0000000..c4c67d7 --- /dev/null +++ b/src/globalgamejam/tiles/PlayerTile.java @@ -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(); + } +} \ No newline at end of file diff --git a/src/globalgamejam/tiles/VaguesTile.java b/src/globalgamejam/tiles/VaguesTile.java new file mode 100644 index 0000000..28f47a7 --- /dev/null +++ b/src/globalgamejam/tiles/VaguesTile.java @@ -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)); + } + +} diff --git a/src/globalgamejam/world/MainWorld.java b/src/globalgamejam/world/MainWorld.java index b3e53e9..a532af7 100644 --- a/src/globalgamejam/world/MainWorld.java +++ b/src/globalgamejam/world/MainWorld.java @@ -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 listObjet; public MainWorld(MainGame game){ this.game = game; - tiles = new ArrayList(); + 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 list = new ArrayList<>(); - if(hauteurMaxMIN_HAUTEUR_MAX && hauteurMaxMain.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