fixed tilemap display
This commit is contained in:
7
pom.xml
7
pom.xml
@@ -31,6 +31,13 @@
|
||||
<version>1.12.1</version>
|
||||
<classifier>natives-desktop</classifier>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.25.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -18,7 +18,7 @@ public class GameMap {
|
||||
|
||||
public GameMap() {
|
||||
|
||||
this.tileSet = new TileSet("tileset.png", new Vector2(16,16), new Vector2(5,5));
|
||||
this.tileSet = new TileSet("tileset.png", new Vector2(16,16), new Vector2(6,6));
|
||||
List<List<Integer>> map = loadMap();
|
||||
this.tileMap = new TileMap(this.tileSet, map);
|
||||
}
|
||||
@@ -31,7 +31,9 @@ public class GameMap {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
row = new ArrayList<>();
|
||||
for (int j = 0; j < 10; j++) {
|
||||
int tileId = (int) (Math.random()*3);
|
||||
|
||||
int tileId = (i+j)%3;
|
||||
|
||||
row.add(tileId);
|
||||
}
|
||||
res.add(row);
|
||||
|
||||
@@ -15,7 +15,7 @@ public class Minesweeper implements ApplicationListener {
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
viewport = new FitViewport(100,150);
|
||||
viewport = new FitViewport(30,30);
|
||||
spriteBatch = new SpriteBatch();
|
||||
|
||||
gameMap = new GameMap();
|
||||
|
||||
@@ -2,6 +2,8 @@ package bzh.risotto.tilemap;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -20,6 +22,8 @@ public class TileMap {
|
||||
/** 2D list that store the map tiles */
|
||||
private final List<List<Tile>> tileList;
|
||||
|
||||
private static final Logger logger = LogManager.getLogger();
|
||||
|
||||
/**
|
||||
* Load and create the tileMap from a 2D integer list
|
||||
*
|
||||
@@ -47,6 +51,9 @@ public class TileMap {
|
||||
tmpList = new ArrayList<>();
|
||||
for (int i = 0; i < this.map.get(j).size(); i++) {
|
||||
tileId = this.map.get(j).get(i);
|
||||
|
||||
logger.debug("Tile id: " + tileId);
|
||||
|
||||
tile = this.tileSet.getTile(tileId);
|
||||
tmpList.add(tile);
|
||||
}
|
||||
@@ -67,6 +74,7 @@ public class TileMap {
|
||||
for (int j = 0; j < tileList.size(); j++) {
|
||||
for (int i = 0; i < tileList.get(j).size(); i++) {
|
||||
tile = tileList.get(j).get(i);
|
||||
|
||||
pos = new Vector2(i*tileSize.x,j*tileSize.y);
|
||||
tile.render(spriteBatch, pos);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package bzh.risotto.tilemap;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -23,6 +25,8 @@ public class TileSet {
|
||||
/** number of tiles in the tileset */
|
||||
private final Vector2 tilesetSize;
|
||||
|
||||
private Logger logger = LogManager.getLogger();
|
||||
|
||||
/**
|
||||
* Constructor of the class
|
||||
* Loads an array of tile from the tileset
|
||||
@@ -52,16 +56,23 @@ public class TileSet {
|
||||
for (int i = 0; i < this.tilesetSize.y; i++) {
|
||||
for (int j = 0; j < this.tilesetSize.x; j++) {
|
||||
|
||||
Vector2 p = new Vector2(80,80);
|
||||
|
||||
tile = new Tile(
|
||||
|
||||
new TextureRegion(
|
||||
this.tilesTexture,
|
||||
j*tileSize.x,
|
||||
i*tilesetSize.y,
|
||||
tileSize.x,
|
||||
tileSize.y
|
||||
j*(int) tileSize.x,
|
||||
i* (int) tileSize.y,
|
||||
(int) tileSize.x,
|
||||
(int) tileSize.y
|
||||
)
|
||||
);
|
||||
|
||||
logger.debug("------");
|
||||
logger.debug("x:" + j*tileSize.x);
|
||||
logger.debug("y:" + i*tileSize.y);
|
||||
logger.debug(tileSize);
|
||||
tileArray.add(tile);
|
||||
}
|
||||
}
|
||||
|
||||
16
src/main/resources/log4j2.xml
Normal file
16
src/main/resources/log4j2.xml
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration xmlns="https://logging.apache.org/xml/ns"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="https://logging.apache.org/xml/ns
|
||||
https://logging.apache.org/xml/ns/log4j-config-2.xsd">
|
||||
<Appenders>
|
||||
<Console name="CONSOLE">
|
||||
<PatternLayout pattern="%d [%t] %5p %c{1.} - %m%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="DEBUG">
|
||||
<AppenderRef ref="CONSOLE"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
Reference in New Issue
Block a user