diff --git a/res/shaders/main.frag b/res/shaders/main.frag index 5fb950e..a0c0b6e 100644 --- a/res/shaders/main.frag +++ b/res/shaders/main.frag @@ -6,9 +6,11 @@ uniform vec4 color; in vec2 fragTexCoord; in vec3 fragVert; +out vec4 finalColor; + //layout(location = 0) out vec4 finalColor; // https://learnopengl.com/#!Lighting/Multiple-lights pour le lighing en cas de besoin void main() { - gl_FragData[0] = texture(materialTex, fragTexCoord) * color; + finalColor = texture(materialTex, fragTexCoord) * color; } \ No newline at end of file diff --git a/src/globalgamejam/game/MainGame.java b/src/globalgamejam/game/MainGame.java index 672e276..1e373f0 100644 --- a/src/globalgamejam/game/MainGame.java +++ b/src/globalgamejam/game/MainGame.java @@ -1,10 +1,12 @@ package globalgamejam.game; +import globalgamejam.math.Vector2f; import globalgamejam.render.*; import globalgamejam.tiles.TestTile; import globalgamejam.tiles.Tile; import java.util.ArrayList; +import java.util.Random; /** * Class created by MrDev023 (Florian RICHER) on 14/01/2017 @@ -12,31 +14,35 @@ import java.util.ArrayList; public class MainGame extends Game{ private ArrayList tiles; - private FrameBufferObject fbo; + + private Random rand; + + private Player player1; @Override public void init() { - fbo = new FrameBufferObject(); tiles = new ArrayList(); TestTile t = new TestTile(); t.getTransform().translate(100,100,0); t.getTransform().scale(10,10,0); tiles.add(t); + + player1 = new Player(-100, 0); + tiles.add(player1.getTile()); + + rand = new Random(); } @Override public void update() { Camera.transform(); - + // player1.setPosition((rand.nextFloat() - 0.5f) * 200f, (rand.nextFloat() - 0.5f) * 150f); + // player1.applyTransform(); } @Override public void render2D() { - fbo.startRenderToFBO(); for(Tile t : tiles)t.render(); - fbo.stopRenderToFBO(); - - fbo.renderFBO(); } @@ -47,7 +53,6 @@ public class MainGame extends Game{ @Override public void destroy() { - fbo.destroy(); tiles.clear(); } 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(); - } -}