1
0
Fork 0
This commit is contained in:
Fiesta87 2017-01-21 01:36:14 +01:00
commit 5d218a3a79
7 changed files with 360 additions and 384 deletions

View file

@ -1,17 +1,9 @@
package globalgamejam.game;
import globalgamejam.math.Vector2f;
import globalgamejam.gui.ActionGUI;
import globalgamejam.gui.GUI;
import globalgamejam.gui.GUILabel;
import globalgamejam.gui.IActionGUI;
import globalgamejam.input.Input;
import globalgamejam.render.*;
import globalgamejam.tiles.TestTile;
import globalgamejam.tiles.Tile;
import globalgamejam.interfaces.MainInterfaces;
import globalgamejam.world.MainWorld;
import java.awt.*;
import java.util.ArrayList;
import java.util.Random;
import org.lwjgl.glfw.GLFW;
@ -21,100 +13,41 @@ import org.lwjgl.glfw.GLFW;
*/
public class MainGame extends Game{
private ArrayList<Tile> tiles;
private MainWorld world;
private MainInterfaces interfaces;
public int[] scores;
private Random rand;
private Player player1;
private ArrayList<GUI> guis;
private GUILabel label;
@Override
public void init() {
tiles = new ArrayList<Tile>();
guis = new ArrayList<GUI>();
TestTile t = new TestTile();
t.getTransform().translate(100,100,0);
t.getTransform().scale(10,10,0);
tiles.add(t);
player1 = new Player(200, 150);
tiles.add(player1.getTile());
rand = new Random();
label = new GUILabel("Test");
label.setX(10);
label.setY(10);
label.setAction(new ActionGUI() {
@Override
public void enter(float mouseX, float mouseY) {
label.setColor(Color.RED);
}
@Override
public void leave(float mouseX, float mouseY) {
label.setColor(Color.WHITE);
}
});
guis.add(label);
this.scores = new int[2];
world = new MainWorld(this);
interfaces = new MainInterfaces(this);
}
@Override
public void update() {
Camera.transform();
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();
interfaces.update();
world.update();
}
@Override
public void render2D() {
for(Tile t : tiles)t.render();
world.render();
}
@Override
public void renderGUI() {
for(GUI g : guis)g.render();
interfaces.render();
}
@Override
public void destroy() {
tiles.clear();
guis.clear();
interfaces.destroy();
world.destroy();
}
}

View file

@ -18,6 +18,7 @@ public abstract class GUI {
this.y = y;
this.width = 0;
this.height = 0;
this.action = new ActionGUI();
}
public void setAction(IActionGUI action){

View file

@ -54,9 +54,9 @@ public class GUILabel extends GUI {
this.vbo = GL15.glGenBuffers();
float[] a = new float[]{
0,0, 0.0f,0.0f,
this.texture.width,0, 1.0f,0.0f,
this.texture.width,this.texture.height, 1.0f,1.0f,
0,this.texture.height, 0.0f,1.0f
1,0, 1.0f,0.0f,
1,1, 1.0f,1.0f,
0,1, 0.0f,1.0f
};
FloatBuffer buff = BufferUtils.createFloatBuffer(a.length);
buff.put(a).flip();
@ -72,6 +72,7 @@ public class GUILabel extends GUI {
Shaders.MAIN_SHADERS.uniform("camera", Camera.matrix);
Matrix4f transform = new Matrix4f();
transform.translate(super.x,super.y,0);
transform.scale(this.getWitdh(),this.getHeight(),1);
Shaders.MAIN_SHADERS.uniform("transform", transform);
Shaders.MAIN_SHADERS.uniform("projection", DisplayManager.projection);
Shaders.MAIN_SHADERS.uniform("color", Color4f.WHITE);
@ -142,8 +143,6 @@ public class GUILabel extends GUI {
this.texture = Texture.loadFont(text,color,font,size);
}
/**
* Return the x coordonnate of the Label (upper left corner)
* @return x (float) : the x coordonnate of the Label
@ -191,7 +190,7 @@ public class GUILabel extends GUI {
* @return witdh (int) : the width
*/
public int getWitdh() {
return super.width;
return this.texture.width;
}
/**
@ -199,7 +198,7 @@ public class GUILabel extends GUI {
* @return height (int) : the height
*/
public int getHeight() {
return super.height;
return this.texture.height;
}
public void destroy(){

View file

@ -0,0 +1,53 @@
package globalgamejam.interfaces;
import globalgamejam.Main;
import globalgamejam.game.MainGame;
import globalgamejam.gui.GUI;
import globalgamejam.gui.GUILabel;
import java.awt.*;
import java.util.ArrayList;
/**
* Created by trexr on 20/01/2017.
*/
public class MainInterfaces {
private final int SIZE_OF_DETAILS = 100;
private MainGame game;
private ArrayList<GUI> guis;
private GUILabel p1,p2;
public MainInterfaces(MainGame game){
this.game = game;
guis = new ArrayList<GUI>();
init();
}
public void init(){
p1 = new GUILabel("Player 1 : ", Main.WIDTH/4 - 50,10, Color.WHITE,"Arial",16);
p2 = new GUILabel("Player 2 : ", Main.WIDTH/4 * 3 - 50,10, Color.WHITE,"Arial",16);
guis.add(p1);
guis.add(p2);
}
public void update(){
p1.setText("Player 1 : " + this.game.scores[0]);
p1.setX((Main.WIDTH-SIZE_OF_DETAILS)/4 - p1.getWitdh()/2);
p2.setText("Player 2 : " + this.game.scores[1]);
p2.setX((Main.WIDTH-SIZE_OF_DETAILS)/4*3 - p2.getWitdh()/2);
for(GUI g : guis)g.update();
}
public void render(){
for(GUI g : guis)g.render();
}
public void destroy(){
guis.clear();
}
}

View file

@ -82,7 +82,6 @@ public class Texture {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
glBindTexture(GL_TEXTURE_2D, 0);
System.out.println("Texture loaded ! " + width + "x" + height + " id:" + textureID);
return new Texture(image.getWidth(),image.getHeight(),textureID);
}
@ -122,6 +121,8 @@ public class Texture {
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
glBindTexture(GL_TEXTURE_2D, 0);
System.out.println("Texture loaded ! " + width + "x" + height + " id:" + id);
return new Texture(width, height, id);
} catch (IOException e) {

View file

@ -0,0 +1,74 @@
package globalgamejam.world;
import globalgamejam.game.MainGame;
import globalgamejam.game.Player;
import globalgamejam.input.Input;
import globalgamejam.tiles.Tile;
import java.util.ArrayList;
import org.lwjgl.glfw.GLFW;
/**
* Created by trexr on 20/01/2017.
*/
public class MainWorld {
private ArrayList<Tile> tiles;
private MainGame game;
private Player player1;
public MainWorld(MainGame game){
this.game = game;
tiles = new ArrayList<Tile>();
init();
}
public void init(){
player1 = new Player(200, 150);
tiles.add(player1.getTile());
}
public void update(){
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);
}
public void render(){
for(Tile t : tiles)t.render();
}
public void destroy(){
tiles.clear();
}
}