From 8668bc201799181c736bbe6bc288996ac40278a9 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Mon, 25 May 2020 19:36:19 +0200 Subject: [PATCH 1/6] add inputProcesser --- core/src/netwerkprog/game/client/MainGame.java | 4 +++- .../game/util/application/InputTransform.java | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 core/src/netwerkprog/game/util/application/InputTransform.java diff --git a/core/src/netwerkprog/game/client/MainGame.java b/core/src/netwerkprog/game/client/MainGame.java index 0f280b8..16a53ad 100644 --- a/core/src/netwerkprog/game/client/MainGame.java +++ b/core/src/netwerkprog/game/client/MainGame.java @@ -17,7 +17,7 @@ import netwerkprog.game.client.game.map.MapRenderer; import netwerkprog.game.client.map.GameInputProcessor; import netwerkprog.game.util.graphics.FrameRate; -public class MainGame extends ApplicationAdapter { +public class MainGame extends ApplicationAdapter{ SpriteBatch batch; float screenWidth; float screenHeight; @@ -148,4 +148,6 @@ public class MainGame extends ApplicationAdapter { public int getHorizontalTileAmount() { return map.getWidth(); } + + } diff --git a/core/src/netwerkprog/game/util/application/InputTransform.java b/core/src/netwerkprog/game/util/application/InputTransform.java new file mode 100644 index 0000000..1faad11 --- /dev/null +++ b/core/src/netwerkprog/game/util/application/InputTransform.java @@ -0,0 +1,12 @@ +package netwerkprog.game.util.application; + +public class InputTransform { + + public static float getCursorToModelX(int screenwidth, int screenX, int cursorX) { + return (((float) cursorX) * screenwidth) / ((float) screenX); + } + + public static float getCursorToModelY(int screenHeight, int screenY, int cursorY) { + return ((float) (screenY - cursorY)) * screenHeight / ((float) screenY); + } +} \ No newline at end of file -- 2.47.2 From bdcdff4c17d318ab7a06d7bc9c1569d3ba0b9cf8 Mon Sep 17 00:00:00 2001 From: MickWerf Date: Mon, 25 May 2020 19:48:29 +0200 Subject: [PATCH 2/6] Split and personalized client code to fit our program. Added comments to client code. --- core/src/netwerkprog/game/client/Client.java | 92 +++++++++++-------- .../game/util/data/DataParser.java | 4 + 2 files changed, 59 insertions(+), 37 deletions(-) diff --git a/core/src/netwerkprog/game/client/Client.java b/core/src/netwerkprog/game/client/Client.java index 907c6fe..1a54dec 100644 --- a/core/src/netwerkprog/game/client/Client.java +++ b/core/src/netwerkprog/game/client/Client.java @@ -9,15 +9,15 @@ import java.io.DataOutputStream; import java.io.IOException; import java.net.Socket; import java.util.Arrays; -import java.util.Scanner; public class Client extends Controller { - private int port; - private String hostname; - private DataParser parser; + private final int port; + private final String hostname; + private final DataParser parser; private boolean isConnected = true; - - + private Socket socket; + private Thread receiveThread; + private DataOutputStream outputStream; public Client(String hostname) { this.port = Data.port(); @@ -25,41 +25,26 @@ public class Client extends Controller { this.parser = new DataParser(); } + /** + * Starts the client process. + */ @Override public void run() { this.connect(); + this.receiveThread.start(); } + /** + * Connects the client to the server. + */ public void connect() { - System.out.println("[CLIENT] connecting to server on port " + port); - Scanner scanner = new Scanner(System.in); + System.out.println("[CLIENT] connecting to server on port " + this.port); try { - Socket socket = new Socket(hostname,port); + this.socket = new Socket(this.hostname, this.port); DataInputStream in = new DataInputStream(socket.getInputStream()); - DataOutputStream out = new DataOutputStream(socket.getOutputStream()); + this.outputStream = new DataOutputStream(socket.getOutputStream()); - Thread readSocketThread = new Thread( () -> { - receiveDataFromSocket(in); - }); - - readSocketThread.start(); - - String input = ""; - - while (!input.equals("\\quit")) { - input = scanner.nextLine(); - out.writeUTF(input); - } - - isConnected = false; - - socket.close(); - - try { - readSocketThread.join(); - } catch (InterruptedException e) { - e.printStackTrace(); - } + this.receiveThread = new Thread( () -> receive(in)); } catch (IOException e) { System.out.println("[CLIENT] there was an error connecting : " + e.getMessage()); @@ -69,17 +54,50 @@ public class Client extends Controller { } } - private void receiveDataFromSocket(DataInputStream in) { - String received = ""; + /** + * Sends a message to the server. + * @param message The message to send. + */ + public void send(String message) { + try { + this.outputStream.writeUTF(message); + } catch (IOException e) { + e.printStackTrace(); + } + } + + /** + * Receives a message from the server. + * @param in The inputStream + */ + public void receive(DataInputStream in) { + Data data = null; while (isConnected) { try { - received = in.readUTF(); - + data = this.parser.parse(in.readUTF()); } catch (IOException e) { - System.out.println("exception caught - " + e.getMessage());; + e.printStackTrace(); + } + if (data != null) { + send(this.parser.parse(data)); } } } + public void disconnect() { + this.isConnected = false; + try { + this.receiveThread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + send("Disconnect"); + + try { + this.socket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } } diff --git a/core/src/netwerkprog/game/util/data/DataParser.java b/core/src/netwerkprog/game/util/data/DataParser.java index 938e4a6..487fad2 100644 --- a/core/src/netwerkprog/game/util/data/DataParser.java +++ b/core/src/netwerkprog/game/util/data/DataParser.java @@ -7,4 +7,8 @@ public class DataParser { public Data parse(String request) { return null; } + + public String parse(Data data) { + return null; + } } -- 2.47.2 From afeb7afa295a9436faada5ecffa84c9ec5dcdf7c Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Mon, 25 May 2020 19:52:46 +0200 Subject: [PATCH 3/6] stuff --- .../game/client/game/map/MapRenderer.java | 13 ++++++++++-- .../game/client/map/GameInputProcessor.java | 3 +++ .../src/netwerkprog/game/client/map/Tile.java | 20 +++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 core/src/netwerkprog/game/client/map/Tile.java diff --git a/core/src/netwerkprog/game/client/game/map/MapRenderer.java b/core/src/netwerkprog/game/client/game/map/MapRenderer.java index 37457e2..a5082d7 100644 --- a/core/src/netwerkprog/game/client/game/map/MapRenderer.java +++ b/core/src/netwerkprog/game/client/game/map/MapRenderer.java @@ -4,6 +4,7 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.maps.tiled.TiledMapTile; import netwerkprog.game.util.graphics.Renderable; import com.badlogic.gdx.graphics.g2d.TextureRegion; @@ -22,6 +23,8 @@ public class MapRenderer implements Renderable { public static TextureRegion WALL_TILE; public static TextureRegion PATH_TILE; + private TextureRegion[][] sprites; + public MapRenderer(Map map, int tileWidth, SpriteBatch batch, OrthographicCamera camera) { this.map = map; @@ -35,10 +38,12 @@ public class MapRenderer implements Renderable { private void makeTiles() { Texture texture = new Texture(Gdx.files.internal(tilePath)); TextureRegion[][] tiles = TextureRegion.split(texture, 32, 32); + FLOOR_TILE = tiles[1][6]; WALL_TILE = tiles[0][4]; PATH_TILE = tiles[4][6]; + this.sprites = new TextureRegion[map.getHeight()][map.getWidth()]; } public int getTileWidth() { @@ -69,8 +74,8 @@ public class MapRenderer implements Renderable { batch.draw(FLOOR_TILE, x, y); } else if (map.get(row, col) == '#') { batch.draw(WALL_TILE, x, y); - } else if (map.get(row,col) == 'x') { - batch.draw(PATH_TILE,x,y); + } else if (map.get(row, col) == 'x') { + batch.draw(PATH_TILE, x, y); } x += 32; } @@ -92,4 +97,8 @@ public class MapRenderer implements Renderable { cam.update(); batch.setProjectionMatrix(cam.combined); } + + public TextureRegion[][] getSprites() { + return sprites; + } } diff --git a/core/src/netwerkprog/game/client/map/GameInputProcessor.java b/core/src/netwerkprog/game/client/map/GameInputProcessor.java index ee33d38..ebd2fcf 100644 --- a/core/src/netwerkprog/game/client/map/GameInputProcessor.java +++ b/core/src/netwerkprog/game/client/map/GameInputProcessor.java @@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.utils.TimeUtils; import netwerkprog.game.client.MainGame; +import netwerkprog.game.util.application.InputTransform; import java.util.ArrayList; import java.util.Arrays; @@ -119,6 +120,8 @@ public class GameInputProcessor implements InputProcessor { @Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { + float pointerX = InputTransform.getCursorToModelX((int)game.getScreenWidth(), (int)game.getScreenWidth(),screenX); + float pointerY = InputTransform.getCursorToModelY((int)game.getScreenHeight(),(int)game.getScreenHeight(),screenY); return false; } diff --git a/core/src/netwerkprog/game/client/map/Tile.java b/core/src/netwerkprog/game/client/map/Tile.java new file mode 100644 index 0000000..1a5ed84 --- /dev/null +++ b/core/src/netwerkprog/game/client/map/Tile.java @@ -0,0 +1,20 @@ +package netwerkprog.game.client.map; + +import com.badlogic.gdx.graphics.g2d.TextureRegion; + +public class Tile { + private TextureRegion textureRegion; + private int xPos; + private int yPos; + + public Tile(TextureRegion textureRegion, int xPos, int yPos) { + this.textureRegion = textureRegion; + this.xPos = xPos; + this.yPos = yPos; + } + + public boolean contains(int x, int y) { + + return false; + } +} -- 2.47.2 From 6c85ae994913a8eb720af214e9a2fefb01814226 Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Mon, 25 May 2020 20:13:10 +0200 Subject: [PATCH 4/6] remade the map drawing with tile classes that have a position --- .../game/client/game/map/MapRenderer.java | 66 ++++++++++++------- .../src/netwerkprog/game/client/map/Tile.java | 16 ++--- 2 files changed, 52 insertions(+), 30 deletions(-) diff --git a/core/src/netwerkprog/game/client/game/map/MapRenderer.java b/core/src/netwerkprog/game/client/game/map/MapRenderer.java index a5082d7..d6ca77b 100644 --- a/core/src/netwerkprog/game/client/game/map/MapRenderer.java +++ b/core/src/netwerkprog/game/client/game/map/MapRenderer.java @@ -4,7 +4,7 @@ import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; -import com.badlogic.gdx.maps.tiled.TiledMapTile; +import netwerkprog.game.client.map.Tile; import netwerkprog.game.util.graphics.Renderable; import com.badlogic.gdx.graphics.g2d.TextureRegion; @@ -23,7 +23,9 @@ public class MapRenderer implements Renderable { public static TextureRegion WALL_TILE; public static TextureRegion PATH_TILE; - private TextureRegion[][] sprites; + private Tile[][] tiles; + + private boolean isStarted = false; public MapRenderer(Map map, int tileWidth, SpriteBatch batch, OrthographicCamera camera) { @@ -37,13 +39,28 @@ public class MapRenderer implements Renderable { private void makeTiles() { Texture texture = new Texture(Gdx.files.internal(tilePath)); - TextureRegion[][] tiles = TextureRegion.split(texture, 32, 32); + TextureRegion[][] tileTextures = TextureRegion.split(texture, 32, 32); - FLOOR_TILE = tiles[1][6]; - WALL_TILE = tiles[0][4]; - PATH_TILE = tiles[4][6]; + FLOOR_TILE = tileTextures[1][6]; + WALL_TILE = tileTextures[0][4]; + PATH_TILE = tileTextures[4][6]; - this.sprites = new TextureRegion[map.getHeight()][map.getWidth()]; + this.tiles = new Tile[map.getHeight()][map.getWidth()]; + + for (int row = map.getHeight(); row >= 0; row--) { + y += 32; + x = 0; + for (int col = 0; col < map.getWidth(); col++) { + if (map.get(row, col) == ' ') { + tiles[row][col] = new Tile(FLOOR_TILE,x,y); + } else if (map.get(row, col) == '#') { + tiles[row][col] = new Tile(WALL_TILE,x,y); + } else if (map.get(row, col) == 'x') { + tiles[row][col] = new Tile(PATH_TILE,x,y); + } + x += 32; + } + } } public int getTileWidth() { @@ -66,21 +83,26 @@ public class MapRenderer implements Renderable { public void render() { batch.begin(); batch.setProjectionMatrix(camera.combined); - for (int row = map.getHeight(); row >= 0; row--) { - y += 32; - x = 0; - for (int col = 0; col < map.getWidth(); col++) { - if (map.get(row, col) == ' ') { - batch.draw(FLOOR_TILE, x, y); - } else if (map.get(row, col) == '#') { - batch.draw(WALL_TILE, x, y); - } else if (map.get(row, col) == 'x') { - batch.draw(PATH_TILE, x, y); - } - x += 32; +// for (int row = map.getHeight(); row >= 0; row--) { +// y += 32; +// x = 0; +// for (int col = 0; col < map.getWidth(); col++) { +// if (map.get(row, col) == ' ') { +// batch.draw(FLOOR_TILE, x, y); +// } else if (map.get(row, col) == '#') { +// batch.draw(WALL_TILE, x, y); +// } else if (map.get(row, col) == 'x') { +// batch.draw(PATH_TILE, x, y); +// } +// x += 32; + // } +// } + for (int row = 0; row < tiles.length; row++) { + for (int col = 0; col < tiles[0].length; col++) { + Tile cur = tiles[row][col]; + batch.draw(cur.getTextureRegion(),cur.x,cur.y); } } -// batch.draw(FLOOR_TILE,100,100); batch.end(); x = 0; y = 0; @@ -98,7 +120,7 @@ public class MapRenderer implements Renderable { batch.setProjectionMatrix(cam.combined); } - public TextureRegion[][] getSprites() { - return sprites; + public Tile[][] getTiles() { + return tiles; } } diff --git a/core/src/netwerkprog/game/client/map/Tile.java b/core/src/netwerkprog/game/client/map/Tile.java index 1a5ed84..00c9a9f 100644 --- a/core/src/netwerkprog/game/client/map/Tile.java +++ b/core/src/netwerkprog/game/client/map/Tile.java @@ -1,20 +1,20 @@ package netwerkprog.game.client.map; import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.math.Rectangle; -public class Tile { +public class Tile extends Rectangle{ private TextureRegion textureRegion; - private int xPos; - private int yPos; public Tile(TextureRegion textureRegion, int xPos, int yPos) { this.textureRegion = textureRegion; - this.xPos = xPos; - this.yPos = yPos; + super.x = xPos; + super.y = yPos; + super.width = textureRegion.getRegionWidth(); + super.height = textureRegion.getRegionHeight(); } - public boolean contains(int x, int y) { - - return false; + public TextureRegion getTextureRegion() { + return textureRegion; } } -- 2.47.2 From 75f1c26349df17faf41dfe6728664b60a03f792a Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Mon, 25 May 2020 20:44:20 +0200 Subject: [PATCH 5/6] add ability to see which tile was selected when you click on it --- .../src/netwerkprog/game/client/MainGame.java | 2 +- .../game/client/game/map/MapRenderer.java | 28 ++++++------------- .../game/client/map/GameInputProcessor.java | 20 +++++++++++-- .../src/netwerkprog/game/client/map/Tile.java | 17 ++++++++++- 4 files changed, 42 insertions(+), 25 deletions(-) diff --git a/core/src/netwerkprog/game/client/MainGame.java b/core/src/netwerkprog/game/client/MainGame.java index 16a53ad..1a3396a 100644 --- a/core/src/netwerkprog/game/client/MainGame.java +++ b/core/src/netwerkprog/game/client/MainGame.java @@ -27,7 +27,7 @@ public class MainGame extends ApplicationAdapter{ private GameInputProcessor gameInputProcessor; private Map map; - private MapRenderer mapRenderer; + public MapRenderer mapRenderer; diff --git a/core/src/netwerkprog/game/client/game/map/MapRenderer.java b/core/src/netwerkprog/game/client/game/map/MapRenderer.java index d6ca77b..ff59fdc 100644 --- a/core/src/netwerkprog/game/client/game/map/MapRenderer.java +++ b/core/src/netwerkprog/game/client/game/map/MapRenderer.java @@ -52,11 +52,11 @@ public class MapRenderer implements Renderable { x = 0; for (int col = 0; col < map.getWidth(); col++) { if (map.get(row, col) == ' ') { - tiles[row][col] = new Tile(FLOOR_TILE,x,y); + tiles[row][col] = new Tile(FLOOR_TILE,x,y, ' '); } else if (map.get(row, col) == '#') { - tiles[row][col] = new Tile(WALL_TILE,x,y); + tiles[row][col] = new Tile(WALL_TILE,x,y, '#'); } else if (map.get(row, col) == 'x') { - tiles[row][col] = new Tile(PATH_TILE,x,y); + tiles[row][col] = new Tile(PATH_TILE,x,y, 'x'); } x += 32; } @@ -83,26 +83,14 @@ public class MapRenderer implements Renderable { public void render() { batch.begin(); batch.setProjectionMatrix(camera.combined); -// for (int row = map.getHeight(); row >= 0; row--) { -// y += 32; -// x = 0; -// for (int col = 0; col < map.getWidth(); col++) { -// if (map.get(row, col) == ' ') { -// batch.draw(FLOOR_TILE, x, y); -// } else if (map.get(row, col) == '#') { -// batch.draw(WALL_TILE, x, y); -// } else if (map.get(row, col) == 'x') { -// batch.draw(PATH_TILE, x, y); -// } -// x += 32; - // } -// } - for (int row = 0; row < tiles.length; row++) { + + for (Tile[] tileRow : tiles) { for (int col = 0; col < tiles[0].length; col++) { - Tile cur = tiles[row][col]; - batch.draw(cur.getTextureRegion(),cur.x,cur.y); + Tile cur = tileRow[col]; + batch.draw(cur.getTextureRegion(), cur.x, cur.y); } } + batch.end(); x = 0; y = 0; diff --git a/core/src/netwerkprog/game/client/map/GameInputProcessor.java b/core/src/netwerkprog/game/client/map/GameInputProcessor.java index ebd2fcf..0d69417 100644 --- a/core/src/netwerkprog/game/client/map/GameInputProcessor.java +++ b/core/src/netwerkprog/game/client/map/GameInputProcessor.java @@ -1,9 +1,11 @@ package netwerkprog.game.client.map; +import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Input; import com.badlogic.gdx.InputProcessor; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.math.MathUtils; +import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.utils.TimeUtils; import netwerkprog.game.client.MainGame; import netwerkprog.game.util.application.InputTransform; @@ -89,7 +91,7 @@ public class GameInputProcessor implements InputProcessor { @Override public boolean keyUp(int keycode) { - System.out.println(camera.position.x + " , " + camera.position.y); +// System.out.println(camera.position.x + " , " + camera.position.y); if (keysList.contains(keycode)) { if (keycode == keysList.get(0)) { this.isWPressed = false; @@ -120,8 +122,20 @@ public class GameInputProcessor implements InputProcessor { @Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { - float pointerX = InputTransform.getCursorToModelX((int)game.getScreenWidth(), (int)game.getScreenWidth(),screenX); - float pointerY = InputTransform.getCursorToModelY((int)game.getScreenHeight(),(int)game.getScreenHeight(),screenY); + + Vector3 touchPoint = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0); + camera.unproject(touchPoint); + + for (int row = 0; row < game.mapRenderer.getTiles().length; row++) { + for (int col = 0; col < game.mapRenderer.getTiles()[0].length; col++) { + Tile tile = game.mapRenderer.getTiles()[row][col]; + if (tile.contains(touchPoint.x,touchPoint.y)) { + System.out.println(tile + " row: " + row + ", col: " + col); + //TODO make stuff happen with the tile + return true; + } + } + } return false; } diff --git a/core/src/netwerkprog/game/client/map/Tile.java b/core/src/netwerkprog/game/client/map/Tile.java index 00c9a9f..2e2dbc3 100644 --- a/core/src/netwerkprog/game/client/map/Tile.java +++ b/core/src/netwerkprog/game/client/map/Tile.java @@ -5,9 +5,11 @@ import com.badlogic.gdx.math.Rectangle; public class Tile extends Rectangle{ private TextureRegion textureRegion; + private char symbol; - public Tile(TextureRegion textureRegion, int xPos, int yPos) { + public Tile(TextureRegion textureRegion, int xPos, int yPos, char symbol) { this.textureRegion = textureRegion; + this.symbol = symbol; super.x = xPos; super.y = yPos; super.width = textureRegion.getRegionWidth(); @@ -17,4 +19,17 @@ public class Tile extends Rectangle{ public TextureRegion getTextureRegion() { return textureRegion; } + + public char getSymbol() { + return symbol; + } + + @Override + public String toString() { + return "Tile{" + + "symbol=" + symbol + + ", x=" + x + + ", y=" + y + + '}'; + } } -- 2.47.2 From d4c6d76aea3d6eb3f0f56e250dd66cd17a28884e Mon Sep 17 00:00:00 2001 From: Sem van der Hoeven Date: Mon, 25 May 2020 20:55:02 +0200 Subject: [PATCH 6/6] removed inputtransform class, add comments and made smol fixes --- .../game/client/game/map/MapRenderer.java | 12 +++++++++++- .../game/client/map/GameInputProcessor.java | 15 +++++++-------- .../game/util/application/InputTransform.java | 12 ------------ 3 files changed, 18 insertions(+), 21 deletions(-) delete mode 100644 core/src/netwerkprog/game/util/application/InputTransform.java diff --git a/core/src/netwerkprog/game/client/game/map/MapRenderer.java b/core/src/netwerkprog/game/client/game/map/MapRenderer.java index ff59fdc..1693171 100644 --- a/core/src/netwerkprog/game/client/game/map/MapRenderer.java +++ b/core/src/netwerkprog/game/client/game/map/MapRenderer.java @@ -28,6 +28,13 @@ public class MapRenderer implements Renderable { private boolean isStarted = false; + /** + * makea a new mapRenderer object + * @param map the map object + * @param tileWidth the width of the tile + * @param batch the batch object so no new ones have to be made + * @param camera the camera object + */ public MapRenderer(Map map, int tileWidth, SpriteBatch batch, OrthographicCamera camera) { this.map = map; this.tileWidth = tileWidth; @@ -37,6 +44,9 @@ public class MapRenderer implements Renderable { makeTiles(); } + /** + * loads all the images for the tiles and adds all the tiles to the array + */ private void makeTiles() { Texture texture = new Texture(Gdx.files.internal(tilePath)); TextureRegion[][] tileTextures = TextureRegion.split(texture, 32, 32); @@ -103,7 +113,7 @@ public class MapRenderer implements Renderable { public void resize(int screenWidth, int screenHeight) { cam = new OrthographicCamera(screenWidth, screenHeight); - cam.translate(screenWidth / 2, screenHeight / 2); + cam.translate(screenWidth / 2f, screenHeight / 2f); cam.update(); batch.setProjectionMatrix(cam.combined); } diff --git a/core/src/netwerkprog/game/client/map/GameInputProcessor.java b/core/src/netwerkprog/game/client/map/GameInputProcessor.java index 0d69417..d7ab70f 100644 --- a/core/src/netwerkprog/game/client/map/GameInputProcessor.java +++ b/core/src/netwerkprog/game/client/map/GameInputProcessor.java @@ -8,7 +8,6 @@ import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.utils.TimeUtils; import netwerkprog.game.client.MainGame; -import netwerkprog.game.util.application.InputTransform; import java.util.ArrayList; import java.util.Arrays; @@ -28,6 +27,12 @@ public class GameInputProcessor implements InputProcessor { private final float CAMERA_MOVE_SPEED = .3f; + /** + * makes a new game input processor + * + * @param camera the camera object to use + * @param game the game object to get objects from + */ public GameInputProcessor(OrthographicCamera camera, MainGame game) { this.camera = camera; this.game = game; @@ -40,12 +45,6 @@ public class GameInputProcessor implements InputProcessor { keysList.add(Input.Keys.D); camera.zoom = MathUtils.clamp(camera.zoom, 1.5f, 1.8f); -// -// float effectiveViewportWidth = camera.viewportWidth * camera.zoom; -// float effectiveViewportHeight = camera.viewportHeight * camera.zoom; -// -// camera.position.x = MathUtils.clamp(camera.position.x, effectiveViewportWidth / 2f, game.getScreenWidth() - effectiveViewportWidth / 2f); -// camera.position.y = MathUtils.clamp(camera.position.y, effectiveViewportHeight / 2f, game.getScreenHeight() - effectiveViewportHeight / 2f); } @@ -129,7 +128,7 @@ public class GameInputProcessor implements InputProcessor { for (int row = 0; row < game.mapRenderer.getTiles().length; row++) { for (int col = 0; col < game.mapRenderer.getTiles()[0].length; col++) { Tile tile = game.mapRenderer.getTiles()[row][col]; - if (tile.contains(touchPoint.x,touchPoint.y)) { + if (tile.contains(touchPoint.x, touchPoint.y)) { System.out.println(tile + " row: " + row + ", col: " + col); //TODO make stuff happen with the tile return true; diff --git a/core/src/netwerkprog/game/util/application/InputTransform.java b/core/src/netwerkprog/game/util/application/InputTransform.java deleted file mode 100644 index 1faad11..0000000 --- a/core/src/netwerkprog/game/util/application/InputTransform.java +++ /dev/null @@ -1,12 +0,0 @@ -package netwerkprog.game.util.application; - -public class InputTransform { - - public static float getCursorToModelX(int screenwidth, int screenX, int cursorX) { - return (((float) cursorX) * screenwidth) / ((float) screenX); - } - - public static float getCursorToModelY(int screenHeight, int screenY, int cursorY) { - return ((float) (screenY - cursorY)) * screenHeight / ((float) screenY); - } -} \ No newline at end of file -- 2.47.2