merge
This commit is contained in:
parent
89c691beca
commit
4dbd9699c8
5 changed files with 66 additions and 16 deletions
BIN
res/textures/perso.png
Normal file
BIN
res/textures/perso.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 KiB |
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Reference in a new issue