refactor tile to gametile
This commit is contained in:
@@ -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 netwerkprog.game.client.map.Tile;
|
||||
import netwerkprog.game.client.map.GameTile;
|
||||
import netwerkprog.game.util.graphics.Renderable;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
|
||||
@@ -23,9 +23,8 @@ public class MapRenderer implements Renderable {
|
||||
public static TextureRegion WALL_TILE;
|
||||
public static TextureRegion PATH_TILE;
|
||||
|
||||
private Tile[][] tiles;
|
||||
|
||||
private boolean isStarted = false;
|
||||
private GameTile[][] gameTiles;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@@ -55,18 +54,18 @@ public class MapRenderer implements Renderable {
|
||||
WALL_TILE = tileTextures[0][4];
|
||||
PATH_TILE = tileTextures[4][6];
|
||||
|
||||
this.tiles = new Tile[map.getHeight()][map.getWidth()];
|
||||
this.gameTiles = new GameTile[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, ' ');
|
||||
gameTiles[row][col] = new GameTile(FLOOR_TILE,x,y, ' ');
|
||||
} else if (map.get(row, col) == '#') {
|
||||
tiles[row][col] = new Tile(WALL_TILE,x,y, '#');
|
||||
gameTiles[row][col] = new GameTile(WALL_TILE,x,y, '#');
|
||||
} else if (map.get(row, col) == 'x') {
|
||||
tiles[row][col] = new Tile(PATH_TILE,x,y, 'x');
|
||||
gameTiles[row][col] = new GameTile(PATH_TILE,x,y, 'x');
|
||||
}
|
||||
x += 32;
|
||||
}
|
||||
@@ -94,9 +93,9 @@ public class MapRenderer implements Renderable {
|
||||
batch.begin();
|
||||
batch.setProjectionMatrix(camera.combined);
|
||||
|
||||
for (Tile[] tileRow : tiles) {
|
||||
for (int col = 0; col < tiles[0].length; col++) {
|
||||
Tile cur = tileRow[col];
|
||||
for (GameTile[] gameTileRow : gameTiles) {
|
||||
for (int col = 0; col < gameTiles[0].length; col++) {
|
||||
GameTile cur = gameTileRow[col];
|
||||
batch.draw(cur.getTextureRegion(), cur.x, cur.y);
|
||||
}
|
||||
}
|
||||
@@ -118,7 +117,7 @@ public class MapRenderer implements Renderable {
|
||||
batch.setProjectionMatrix(cam.combined);
|
||||
}
|
||||
|
||||
public Tile[][] getTiles() {
|
||||
return tiles;
|
||||
public GameTile[][] getGameTiles() {
|
||||
return gameTiles;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,6 @@ import com.badlogic.gdx.utils.TimeUtils;
|
||||
import netwerkprog.game.client.MainGame;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
public class GameInputProcessor implements InputProcessor {
|
||||
private final OrthographicCamera camera;
|
||||
@@ -125,11 +123,11 @@ public class GameInputProcessor implements InputProcessor {
|
||||
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);
|
||||
for (int row = 0; row < game.mapRenderer.getGameTiles().length; row++) {
|
||||
for (int col = 0; col < game.mapRenderer.getGameTiles()[0].length; col++) {
|
||||
GameTile gameTile = game.mapRenderer.getGameTiles()[row][col];
|
||||
if (gameTile.contains(touchPoint.x, touchPoint.y)) {
|
||||
System.out.println(gameTile + " row: " + row + ", col: " + col);
|
||||
//TODO make stuff happen with the tile
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ import com.badlogic.gdx.math.Rectangle;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Tile extends Rectangle {
|
||||
public class GameTile extends Rectangle {
|
||||
private TextureRegion textureRegion;
|
||||
private char symbol;
|
||||
|
||||
public Tile(TextureRegion textureRegion, int xPos, int yPos, char symbol) {
|
||||
public GameTile(TextureRegion textureRegion, int xPos, int yPos, char symbol) {
|
||||
this.textureRegion = textureRegion;
|
||||
this.symbol = symbol;
|
||||
super.x = xPos;
|
||||
@@ -38,14 +38,14 @@ public class Tile extends Rectangle {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Tile)) return false;
|
||||
if (!(o instanceof GameTile)) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
Tile tile = (Tile) o;
|
||||
return getSymbol() == tile.getSymbol() &&
|
||||
tile.x == this.x &&
|
||||
tile.y == this.y &&
|
||||
this.width == tile.width &&
|
||||
this.height == tile.height;
|
||||
GameTile gameTile = (GameTile) o;
|
||||
return getSymbol() == gameTile.getSymbol() &&
|
||||
gameTile.x == this.x &&
|
||||
gameTile.y == this.y &&
|
||||
this.width == gameTile.width &&
|
||||
this.height == gameTile.height;
|
||||
}
|
||||
|
||||
@Override
|
||||
Reference in New Issue
Block a user