From 8b4538da3952fd6ea800a98a3fe3ae4a2b5d42f1 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Sat, 6 Jun 2020 14:40:22 +0200 Subject: [PATCH] add square to selected character --- core/assets/square.png | Bin 0 -> 913 bytes .../src/netwerkprog/game/client/MainGame.java | 21 +++++++++- .../netwerkprog/game/client/game/Game.java | 15 ------- .../game/client/game/Graphics.java | 14 ------- .../client/game/map/GameInputProcessor.java | 7 +++- .../game/client/game/map/MapRenderer.java | 12 +++++- .../game/util/graphics/TextRenderer.java | 38 ++++++++++++++++++ 7 files changed, 75 insertions(+), 32 deletions(-) create mode 100644 core/assets/square.png delete mode 100644 core/src/netwerkprog/game/client/game/Game.java delete mode 100644 core/src/netwerkprog/game/client/game/Graphics.java create mode 100644 core/src/netwerkprog/game/util/graphics/TextRenderer.java diff --git a/core/assets/square.png b/core/assets/square.png new file mode 100644 index 0000000000000000000000000000000000000000..3b1e50f9add9186437928d2f422574a610776e5f GIT binary patch literal 913 zcmV;C18)3@P) zaB^>EX>4U6ba`-PAZ2)IW&i+q+U=J?lH@21MfaRyj({YD#Bnf~h`B)@e?FLUR%TUq zM0d=h7iq#amcC_0-P9zC^Sr!udK6l~nz9jGNz2q*|ZI|a%gqXKO ze#z0clfKyH4#Q6~qDSPX7p8ZJFS#3|`xxi7x|%XFmBU`t$5K`gjt5dHYgk4zoQl4! zR?r+vY#`P_^FV8X3Nf-hC{d?MgU)qt)G)=wCmZg}jb+(fj0-op5TMaulOjEcgHr=F zftl~Q(284Dyhe`5o#4p?F~W#1EqrJElXeS@F-w;y`kgDxi)T$^8k5|-!V5rX?40V# z?`q*w-Na8|1q5}a*|ESHk4xfEdeoLI&H_J;Da31Qko7Hq6d|@^GN|H2F_S1|ipFe2 z$fJW##mrd}A0R-g+$jvOLG=TU^Nfu#M$4C#FEc(Z0HN3-1~f$~V5Ov}A4`rJsw$d- zs%ABHEn2hWlr`sUd48j+i6v9ZX69C`x_EN+?B?#pYvCgJglWmeLh({ctq58nT`{`C zqt=5DIntp=KJ4(L9JQf*T58&Iv*xX|+PO=|_V2k{=-x}OC!HvzGo5N7QZA@^%)w5d&EY5CcM8q8)N5;Q+2I+=kOCjxPs1W?dCnMJ3R zc#@mUVqt6wWl$rXa5_z5Aec^K9dxsMkozUKpy{``@z2PGiSGX(7bdz*?kl%%sP(#j zQDgy{yKv?-%D{)MACt1`H$%gbJ7f0000mNkl+|T2n3*Wfec~)PA-NYNI+$Ka_Hrl nfPjF2fPjF2fPjF2fPlaUFXsWTKSm>y00000NkvXXu0mjf9}1m; literal 0 HcmV?d00001 diff --git a/core/src/netwerkprog/game/client/MainGame.java b/core/src/netwerkprog/game/client/MainGame.java index 65e9ced..c06fdf6 100644 --- a/core/src/netwerkprog/game/client/MainGame.java +++ b/core/src/netwerkprog/game/client/MainGame.java @@ -7,6 +7,8 @@ import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.TextureRegion; @@ -18,6 +20,7 @@ import netwerkprog.game.client.game.map.MapRenderer; import netwerkprog.game.client.game.map.GameInputProcessor; import netwerkprog.game.util.game.GameCharacter; import netwerkprog.game.util.graphics.FrameRate; +import netwerkprog.game.util.graphics.TextRenderer; public class MainGame extends ApplicationAdapter { SpriteBatch batch; @@ -29,6 +32,10 @@ public class MainGame extends ApplicationAdapter { private GameInputProcessor gameInputProcessor; private GameCharacter selectedCharacter; private Team team; + private Team enemyTeam; + private TextRenderer textRenderer; + private BitmapFont font; + private Map map; public MapRenderer mapRenderer; @@ -55,6 +62,8 @@ public class MainGame extends ApplicationAdapter { screenHeight = Gdx.graphics.getHeight(); frameRate = new FrameRate(); camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + textRenderer = new TextRenderer(); + font = new BitmapFont(); String[] strings = new String[]{ @@ -80,6 +89,7 @@ public class MainGame extends ApplicationAdapter { camera.viewportWidth = screenWidth / 2; camera.viewportHeight = screenHeight / 2; camera.update(); + initCharacters(); // this.tree.insert(new Hacker(,new BodySwap())); @@ -93,7 +103,7 @@ public class MainGame extends ApplicationAdapter { private void initCharacters() { Texture texture = new Texture(Gdx.files.internal("core/assets/characters.png")); TextureRegion[][] characters = TextureRegion.split(texture, 32, 32); - this.testCharacter = new Hacker("harry",characters[1][0], new BodySwap("test")); + this.testCharacter = new Hacker("harryyyyyyyyyy",characters[1][0], new BodySwap("test")); GameCharacter character2 = new Hacker("test2",characters[2][0], new BodySwap("test")); this.setSelectedCharacter(testCharacter); mapRenderer.getGameTiles()[1][1].visit(testCharacter); @@ -135,6 +145,13 @@ public class MainGame extends ApplicationAdapter { Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); mapRenderer.render(); frameRate.render(); + renderText(); + + } + + private void renderText() { + String text = "Selected character: " + selectedCharacter.getName(); + textRenderer.render(text,Gdx.graphics.getWidth() - text.length() * 6.5f,Gdx.graphics.getHeight() - 3); } /** @@ -153,6 +170,7 @@ public class MainGame extends ApplicationAdapter { screenWidth = width; frameRate.resize(width, height); mapRenderer.resize(width, height); + textRenderer.resize(width,height); } @Override @@ -163,6 +181,7 @@ public class MainGame extends ApplicationAdapter { @Override public void dispose() { batch.dispose(); + textRenderer.dispose(); } public float getScreenWidth() { diff --git a/core/src/netwerkprog/game/client/game/Game.java b/core/src/netwerkprog/game/client/game/Game.java deleted file mode 100644 index ddfdc1d..0000000 --- a/core/src/netwerkprog/game/client/game/Game.java +++ /dev/null @@ -1,15 +0,0 @@ -package netwerkprog.game.client.game; - -import netwerkprog.game.util.application.Controller; - -public class Game extends Controller { - - - public Game() { - } - - @Override - public void run() { - - } -} diff --git a/core/src/netwerkprog/game/client/game/Graphics.java b/core/src/netwerkprog/game/client/game/Graphics.java deleted file mode 100644 index 29747f0..0000000 --- a/core/src/netwerkprog/game/client/game/Graphics.java +++ /dev/null @@ -1,14 +0,0 @@ -package netwerkprog.game.client.game; - -import netwerkprog.game.util.application.Controller; - -public class Graphics extends Controller { - public Graphics() { - - } - - @Override - public void run() { - - } -} diff --git a/core/src/netwerkprog/game/client/game/map/GameInputProcessor.java b/core/src/netwerkprog/game/client/game/map/GameInputProcessor.java index 07ddc6c..9f9aa21 100644 --- a/core/src/netwerkprog/game/client/game/map/GameInputProcessor.java +++ b/core/src/netwerkprog/game/client/game/map/GameInputProcessor.java @@ -108,6 +108,10 @@ public class GameInputProcessor implements InputProcessor { } return true; + } else { + if (keycode == Input.Keys.ENTER) { + + } } return false; } @@ -132,7 +136,8 @@ public class GameInputProcessor implements InputProcessor { if (mainGame.hasCharacterSelected() && !gameTile.containsCharacter()) { // System.out.println(mainGame.getSelectedCharacter()); removeCharacterFromTile(mainGame.getSelectedCharacter()); - gameTile.visit(mainGame.getSelectedCharacter()); + if (gameTile.getSymbol() != '#') + gameTile.visit(mainGame.getSelectedCharacter()); } if (!mainGame.hasCharacterSelected() && gameTile.containsCharacter()) { mainGame.setSelectedCharacter(gameTile.getCharacter()); diff --git a/core/src/netwerkprog/game/client/game/map/MapRenderer.java b/core/src/netwerkprog/game/client/game/map/MapRenderer.java index 5baa40d..060e05f 100644 --- a/core/src/netwerkprog/game/client/game/map/MapRenderer.java +++ b/core/src/netwerkprog/game/client/game/map/MapRenderer.java @@ -3,7 +3,9 @@ package netwerkprog.game.client.game.map; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.BitmapFont; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import netwerkprog.game.client.MainGame; import netwerkprog.game.util.graphics.Renderable; import com.badlogic.gdx.graphics.g2d.TextureRegion; @@ -17,8 +19,12 @@ public class MapRenderer implements Renderable { private OrthographicCamera cam; private static int x = 0; private static int y = 0; + private BitmapFont font; + + private ShapeRenderer shapeRenderer; private MainGame mainGame; + private Texture square; public static TextureRegion FLOOR_TILE; @@ -43,6 +49,8 @@ public class MapRenderer implements Renderable { cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); this.camera = camera; this.mainGame = MainGame.getInstance(); + font = new BitmapFont(); + square = new Texture(Gdx.files.internal("square.png")); makeTiles(); } @@ -100,9 +108,11 @@ public class MapRenderer implements Renderable { for (int col = 0; col < gameTiles[0].length; col++) { GameTile cur = gameTileRow[col]; batch.draw(cur.getTextureRegion(), cur.x, cur.y); + if (cur.containsCharacter()) { batch.draw(cur.getCharacter().getTextureRegion(), cur.x, cur.y); -// System.out.println("drawing character at " + cur.x + " " + cur.y); + if (cur.getCharacter().equals(mainGame.getSelectedCharacter())) + batch.draw(square, cur.x, cur.y); } } } diff --git a/core/src/netwerkprog/game/util/graphics/TextRenderer.java b/core/src/netwerkprog/game/util/graphics/TextRenderer.java new file mode 100644 index 0000000..bfb6d19 --- /dev/null +++ b/core/src/netwerkprog/game/util/graphics/TextRenderer.java @@ -0,0 +1,38 @@ +package netwerkprog.game.util.graphics; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.g2d.BitmapFont; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.utils.Disposable; + +public class TextRenderer implements Disposable { + private BitmapFont font; + private SpriteBatch batch; + private OrthographicCamera cam; + + public TextRenderer() { + font = new BitmapFont(); + batch = new SpriteBatch(); + cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + + } + @Override + public void dispose() { + font.dispose(); + batch.dispose(); + } + + public void resize(int screenWidth, int screenHeight) { + cam = new OrthographicCamera(screenWidth, screenHeight); + cam.translate(screenWidth / 2, screenHeight / 2); + cam.update(); + batch.setProjectionMatrix(cam.combined); + } + + public void render(String text, float x, float y) { + batch.begin(); + font.draw(batch, text, x, y); + batch.end(); + } +}