add ability to see which tile was selected when you click on it
This commit is contained in:
@@ -27,7 +27,7 @@ public class MainGame extends ApplicationAdapter{
|
|||||||
private GameInputProcessor gameInputProcessor;
|
private GameInputProcessor gameInputProcessor;
|
||||||
|
|
||||||
private Map map;
|
private Map map;
|
||||||
private MapRenderer mapRenderer;
|
public MapRenderer mapRenderer;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -52,11 +52,11 @@ public class MapRenderer implements Renderable {
|
|||||||
x = 0;
|
x = 0;
|
||||||
for (int col = 0; col < map.getWidth(); col++) {
|
for (int col = 0; col < map.getWidth(); col++) {
|
||||||
if (map.get(row, 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) == '#') {
|
} 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') {
|
} 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;
|
x += 32;
|
||||||
}
|
}
|
||||||
@@ -83,26 +83,14 @@ public class MapRenderer implements Renderable {
|
|||||||
public void render() {
|
public void render() {
|
||||||
batch.begin();
|
batch.begin();
|
||||||
batch.setProjectionMatrix(camera.combined);
|
batch.setProjectionMatrix(camera.combined);
|
||||||
// for (int row = map.getHeight(); row >= 0; row--) {
|
|
||||||
// y += 32;
|
for (Tile[] tileRow : tiles) {
|
||||||
// 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++) {
|
for (int col = 0; col < tiles[0].length; col++) {
|
||||||
Tile cur = tiles[row][col];
|
Tile cur = tileRow[col];
|
||||||
batch.draw(cur.getTextureRegion(),cur.x,cur.y);
|
batch.draw(cur.getTextureRegion(), cur.x, cur.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
batch.end();
|
batch.end();
|
||||||
x = 0;
|
x = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
package netwerkprog.game.client.map;
|
package netwerkprog.game.client.map;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Input;
|
import com.badlogic.gdx.Input;
|
||||||
import com.badlogic.gdx.InputProcessor;
|
import com.badlogic.gdx.InputProcessor;
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
|
import com.badlogic.gdx.math.Vector3;
|
||||||
import com.badlogic.gdx.utils.TimeUtils;
|
import com.badlogic.gdx.utils.TimeUtils;
|
||||||
import netwerkprog.game.client.MainGame;
|
import netwerkprog.game.client.MainGame;
|
||||||
import netwerkprog.game.util.application.InputTransform;
|
import netwerkprog.game.util.application.InputTransform;
|
||||||
@@ -89,7 +91,7 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyUp(int keycode) {
|
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 (keysList.contains(keycode)) {
|
||||||
if (keycode == keysList.get(0)) {
|
if (keycode == keysList.get(0)) {
|
||||||
this.isWPressed = false;
|
this.isWPressed = false;
|
||||||
@@ -120,8 +122,20 @@ public class GameInputProcessor implements InputProcessor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ import com.badlogic.gdx.math.Rectangle;
|
|||||||
|
|
||||||
public class Tile extends Rectangle{
|
public class Tile extends Rectangle{
|
||||||
private TextureRegion textureRegion;
|
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.textureRegion = textureRegion;
|
||||||
|
this.symbol = symbol;
|
||||||
super.x = xPos;
|
super.x = xPos;
|
||||||
super.y = yPos;
|
super.y = yPos;
|
||||||
super.width = textureRegion.getRegionWidth();
|
super.width = textureRegion.getRegionWidth();
|
||||||
@@ -17,4 +19,17 @@ public class Tile extends Rectangle{
|
|||||||
public TextureRegion getTextureRegion() {
|
public TextureRegion getTextureRegion() {
|
||||||
return textureRegion;
|
return textureRegion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public char getSymbol() {
|
||||||
|
return symbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Tile{" +
|
||||||
|
"symbol=" + symbol +
|
||||||
|
", x=" + x +
|
||||||
|
", y=" + y +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user