Compare commits
2 Commits
e885106efd
...
b29b947030
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b29b947030 | ||
|
|
c419e425eb |
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>
|
||||
@@ -9,7 +9,6 @@ import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public class GameMap {
|
||||
|
||||
@@ -18,7 +17,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 +30,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);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package bzh.risotto;
|
||||
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
|
||||
|
||||
/** Launches the desktop (LWJGL3) application. */
|
||||
public class Main {
|
||||
@@ -9,6 +10,12 @@ public class Main {
|
||||
}
|
||||
|
||||
private static void createApplication() {
|
||||
new Lwjgl3Application(new Minesweeper());
|
||||
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
|
||||
config.setWindowedMode(500, 500); // Explicitly set windowed mode dimensions
|
||||
|
||||
// Optional: Set window title
|
||||
config.setTitle("MineSweeper");
|
||||
|
||||
new Lwjgl3Application(new Minesweeper(), config);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package bzh.risotto;
|
||||
|
||||
import com.badlogic.gdx.ApplicationListener;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.utils.ScreenUtils;
|
||||
import com.badlogic.gdx.utils.viewport.FitViewport;
|
||||
@@ -10,12 +11,17 @@ public class Minesweeper implements ApplicationListener {
|
||||
|
||||
private FitViewport viewport;
|
||||
private SpriteBatch spriteBatch;
|
||||
private OrthographicCamera camera;
|
||||
|
||||
private GameMap gameMap;
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
viewport = new FitViewport(100,150);
|
||||
|
||||
int width = 16*10;
|
||||
int height = 16*10;
|
||||
|
||||
viewport = new FitViewport(width,height);
|
||||
spriteBatch = new SpriteBatch();
|
||||
|
||||
gameMap = new GameMap();
|
||||
@@ -41,6 +47,7 @@ public class Minesweeper implements ApplicationListener {
|
||||
|
||||
private void draw() {
|
||||
ScreenUtils.clear(Color.RED);
|
||||
spriteBatch.setProjectionMatrix(viewport.getCamera().combined);
|
||||
spriteBatch.begin();
|
||||
gameMap.render(spriteBatch);
|
||||
spriteBatch.end();
|
||||
|
||||
@@ -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