implémentation partielle du moteur physique
This commit is contained in:
parent
243864a621
commit
67de09af29
5 changed files with 159 additions and 17 deletions
|
@ -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;
|
||||
}
|
|
@ -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<Tile> tiles;
|
||||
private FrameBufferObject fbo;
|
||||
|
||||
private Random rand;
|
||||
|
||||
private Player player1;
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
fbo = new FrameBufferObject();
|
||||
tiles = new ArrayList<Tile>();
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
73
src/globalgamejam/game/Player.java
Normal file
73
src/globalgamejam/game/Player.java
Normal file
|
@ -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));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
70
src/globalgamejam/physics/PhysicalEntity.java
Normal file
70
src/globalgamejam/physics/PhysicalEntity.java
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package globalgamejam.tiles;
|
||||
|
||||
public class PlayerTile extends Tile {
|
||||
|
||||
public PlayerTile(){
|
||||
super();
|
||||
}
|
||||
}
|
Reference in a new issue