diff --git a/res/textures/perso.png b/res/textures/perso.png new file mode 100644 index 0000000..052aac0 Binary files /dev/null and b/res/textures/perso.png differ diff --git a/src/globalgamejam/game/MainGame.java b/src/globalgamejam/game/MainGame.java index d33db98..05331e7 100644 --- a/src/globalgamejam/game/MainGame.java +++ b/src/globalgamejam/game/MainGame.java @@ -14,6 +14,8 @@ import java.awt.*; import java.util.ArrayList; import java.util.Random; +import org.lwjgl.glfw.GLFW; + /** * Class created by MrDev023 (Florian RICHER) on 14/01/2017 */ @@ -38,7 +40,7 @@ public class MainGame extends Game{ t.getTransform().scale(10,10,0); tiles.add(t); - player1 = new Player(-100, 0); + player1 = new Player(200, 150); tiles.add(player1.getTile()); rand = new Random(); @@ -63,10 +65,39 @@ 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(); + + float xDep = 0, yDep = 0; + if(Input.isKey(GLFW.GLFW_KEY_W)){ + yDep = 10; + } + if(Input.isKey(GLFW.GLFW_KEY_S)){ + yDep = -10; + } + if(Input.isKey(GLFW.GLFW_KEY_A)){ + xDep = -10; + } + if(Input.isKey(GLFW.GLFW_KEY_D)){ + xDep = 10; + } + + 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_SPACE)){ + player1.rotate(-5); + } + if(Input.isKey(GLFW.GLFW_KEY_LEFT_ALT)){ + player1.rotate(5); + } + + System.out.println(player1); + for(GUI g : guis)g.update(); - + } @Override diff --git a/src/globalgamejam/game/Player.java b/src/globalgamejam/game/Player.java index 19332e3..fe8c093 100644 --- a/src/globalgamejam/game/Player.java +++ b/src/globalgamejam/game/Player.java @@ -20,7 +20,7 @@ public class Player extends PhysicalEntity { public Player(float x, float y){ super(x, y, 100, 0, 0, 10); - this.tile = new PlayerTile("res/textures/default.png", -250, 0); + 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); @@ -30,6 +30,14 @@ public class Player extends PhysicalEntity { return this.tile; } + public void move(float x, float y){ + this.addPosition(x, y); + this.tile.setPosition(new Vector2f(this.x, this.y)); + this.tile.applyTransform(); + + this.brosse.addPosition(x, y); + } + public void rotate(float angleRotation){ this.angle += angleRotation; this.angle %= 360; @@ -38,6 +46,7 @@ public class Player extends PhysicalEntity { } this.tile.setRotation(this.angle); + this.tile.applyTransform(); float angleRad = (float)(this.angle * (Math.PI / 180)); @@ -51,6 +60,11 @@ public class Player extends PhysicalEntity { return this.brosse.collideWithSquareHitBox(entity); } + @Override + public String toString(){ + return this.brosse.toString(); + } + private class PlayerTile extends Tile { public PlayerTile(String texturePath, float x, float y){ @@ -58,16 +72,11 @@ public class Player extends PhysicalEntity { this.setTexture(Texture.loadTexture(texturePath)); - this.setPosition(x, y); + this.setPosition(new Vector2f(x, y)); - this.setScale(new Vector2f(50, 50)); + this.setScale(new Vector2f(this.getTexture().width, this.getTexture().height)); 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 index abfd803..87d8b54 100644 --- a/src/globalgamejam/physics/PhysicalEntity.java +++ b/src/globalgamejam/physics/PhysicalEntity.java @@ -67,4 +67,14 @@ public class PhysicalEntity { this.x = x; this.y = y; } + + public void addPosition(float x, float y){ + this.x += x; + this.y += y; + } + + @Override + public String toString(){ + return this.x + " " + this.y; + } } diff --git a/src/globalgamejam/tiles/Tile.java b/src/globalgamejam/tiles/Tile.java index dbd6e63..6121961 100644 --- a/src/globalgamejam/tiles/Tile.java +++ b/src/globalgamejam/tiles/Tile.java @@ -33,10 +33,10 @@ public abstract class Tile { this.color = Color4f.WHITE; this.vbo = GL15.glGenBuffers(); float[] a = new float[]{ - -.5f,-.5f, 0.0f,0.0f, - .5f,-.5f, 1.0f,0.0f, - .5f,.5f, 1.0f,1.0f, - -.5f,.5f, 0.0f,1.0f + -.5f,-.5f, 0.0f,1.0f, + .5f,-.5f, 1.0f,1.0f, + .5f,.5f, 1.0f,0.0f, + -.5f,.5f, 0.0f,0.0f }; FloatBuffer buffer = BufferUtils.createFloatBuffer(a.length); buffer.put(a).flip();