From 4ae8175fda6058db4cf85b1cb02c76c95c5d5431 Mon Sep 17 00:00:00 2001 From: MrDev023 Date: Sat, 21 Jan 2017 00:01:42 +0100 Subject: [PATCH 1/3] Add score player --- .idea/workspace.xml | 338 ++++++++---------- src/globalgamejam/game/MainGame.java | 67 +--- src/globalgamejam/gui/GUI.java | 1 + src/globalgamejam/gui/GUILabel.java | 13 +- .../gui/interfaces/MainInterfaces.java | 53 +++ src/globalgamejam/render/Texture.java | 3 +- src/globalgamejam/world/MainWorld.java | 38 ++ 7 files changed, 267 insertions(+), 246 deletions(-) create mode 100644 src/globalgamejam/gui/interfaces/MainInterfaces.java create mode 100644 src/globalgamejam/world/MainWorld.java diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 7273826..973e7bc 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,6 +2,12 @@ + + + + + + @@ -18,30 +24,20 @@ - - - - - - - - - - - - - - + + + - - - - - + + + + + + @@ -50,8 +46,8 @@ - - + + @@ -63,7 +59,7 @@ - + @@ -71,20 +67,49 @@ - + - - + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -93,19 +118,19 @@ - - + + - - - - - - - - - - + + + + + + + + + + @@ -115,17 +140,7 @@ - - - - - - - - - - - + @@ -135,7 +150,7 @@ - + @@ -145,7 +160,7 @@ - + @@ -209,11 +224,13 @@ @@ -286,7 +303,7 @@ - - - - - - - - - - - - - - - - @@ -1051,7 +990,7 @@ - + @@ -1069,7 +1008,7 @@ - + @@ -1077,7 +1016,7 @@ - + @@ -1085,7 +1024,7 @@ - + @@ -1093,7 +1032,7 @@ - + @@ -1102,61 +1041,88 @@ - - + + - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + - - + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/globalgamejam/game/MainGame.java b/src/globalgamejam/game/MainGame.java index d33db98..c098ade 100644 --- a/src/globalgamejam/game/MainGame.java +++ b/src/globalgamejam/game/MainGame.java @@ -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.gui.interfaces.MainInterfaces; + +import globalgamejam.world.MainWorld; -import java.awt.*; -import java.util.ArrayList; import java.util.Random; /** @@ -19,71 +11,42 @@ import java.util.Random; */ public class MainGame extends Game{ - private ArrayList tiles; - + private MainWorld world; + private MainInterfaces interfaces; + public int[] scores; private Random rand; private Player player1; - private ArrayList guis; - private GUILabel label; - - @Override public void init() { - tiles = new ArrayList(); - guis = 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(); - 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(); - // player1.setPosition((rand.nextFloat() - 0.5f) * 200f, (rand.nextFloat() - 0.5f) * 150f); - // player1.applyTransform(); - 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(); } } diff --git a/src/globalgamejam/gui/GUI.java b/src/globalgamejam/gui/GUI.java index 69d0ba9..f1b7a00 100644 --- a/src/globalgamejam/gui/GUI.java +++ b/src/globalgamejam/gui/GUI.java @@ -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){ diff --git a/src/globalgamejam/gui/GUILabel.java b/src/globalgamejam/gui/GUILabel.java index 3b8f68c..7cd7c0f 100644 --- a/src/globalgamejam/gui/GUILabel.java +++ b/src/globalgamejam/gui/GUILabel.java @@ -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(){ diff --git a/src/globalgamejam/gui/interfaces/MainInterfaces.java b/src/globalgamejam/gui/interfaces/MainInterfaces.java new file mode 100644 index 0000000..dd9fa33 --- /dev/null +++ b/src/globalgamejam/gui/interfaces/MainInterfaces.java @@ -0,0 +1,53 @@ +package globalgamejam.gui.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 guis; + + private GUILabel p1,p2; + + + public MainInterfaces(MainGame game){ + this.game = game; + guis = new ArrayList(); + 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(); + } + +} diff --git a/src/globalgamejam/render/Texture.java b/src/globalgamejam/render/Texture.java index 18c8e7f..90cbe19 100644 --- a/src/globalgamejam/render/Texture.java +++ b/src/globalgamejam/render/Texture.java @@ -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) { diff --git a/src/globalgamejam/world/MainWorld.java b/src/globalgamejam/world/MainWorld.java new file mode 100644 index 0000000..8e74fb1 --- /dev/null +++ b/src/globalgamejam/world/MainWorld.java @@ -0,0 +1,38 @@ +package globalgamejam.world; + +import globalgamejam.game.MainGame; +import globalgamejam.tiles.Tile; + +import java.util.ArrayList; + +/** + * Created by trexr on 20/01/2017. + */ +public class MainWorld { + + private ArrayList tiles; + + private MainGame game; + + public MainWorld(MainGame game){ + this.game = game; + tiles = new ArrayList(); + init(); + } + + public void init(){ + } + + public void update(){ + + } + + public void render(){ + for(Tile t : tiles)t.render(); + } + + public void destroy(){ + tiles.clear(); + } + +} From 94a28400578a8f34c5d9a5187d16f89d5655a7a0 Mon Sep 17 00:00:00 2001 From: MrDev023 Date: Sat, 21 Jan 2017 00:20:29 +0100 Subject: [PATCH 2/3] Refactor --- .idea/workspace.xml | 269 +++++++----------- src/globalgamejam/game/MainGame.java | 2 +- .../{gui => }/interfaces/MainInterfaces.java | 2 +- 3 files changed, 111 insertions(+), 162 deletions(-) rename src/globalgamejam/{gui => }/interfaces/MainInterfaces.java (96%) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 973e7bc..05cd510 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,13 +2,8 @@ - - - + - - - - + @@ -663,7 +666,7 @@ - + @@ -694,21 +697,6 @@ - - - - - - - - - - - - - - - @@ -733,7 +721,6 @@ - @@ -751,9 +738,6 @@ - - - @@ -761,7 +745,6 @@ - @@ -777,21 +760,6 @@ - - - - - - - - - - - - - - - @@ -799,7 +767,9 @@ - + + + @@ -812,7 +782,6 @@ - @@ -834,7 +803,6 @@ - @@ -886,21 +854,6 @@ - - - - - - - - - - - - - - - @@ -940,7 +893,6 @@ - @@ -948,7 +900,6 @@ - @@ -956,10 +907,6 @@ - - - - @@ -967,7 +914,6 @@ - @@ -975,18 +921,10 @@ - - - - - - - - - + @@ -1001,7 +939,6 @@ - @@ -1031,8 +968,8 @@ - - + + @@ -1041,7 +978,7 @@ - + @@ -1058,27 +995,29 @@ - - - - - - - - - - - - + + + + + + + + + + + + + + @@ -1091,10 +1030,10 @@ - - - - + + + + @@ -1113,16 +1052,26 @@ - + - - + + + + + + + + + + + + + + + + - - - - diff --git a/src/globalgamejam/game/MainGame.java b/src/globalgamejam/game/MainGame.java index c098ade..09a6262 100644 --- a/src/globalgamejam/game/MainGame.java +++ b/src/globalgamejam/game/MainGame.java @@ -1,6 +1,6 @@ package globalgamejam.game; -import globalgamejam.gui.interfaces.MainInterfaces; +import globalgamejam.interfaces.MainInterfaces; import globalgamejam.world.MainWorld; diff --git a/src/globalgamejam/gui/interfaces/MainInterfaces.java b/src/globalgamejam/interfaces/MainInterfaces.java similarity index 96% rename from src/globalgamejam/gui/interfaces/MainInterfaces.java rename to src/globalgamejam/interfaces/MainInterfaces.java index dd9fa33..cf86231 100644 --- a/src/globalgamejam/gui/interfaces/MainInterfaces.java +++ b/src/globalgamejam/interfaces/MainInterfaces.java @@ -1,4 +1,4 @@ -package globalgamejam.gui.interfaces; +package globalgamejam.interfaces; import globalgamejam.Main; import globalgamejam.game.MainGame; From 4dbd9699c80863236180e40ec0d18151e04adc78 Mon Sep 17 00:00:00 2001 From: Fiesta87 Date: Sat, 21 Jan 2017 01:23:38 +0100 Subject: [PATCH 3/3] merge --- res/textures/perso.png | Bin 0 -> 2368 bytes src/globalgamejam/game/MainGame.java | 39 ++++++++++++++++-- src/globalgamejam/game/Player.java | 25 +++++++---- src/globalgamejam/physics/PhysicalEntity.java | 10 +++++ src/globalgamejam/tiles/Tile.java | 8 ++-- 5 files changed, 66 insertions(+), 16 deletions(-) create mode 100644 res/textures/perso.png diff --git a/res/textures/perso.png b/res/textures/perso.png new file mode 100644 index 0000000000000000000000000000000000000000..052aac0b8fb217b84dedab18b10a618884ea98e4 GIT binary patch literal 2368 zcmcIm`9BkmAD-MaF{BtWcPxAyMOn<)rZ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