diff --git a/src/globalgamejam/game/MainGame.java b/src/globalgamejam/game/MainGame.java index a3516d6..d7ed9b9 100644 --- a/src/globalgamejam/game/MainGame.java +++ b/src/globalgamejam/game/MainGame.java @@ -1,9 +1,13 @@ package globalgamejam.game; + import java.awt.Color; import java.util.ArrayList; import globalgamejam.Main; + +import globalgamejam.math.Vector2f; + import globalgamejam.gui.ActionGUI; import globalgamejam.gui.GUI; import globalgamejam.gui.GUILabel; @@ -12,12 +16,23 @@ import globalgamejam.tiles.Fond; import globalgamejam.tiles.TestTile; import globalgamejam.tiles.Tile; + +import java.awt.*; +import java.util.ArrayList; +import java.util.Random; + + /** * Class created by MrDev023 (Florian RICHER) on 14/01/2017 */ public class MainGame extends Game{ private ArrayList tiles; + + private Random rand; + + private Player player1; + private ArrayList guis; private GUILabel label; @@ -36,6 +51,12 @@ public class MainGame extends Game{ tiles.add(fond); tiles.add(t); + + player1 = new Player(-100, 0); + tiles.add(player1.getTile()); + + rand = new Random(); + label = new GUILabel("Test"); label.setX(10); label.setY(10); @@ -57,6 +78,8 @@ public class MainGame extends Game{ @Override public void update() { Camera.transform(); + // player1.setPosition((rand.nextFloat() - 0.5f) * 200f, (rand.nextFloat() - 0.5f) * 150f); + // player1.applyTransform(); for(GUI g : guis)g.update(); } diff --git a/src/globalgamejam/game/Player.java b/src/globalgamejam/game/Player.java new file mode 100644 index 0000000..19332e3 --- /dev/null +++ b/src/globalgamejam/game/Player.java @@ -0,0 +1,73 @@ +package globalgamejam.game; + +import globalgamejam.math.Vector2f; +import globalgamejam.physics.PhysicalEntity; +import globalgamejam.render.Texture; +import globalgamejam.tiles.Tile; + +/** + * + * @author Jean-Baptiste + * + */ +public class Player extends PhysicalEntity { + + private final Tile tile; + private float angle; + + private final PhysicalEntity brosse; + private final float longueurBalai; + + public Player(float x, float y){ + super(x, y, 100, 0, 0, 10); + this.tile = new PlayerTile("res/textures/default.png", -250, 0); + + this.longueurBalai = 100; + this.brosse = new PhysicalEntity(x, y + this.longueurBalai, 20, 0, 0, 0); + } + + public Tile getTile(){ + return this.tile; + } + + public void rotate(float angleRotation){ + this.angle += angleRotation; + this.angle %= 360; + if(this.angle < 0){ + this.angle += 360; + } + + this.tile.setRotation(this.angle); + + 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); + + this.brosse.setPosition(xBrosse, yBrosse); + } + + public boolean brosseCollideWith(PhysicalEntity entity){ + return this.brosse.collideWithSquareHitBox(entity); + } + + private class PlayerTile extends Tile { + + public PlayerTile(String texturePath, float x, float y){ + super(); + + this.setTexture(Texture.loadTexture(texturePath)); + + this.setPosition(x, y); + + this.setScale(new Vector2f(50, 50)); + + this.applyTransform(); + } + + public void setPosition(float x, float y){ + this.setPosition(new Vector2f(x, y)); + + } + } +} diff --git a/src/globalgamejam/physics/PhysicalEntity.java b/src/globalgamejam/physics/PhysicalEntity.java new file mode 100644 index 0000000..abfd803 --- /dev/null +++ b/src/globalgamejam/physics/PhysicalEntity.java @@ -0,0 +1,70 @@ +package globalgamejam.physics; + +/** + * + * @author Jean-Baptiste + * + */ +public class PhysicalEntity { + + protected float x; + protected float y; + + private float sizeRadius; + + private float xVelocity; + private float yVelocity; + + private float frictionFactor; + + public PhysicalEntity(float x, float y, float sizeRadius, float xVelocity, float yVelocity, float frictionFactor) { + this.x = x; + this.y = y; + this.sizeRadius = sizeRadius; + this.xVelocity = xVelocity; + this.yVelocity = yVelocity; + this.frictionFactor = frictionFactor; + } + + public boolean collideWithSquareHitBox(PhysicalEntity entity){ + + // on teste une collision avec une hitbox carré + return (this.x + this.sizeRadius >= entity.x - entity.sizeRadius + && this.x - this.sizeRadius <= entity.x + entity.sizeRadius + && this.y + this.sizeRadius >= entity.y - entity.sizeRadius + && this.y - this.sizeRadius <= entity.y + entity.sizeRadius); + } + /* + public boolean collideWithRoundHitBox(PhysicalEntity entity){ + if(this.collideWithSquareHitBox(entity)){ + + // teste avec une hitbox ronde à venir ... + return true; + } + return false; + } + */ + /** + * Déplace l'entity et actualise ça vélocité + */ + public void move(){ + this.x += this.xVelocity; + this.y += this.yVelocity; + + this.xVelocity *= -this.frictionFactor; + this.yVelocity *= -this.frictionFactor; + + if(this.xVelocity <= 0.1){ + this.xVelocity = 0; + } + + if(this.yVelocity <= 0.1){ + this.yVelocity = 0; + } + } + + public void setPosition(float x, float y){ + this.x = x; + this.y = y; + } +} diff --git a/src/globalgamejam/tiles/PlayerTile.java b/src/globalgamejam/tiles/PlayerTile.java deleted file mode 100644 index 171dd31..0000000 --- a/src/globalgamejam/tiles/PlayerTile.java +++ /dev/null @@ -1,8 +0,0 @@ -package globalgamejam.tiles; - -public class PlayerTile extends Tile { - - public PlayerTile(){ - super(); - } -}