Compare commits
10 Commits
e885106efd
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b50ac3ef44 | ||
|
|
41fa146b12 | ||
|
|
a9512b4af8 | ||
|
|
f3118ddf96 | ||
|
|
06f49b2b23 | ||
|
|
9442cc8b14 | ||
|
|
6e317799f1 | ||
|
|
b9583f2a0f | ||
|
|
b29b947030 | ||
|
|
c419e425eb |
10
notes.md
Normal file
10
notes.md
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
0, 0, 0, 1, 1, 2,-1, 2, 1, 0
|
||||||
|
0, 0, 0, 1,-1, 2, 2,-1, 1, 0
|
||||||
|
0, 0, 0, 1, 1, 1, 1, 1, 1, 0
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||||
|
0, 1, 1, 1, 0, 0, 0, 0, 1, 1
|
||||||
|
0, 1,-1, 1, 0, 0, 0, 0, 1,-1
|
||||||
|
0, 1, 1, 1, 1, 2, 2, 1, 1, 1
|
||||||
|
0, 0, 1, 1, 2,-1,-1, 2, 1, 1
|
||||||
|
0, 0, 1,-1, 2, 2, 2, 2,-1, 2
|
||||||
|
0, 0, 1, 1, 1, 0, 0, 1, 2,-1
|
||||||
7
pom.xml
7
pom.xml
@@ -31,6 +31,13 @@
|
|||||||
<version>1.12.1</version>
|
<version>1.12.1</version>
|
||||||
<classifier>natives-desktop</classifier>
|
<classifier>natives-desktop</classifier>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
<artifactId>log4j-core</artifactId>
|
||||||
|
<version>2.25.3</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
package bzh.risotto;
|
|
||||||
|
|
||||||
import bzh.risotto.tilemap.TileMap;
|
|
||||||
import bzh.risotto.tilemap.TileSet;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|
||||||
import com.badlogic.gdx.maps.tiled.TiledMap;
|
|
||||||
import com.badlogic.gdx.maps.tiled.TiledMapTileSet;
|
|
||||||
import com.badlogic.gdx.math.Vector2;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
public class GameMap {
|
|
||||||
|
|
||||||
private TileSet tileSet;
|
|
||||||
private TileMap tileMap;
|
|
||||||
|
|
||||||
public GameMap() {
|
|
||||||
|
|
||||||
this.tileSet = new TileSet("tileset.png", new Vector2(16,16), new Vector2(5,5));
|
|
||||||
List<List<Integer>> map = loadMap();
|
|
||||||
this.tileMap = new TileMap(this.tileSet, map);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<List<Integer>> loadMap() {
|
|
||||||
|
|
||||||
List<List<Integer>> res = new ArrayList<>();
|
|
||||||
|
|
||||||
List<Integer> row;
|
|
||||||
for (int i = 0; i < 10; i++) {
|
|
||||||
row = new ArrayList<>();
|
|
||||||
for (int j = 0; j < 10; j++) {
|
|
||||||
int tileId = (int) (Math.random()*3);
|
|
||||||
row.add(tileId);
|
|
||||||
}
|
|
||||||
res.add(row);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void render(SpriteBatch spriteBatch) {
|
|
||||||
this.tileMap.render(spriteBatch);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package bzh.risotto;
|
package bzh.risotto;
|
||||||
|
|
||||||
|
import bzh.risotto.core.Game;
|
||||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
|
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
|
||||||
|
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
|
||||||
|
|
||||||
/** Launches the desktop (LWJGL3) application. */
|
/** Launches the desktop (LWJGL3) application. */
|
||||||
public class Main {
|
public class Main {
|
||||||
@@ -9,6 +11,12 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void createApplication() {
|
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 Game(), config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,63 +0,0 @@
|
|||||||
package bzh.risotto;
|
|
||||||
|
|
||||||
import com.badlogic.gdx.ApplicationListener;
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|
||||||
import com.badlogic.gdx.utils.ScreenUtils;
|
|
||||||
import com.badlogic.gdx.utils.viewport.FitViewport;
|
|
||||||
|
|
||||||
public class Minesweeper implements ApplicationListener {
|
|
||||||
|
|
||||||
private FitViewport viewport;
|
|
||||||
private SpriteBatch spriteBatch;
|
|
||||||
|
|
||||||
private GameMap gameMap;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void create() {
|
|
||||||
viewport = new FitViewport(100,150);
|
|
||||||
spriteBatch = new SpriteBatch();
|
|
||||||
|
|
||||||
gameMap = new GameMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resize(int width, int height) {
|
|
||||||
viewport.update(width, height, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void render() {
|
|
||||||
logic();
|
|
||||||
move();
|
|
||||||
draw();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void logic() {
|
|
||||||
}
|
|
||||||
|
|
||||||
private void move() {
|
|
||||||
}
|
|
||||||
|
|
||||||
private void draw() {
|
|
||||||
ScreenUtils.clear(Color.RED);
|
|
||||||
spriteBatch.begin();
|
|
||||||
gameMap.render(spriteBatch);
|
|
||||||
spriteBatch.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void pause() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void resume() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dispose() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
124
src/main/java/bzh/risotto/core/Game.java
Normal file
124
src/main/java/bzh/risotto/core/Game.java
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
package bzh.risotto.core;
|
||||||
|
|
||||||
|
import bzh.risotto.utils.Timer;
|
||||||
|
import com.badlogic.gdx.ApplicationListener;
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.Input;
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
import com.badlogic.gdx.utils.ScreenUtils;
|
||||||
|
import com.badlogic.gdx.utils.viewport.FitViewport;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
|
||||||
|
public class Game implements ApplicationListener {
|
||||||
|
|
||||||
|
private static final Logger log = LogManager.getLogger(Game.class);
|
||||||
|
private FitViewport viewport;
|
||||||
|
private SpriteBatch spriteBatch;
|
||||||
|
private OrthographicCamera camera;
|
||||||
|
private Vector2 zoom;
|
||||||
|
|
||||||
|
private Minesweeper minesweeper;
|
||||||
|
private Timer clickDelay;
|
||||||
|
|
||||||
|
private Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void create() {
|
||||||
|
|
||||||
|
int width = 16*10;
|
||||||
|
int height = 16*10;
|
||||||
|
|
||||||
|
viewport = new FitViewport(width,height);
|
||||||
|
spriteBatch = new SpriteBatch();
|
||||||
|
|
||||||
|
zoom = new Vector2(Gdx.graphics.getHeight() / height, Gdx.graphics.getWidth() / width);
|
||||||
|
|
||||||
|
minesweeper = new Minesweeper(new Vector2(10, 10), 20);
|
||||||
|
|
||||||
|
clickDelay = new Timer(0.25);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resize(int width, int height) {
|
||||||
|
viewport.update(width, height, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render() {
|
||||||
|
logic();
|
||||||
|
move();
|
||||||
|
draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void logic() {
|
||||||
|
|
||||||
|
if (Gdx.input.isButtonPressed(Input.Buttons.LEFT) && clickDelay.isFinished()) {
|
||||||
|
Vector2 mousePos = getMouseWorldPos();
|
||||||
|
minesweeper.dig(mousePos);
|
||||||
|
clickDelay.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Gdx.input.isButtonPressed(Input.Buttons.RIGHT) && clickDelay.isFinished()) {
|
||||||
|
Vector2 mousePos = getMouseWorldPos();
|
||||||
|
minesweeper.mark(mousePos);
|
||||||
|
clickDelay.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (minesweeper.isEndgame()) {
|
||||||
|
minesweeper.endGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void move() {
|
||||||
|
|
||||||
|
minesweeper.update();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void draw() {
|
||||||
|
ScreenUtils.clear(Color.RED);
|
||||||
|
spriteBatch.setProjectionMatrix(viewport.getCamera().combined);
|
||||||
|
spriteBatch.begin();
|
||||||
|
minesweeper.render(spriteBatch);
|
||||||
|
spriteBatch.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pause() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resume() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void gameOver(Vector2 pause) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private Vector2 getMouseWorldPos() {
|
||||||
|
float mouseX = Gdx.input.getX();
|
||||||
|
float mouseY = Gdx.input.getY();
|
||||||
|
Vector2 mouseWorldCoord = new Vector2(mouseX, mouseY);
|
||||||
|
|
||||||
|
mouseWorldCoord = viewport.unproject(mouseWorldCoord);
|
||||||
|
|
||||||
|
return mouseWorldCoord;
|
||||||
|
}
|
||||||
|
}
|
||||||
125
src/main/java/bzh/risotto/core/MinesMap.java
Normal file
125
src/main/java/bzh/risotto/core/MinesMap.java
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
package bzh.risotto.core;
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class that load, store and update the mines map
|
||||||
|
*/
|
||||||
|
public class MinesMap {
|
||||||
|
|
||||||
|
private Vector2 size;
|
||||||
|
private List<List<Integer>> map;
|
||||||
|
|
||||||
|
private final Random rand = new Random();
|
||||||
|
|
||||||
|
private final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
|
public MinesMap(Vector2 size, int nbMines) {
|
||||||
|
this.size = size;
|
||||||
|
this.map = loadMap(size, nbMines);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCell(Vector2 coord) {
|
||||||
|
if (coord != null) {
|
||||||
|
return this.map.get((int) coord.y).get((int) coord.x);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<List<Integer>> loadMap(Vector2 size, int nbMines) {
|
||||||
|
|
||||||
|
// generate empty map
|
||||||
|
List<List<Integer>> res = emptyMap(size);
|
||||||
|
|
||||||
|
// set random mines
|
||||||
|
loadMines(res, nbMines);
|
||||||
|
|
||||||
|
// count surrounding mines
|
||||||
|
countMines(res);
|
||||||
|
|
||||||
|
logger.debug(res);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<List<Integer>> emptyMap(Vector2 size) {
|
||||||
|
|
||||||
|
List<List<Integer>> res = new ArrayList<>();
|
||||||
|
List<Integer> row;
|
||||||
|
for (int i = 0; i < size.y; i++) {
|
||||||
|
row = new ArrayList<>();
|
||||||
|
for (int j = 0; j < size.x; j++) {
|
||||||
|
row.add(0);
|
||||||
|
}
|
||||||
|
res.add(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadMines(List<List<Integer>> map, int nbMines) {
|
||||||
|
|
||||||
|
while (nbMines > 0) {
|
||||||
|
|
||||||
|
int coordX = this.rand.nextInt(map.getFirst().size());
|
||||||
|
int coordY = this.rand.nextInt(map.size());
|
||||||
|
|
||||||
|
if (map.get(coordY).get(coordX) != -1) {
|
||||||
|
List<Integer> row = map.get(coordY);
|
||||||
|
row.set(coordX, -1);
|
||||||
|
map.set(coordY, row);
|
||||||
|
|
||||||
|
nbMines --;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void countMines(List<List<Integer>> map) {
|
||||||
|
|
||||||
|
for (int i = 0; i < map.size(); i++) {
|
||||||
|
for (int j = 0; j < map.getFirst().size(); j++) {
|
||||||
|
|
||||||
|
if (map.get(i).get(j) != -1) {
|
||||||
|
int nbMines = countSurroundingMines(map, j, i);
|
||||||
|
List<Integer> row = map.get(i);
|
||||||
|
row.set(j, nbMines);
|
||||||
|
map.set(i, row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int countSurroundingMines(List<List<Integer>> map, int coordX, int coordY) {
|
||||||
|
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
|
for (int i = -1; i < 2; i ++) {
|
||||||
|
for (int j = -1; j < 2; j++) {
|
||||||
|
Integer cell = null;
|
||||||
|
|
||||||
|
// prevent out of bound error while checking border tiles
|
||||||
|
try {
|
||||||
|
cell = map.get(coordY + i).get(coordX + j);
|
||||||
|
} catch (IndexOutOfBoundsException e) {
|
||||||
|
logger.info("Out of world check", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cell != null && cell == -1) {
|
||||||
|
res ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
372
src/main/java/bzh/risotto/core/Minesweeper.java
Normal file
372
src/main/java/bzh/risotto/core/Minesweeper.java
Normal file
@@ -0,0 +1,372 @@
|
|||||||
|
package bzh.risotto.core;
|
||||||
|
|
||||||
|
import bzh.risotto.graphics.Animation;
|
||||||
|
import bzh.risotto.utils.Utils;
|
||||||
|
import bzh.risotto.tilemap.Tile;
|
||||||
|
import bzh.risotto.tilemap.TileMap;
|
||||||
|
import bzh.risotto.tilemap.TileSet;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* class that load, store and update the visual map of the game,
|
||||||
|
* according to the game actions
|
||||||
|
*/
|
||||||
|
public class Minesweeper {
|
||||||
|
|
||||||
|
/** size of the map */
|
||||||
|
private final Vector2 size;
|
||||||
|
|
||||||
|
/** map of the mines */
|
||||||
|
private final MinesMap minesMap;
|
||||||
|
|
||||||
|
/** tilemap used by the gamemap */
|
||||||
|
private final TileMap tileMap;
|
||||||
|
|
||||||
|
/** overlay tilemap */
|
||||||
|
private final TileMap overlayMap;
|
||||||
|
|
||||||
|
/** list of tile that are not digged */
|
||||||
|
private List<Integer> dirtTiles;
|
||||||
|
|
||||||
|
|
||||||
|
private Vector2 lastTileDigged;
|
||||||
|
|
||||||
|
private final int nbMines;
|
||||||
|
private int nbLeftOverMines;
|
||||||
|
private int markedMines;
|
||||||
|
|
||||||
|
private Animation explosion;
|
||||||
|
|
||||||
|
private final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor of the gamemap
|
||||||
|
*
|
||||||
|
* @param size size of the map
|
||||||
|
*/
|
||||||
|
public Minesweeper(Vector2 size, int nbMines) {
|
||||||
|
|
||||||
|
this.size = size;
|
||||||
|
|
||||||
|
TileSet tileSet = new TileSet("tileset.png", new Vector2(16,16), new Vector2(6,10));
|
||||||
|
|
||||||
|
this.minesMap = new MinesMap(new Vector2(10, 10), nbMines);
|
||||||
|
|
||||||
|
List<List<Integer>> map = loadMap(size);
|
||||||
|
this.tileMap = new TileMap(tileSet, map);
|
||||||
|
|
||||||
|
tileSet = new TileSet("ui.png", new Vector2(16,16), new Vector2(5,3));
|
||||||
|
this.overlayMap = new TileMap(tileSet, Utils.emptyMap(size));
|
||||||
|
|
||||||
|
this.nbMines = nbMines;
|
||||||
|
this.nbLeftOverMines = nbMines;
|
||||||
|
|
||||||
|
this.explosion = new Animation("explosion.png", new Vector2(16, 16), 5, 0.10);
|
||||||
|
loadConstArrays();
|
||||||
|
|
||||||
|
digFirstTile();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* generate the gameMap
|
||||||
|
*
|
||||||
|
* @param size size of the map
|
||||||
|
* @return the generated map
|
||||||
|
*/
|
||||||
|
private List<List<Integer>> loadMap(Vector2 size) {
|
||||||
|
|
||||||
|
List<List<Integer>> res = new ArrayList<>();
|
||||||
|
|
||||||
|
List<Integer> row;
|
||||||
|
for (int i = 0; i < size.y; i++) {
|
||||||
|
row = new ArrayList<>();
|
||||||
|
for (int j = 0; j < size.x; j++) {
|
||||||
|
|
||||||
|
int tileId = (i+j)%3;
|
||||||
|
|
||||||
|
row.add(tileId);
|
||||||
|
}
|
||||||
|
res.add(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dig the first tile to start the game on an empty tile
|
||||||
|
*/
|
||||||
|
private void digFirstTile() {
|
||||||
|
// dig empty tile to start game
|
||||||
|
List<Vector2> emptyTiles = new ArrayList<>();
|
||||||
|
Vector2 pos;
|
||||||
|
for (int i = 0; i < size.x; i++) {
|
||||||
|
for (int j = 0; j < size.y; j++) {
|
||||||
|
pos = new Vector2(j, i);
|
||||||
|
if (this.minesMap.getCell(pos) == 0) {
|
||||||
|
emptyTiles.add(pos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2 digPos = emptyTiles.get((int) (Math.random() * emptyTiles.size()));
|
||||||
|
dig(tileMap.toWorldMapCoord(digPos));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dig the gamemap at the coord
|
||||||
|
* convert grass tiles to dirt tiles, and make them visualy connect
|
||||||
|
*
|
||||||
|
* @param worldCoord the world coordinat to dig
|
||||||
|
*/
|
||||||
|
public void dig(Vector2 worldCoord) {
|
||||||
|
|
||||||
|
// convert world coord to tilemap coord
|
||||||
|
Vector2 coord = tileMap.toTileMapCoord(worldCoord);
|
||||||
|
logger.debug("pos: " + coord);
|
||||||
|
logger.debug("tileType: " + getTileType((int) coord.x, (int) coord.y));
|
||||||
|
|
||||||
|
// prevent diging if spot is marked
|
||||||
|
int overlayTileId = this.overlayMap.getTileId((int) coord.x, (int) coord.y);
|
||||||
|
if (overlayTileId == 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// dig the tile
|
||||||
|
tileMap.setTile(13, (int) coord.x, (int) coord.y);
|
||||||
|
lastTileDigged = coord;
|
||||||
|
|
||||||
|
// update the surrounding tiles
|
||||||
|
for (int i = -1; i < 2; i ++) {
|
||||||
|
for (int j = -1; j < 2; j ++) {
|
||||||
|
Tile tile = null;
|
||||||
|
|
||||||
|
// prevent out of bound error while checking border tiles
|
||||||
|
try {
|
||||||
|
tile = tileMap.getTile((int) coord.x + j, (int) coord.y + i);
|
||||||
|
} catch (IndexOutOfBoundsException e) {
|
||||||
|
logger.info("Out of world check", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the right tile to make them visually connect
|
||||||
|
if ( tile != null && !dirtTiles.contains(tile.getId())) {
|
||||||
|
int tileType = getTileType((int) coord.x + j, (int) coord.y + i);
|
||||||
|
int tileId = tileTypeToId(tileType);
|
||||||
|
|
||||||
|
tileMap.setTile(tileId, (int) coord.x + j, (int) coord.y + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int nbMines = minesMap.getCell(coord);
|
||||||
|
this.overlayMap.setTile((nbMines+5), (int) coord.x, (int) coord.y);
|
||||||
|
|
||||||
|
if (minesMap.getCell(coord) == 0) {
|
||||||
|
digEmptyArround(coord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void digEmptyArround(Vector2 pos) {
|
||||||
|
|
||||||
|
for (int i = -1; i < 2; i ++) {
|
||||||
|
for (int j = -1; j < 2; j ++) {
|
||||||
|
Tile tile = null;
|
||||||
|
|
||||||
|
Vector2 tilePos = new Vector2(pos.x + j, pos.y + i);
|
||||||
|
|
||||||
|
// prevent out of bound error while checking border tiles
|
||||||
|
try {
|
||||||
|
tile = tileMap.getTile((int) tilePos.x, (int) tilePos.y);
|
||||||
|
} catch (IndexOutOfBoundsException e) {
|
||||||
|
|
||||||
|
//logger.info("Out of world check", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if not digged and mines arround is 0, dig
|
||||||
|
if (tile != null && dirtTiles.contains(tile.getId())) {
|
||||||
|
dig(tileMap.toWorldMapCoord(tilePos));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mark(Vector2 worldCoord) {
|
||||||
|
Vector2 coord = tileMap.toTileMapCoord(worldCoord);
|
||||||
|
|
||||||
|
int tileId = this.overlayMap.getTileId((int) coord.x, (int) coord.y);
|
||||||
|
|
||||||
|
if (tileId == 0) {
|
||||||
|
this.overlayMap.setTile((1), (int) coord.x, (int) coord.y);
|
||||||
|
if (minesMap.getCell(coord) == -1) {
|
||||||
|
nbLeftOverMines -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.markedMines -= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (tileId == 1) {
|
||||||
|
this.overlayMap.setTile((0), (int) coord.x, (int) coord.y);
|
||||||
|
if (minesMap.getCell(coord) == -1) {
|
||||||
|
nbLeftOverMines += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.markedMines += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEndgame() {
|
||||||
|
return (nbLeftOverMines == 0 && markedMines == nbMines) || minesMap.getCell(lastTileDigged) == -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void endGame() {
|
||||||
|
|
||||||
|
if (lastTileDigged != null && minesMap.getCell(lastTileDigged) == -1) {
|
||||||
|
explosion.play(new Vector2(lastTileDigged.x*16, lastTileDigged.y*16), false);
|
||||||
|
revealMines();
|
||||||
|
lastTileDigged = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void revealMines() {
|
||||||
|
for (int i = 0; i < size.y; i++ ) {
|
||||||
|
for (int j = 0; j < size.y; j++ ) {
|
||||||
|
if (
|
||||||
|
minesMap.getCell(new Vector2(j,i)) == -1
|
||||||
|
&& overlayMap.getTileId(j, i) != 1
|
||||||
|
) {
|
||||||
|
overlayMap.setTile(4, j, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
this.explosion.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* draw the map to the screen
|
||||||
|
*
|
||||||
|
* @param spriteBatch the spritebatch to use
|
||||||
|
*/
|
||||||
|
public void render(SpriteBatch spriteBatch) {
|
||||||
|
this.tileMap.render(spriteBatch);
|
||||||
|
this.overlayMap.render(spriteBatch);
|
||||||
|
this.explosion.render(spriteBatch);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* calculate the type of the tile, by checking the surrounding tiles
|
||||||
|
*
|
||||||
|
* @param coordX x coordinate of the tile to check
|
||||||
|
* @param coordY y coordinate of the tile to check
|
||||||
|
* @return the tile type
|
||||||
|
*/
|
||||||
|
private int getTileType(int coordX, int coordY) {
|
||||||
|
// count tiles around
|
||||||
|
int p = 0;
|
||||||
|
int tileType = 0;
|
||||||
|
for (int i = -1; i < 2; i ++) {
|
||||||
|
for (int j = -1; j < 2; j ++) {
|
||||||
|
Tile tile = null;
|
||||||
|
|
||||||
|
// prevent out of bound error when checking border tiles
|
||||||
|
try {
|
||||||
|
tile = tileMap.getTile(coordX + j, coordY + i);
|
||||||
|
} catch (IndexOutOfBoundsException e) {
|
||||||
|
logger.info("Out of world check", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
// compute tile type
|
||||||
|
if (tile != null && !dirtTiles.contains(tile.getId())) {
|
||||||
|
tileType += (int) Math.pow(2, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tileType -= 16;
|
||||||
|
|
||||||
|
return tileType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convert tile type to tile set coordinate
|
||||||
|
* (could be generalized too fit every tileset)
|
||||||
|
*coordinate
|
||||||
|
* @param tileType the tile type we want to convert
|
||||||
|
* @return the corresponding coordinate in the tileset
|
||||||
|
*/
|
||||||
|
private int tileTypeToId(int tileType) {
|
||||||
|
return switch (tileType) {
|
||||||
|
case 2, 3, 6, 7, 71, 323, 327, 66, 322, 67, 258, 259, 263, 262, 326, 70 -> 10; // down
|
||||||
|
case 128, 192, 448, 384, 385, 449, 453, 193, 132, 196, 452, 133, 197, 388, 389, 129 -> 22; // up
|
||||||
|
case 8, 73, 72, 9, 329, 333, 328, 332, 77, 264, 268, 269, 12, 13, 76 -> 17; // right
|
||||||
|
case 32, 288, 292, 36, 356, 357, 33, 97, 353, 96, 100, 101, 37, 293, 352, 289 -> 15; // left
|
||||||
|
case 160, 161, 165, 229, 224, 228, 164, 225 -> 21; // inner bot-left corner
|
||||||
|
case 10, 74, 330, 334, 266, 270, 78, 14 -> 11; // inner top-right corner
|
||||||
|
case 34, 35, 99, 355, 290, 354, 291, 98 -> 9; // inner top-left corner
|
||||||
|
case 136, 137, 393, 397, 140, 141, 392, 396 -> 23; // inner bot-right corner
|
||||||
|
case 40, 44, 45, 109, 365, 105, 361, 296, 360, 104, 364, 41, 297, 301, 108, 300 -> 45; // left-right corridor
|
||||||
|
case 130, 134, 135, 199, 455, 391, 194, 195, 451, 198, 131, 387, 450, 454, 386, 390 -> 39; // top-down corridor
|
||||||
|
case 168, 169, 173, 172 -> 34; // T up
|
||||||
|
case 42, 106, 362, 298 -> 29; // T down
|
||||||
|
case 138, 394, 398, 142 -> 35; // T right
|
||||||
|
case 227, 162, 226, 163 -> 28; // T left
|
||||||
|
case 38, 102, 358, 359, 294, 295, 39, 103 -> 6; // top-left corner
|
||||||
|
case 204, 205, 461, 456, 457, 200, 201, 460 -> 20; // bot-left corner
|
||||||
|
case 416, 417, 481, 485, 420, 484, 421, 480 -> 18; // bot-right corner
|
||||||
|
case 11, 75, 79, 335, 267, 271, 351, 15, 331 -> 8; // top-right corner
|
||||||
|
case 47, 111, 367, 303 -> 7; // up-straight
|
||||||
|
case 488, 496, 493, 492, 489 -> 19; // bot-straight
|
||||||
|
case 203, 459, 463, 207 -> 14; // left-straight
|
||||||
|
case 422, 486, 487, 423 -> 12; // right-straight
|
||||||
|
case 232, 233, 237, 236 -> 30;
|
||||||
|
case 418, 482, 483, 419 -> 24;
|
||||||
|
case 143, 399, 139, 395 -> 31;
|
||||||
|
case 46, 110, 366, 302 -> 25;
|
||||||
|
case 166, 167, 230, 231 -> 46;
|
||||||
|
case 43, 299, 363, 107 -> 40;
|
||||||
|
case 202, 206, 462, 458 -> 41;
|
||||||
|
case 424, 428, 429, 425 -> 47;
|
||||||
|
case 235 -> 37; // right gateway
|
||||||
|
case 430 -> 38; // left gateway
|
||||||
|
case 175 -> 42; // top gateway
|
||||||
|
case 490 -> 36; // bo gateway
|
||||||
|
case 239 -> 32; // inner top-right
|
||||||
|
case 431 -> 33; // inner top-left
|
||||||
|
case 491 -> 26; // inner bot-left
|
||||||
|
case 494 -> 27; // inner bot-right
|
||||||
|
case 427 -> 44;
|
||||||
|
case 238 -> 43;
|
||||||
|
case 171 -> 54;
|
||||||
|
case 174 -> 55;
|
||||||
|
case 234 -> 48;
|
||||||
|
case 426 -> 49;
|
||||||
|
case 495 -> 13; // center full
|
||||||
|
case 170 -> 16; // center cross
|
||||||
|
default -> 5;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public TileMap getTileMap() {
|
||||||
|
return this.tileMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadConstArrays() {
|
||||||
|
this.dirtTiles = new ArrayList<>();
|
||||||
|
this.dirtTiles.add(0);
|
||||||
|
this.dirtTiles.add(1);
|
||||||
|
this.dirtTiles.add(2);
|
||||||
|
this.dirtTiles.add(4);
|
||||||
|
}
|
||||||
|
}
|
||||||
94
src/main/java/bzh/risotto/graphics/Animation.java
Normal file
94
src/main/java/bzh/risotto/graphics/Animation.java
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
package bzh.risotto.graphics;
|
||||||
|
|
||||||
|
import bzh.risotto.utils.Timer;
|
||||||
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Animation {
|
||||||
|
|
||||||
|
List<TextureRegion> imagesArray;
|
||||||
|
|
||||||
|
private final Vector2 textureSize;
|
||||||
|
private final int nbFrames;
|
||||||
|
private final double frameTime;
|
||||||
|
|
||||||
|
private boolean playing;
|
||||||
|
private int curFrame;
|
||||||
|
|
||||||
|
private Timer imageTime;
|
||||||
|
|
||||||
|
private Vector2 pos;
|
||||||
|
private boolean looping;
|
||||||
|
|
||||||
|
public Animation(String texturePath, Vector2 textureSize, int nbFrames, double frameTime) {
|
||||||
|
|
||||||
|
this.textureSize = textureSize;
|
||||||
|
this.nbFrames = nbFrames;
|
||||||
|
this.frameTime = frameTime;
|
||||||
|
|
||||||
|
this.playing = false;
|
||||||
|
this.curFrame = -1;
|
||||||
|
|
||||||
|
this.imageTime = new Timer(frameTime);
|
||||||
|
loadImages(texturePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadImages(String texturePath) {
|
||||||
|
|
||||||
|
this.imagesArray = new ArrayList<>();
|
||||||
|
|
||||||
|
Texture images = new Texture(texturePath);
|
||||||
|
TextureRegion image;
|
||||||
|
for (int i = 0; i < nbFrames; i++) {
|
||||||
|
|
||||||
|
image = new TextureRegion(images, i * (int) textureSize.x, i, (int) textureSize.x, (int) textureSize.y);
|
||||||
|
|
||||||
|
imagesArray.add(image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void play(Vector2 pos, boolean looping) {
|
||||||
|
|
||||||
|
if (playing != true) {
|
||||||
|
this.playing = true;
|
||||||
|
this.imageTime.start();
|
||||||
|
this.curFrame = 1;
|
||||||
|
this.pos = pos;
|
||||||
|
this.looping = looping;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
System.out.println("Stopped");
|
||||||
|
|
||||||
|
this.playing = false;
|
||||||
|
this.imageTime.stop();
|
||||||
|
this.curFrame = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
|
||||||
|
if (this.playing && this.imageTime.isFinished()) {
|
||||||
|
this.curFrame ++;
|
||||||
|
|
||||||
|
if (looping) {
|
||||||
|
this.curFrame %= this.nbFrames;
|
||||||
|
} else if (this.curFrame >= this.nbFrames) {
|
||||||
|
this.stop();
|
||||||
|
}
|
||||||
|
this.imageTime.start();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render(SpriteBatch spriteBatch) {
|
||||||
|
if (this.playing) {
|
||||||
|
spriteBatch.draw(this.imagesArray.get(this.curFrame), (int) this.pos.x, (int) this.pos.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -9,6 +9,9 @@ import com.badlogic.gdx.math.Vector2;
|
|||||||
*/
|
*/
|
||||||
public class Tile {
|
public class Tile {
|
||||||
|
|
||||||
|
/** the id of the tile */
|
||||||
|
private int id;
|
||||||
|
|
||||||
/** the texture of the tile */
|
/** the texture of the tile */
|
||||||
private final TextureRegion tileTexture;
|
private final TextureRegion tileTexture;
|
||||||
|
|
||||||
@@ -17,10 +20,20 @@ public class Tile {
|
|||||||
*
|
*
|
||||||
* @param tileTexture the texture of the tile
|
* @param tileTexture the texture of the tile
|
||||||
*/
|
*/
|
||||||
public Tile(TextureRegion tileTexture) {
|
public Tile(int id, TextureRegion tileTexture) {
|
||||||
|
this.id = id;
|
||||||
this.tileTexture = tileTexture;
|
this.tileTexture = tileTexture;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getter for the id of the tile
|
||||||
|
*
|
||||||
|
* @return the id of the tile
|
||||||
|
*/
|
||||||
|
public int getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* render the tile
|
* render the tile
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package bzh.risotto.tilemap;
|
|||||||
|
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
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.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -20,6 +22,8 @@ public class TileMap {
|
|||||||
/** 2D list that store the map tiles */
|
/** 2D list that store the map tiles */
|
||||||
private final List<List<Tile>> tileList;
|
private final List<List<Tile>> tileList;
|
||||||
|
|
||||||
|
private static final Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load and create the tileMap from a 2D integer list
|
* Load and create the tileMap from a 2D integer list
|
||||||
*
|
*
|
||||||
@@ -47,6 +51,9 @@ public class TileMap {
|
|||||||
tmpList = new ArrayList<>();
|
tmpList = new ArrayList<>();
|
||||||
for (int i = 0; i < this.map.get(j).size(); i++) {
|
for (int i = 0; i < this.map.get(j).size(); i++) {
|
||||||
tileId = this.map.get(j).get(i);
|
tileId = this.map.get(j).get(i);
|
||||||
|
|
||||||
|
logger.debug("Tile id: " + tileId);
|
||||||
|
|
||||||
tile = this.tileSet.getTile(tileId);
|
tile = this.tileSet.getTile(tileId);
|
||||||
tmpList.add(tile);
|
tmpList.add(tile);
|
||||||
}
|
}
|
||||||
@@ -56,6 +63,39 @@ public class TileMap {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the tile at position x,y
|
||||||
|
*
|
||||||
|
* @param x the x coordinate of the tile
|
||||||
|
* @param y the y coordinate of the tile
|
||||||
|
* @return the tile at position x,y
|
||||||
|
*/
|
||||||
|
public Tile getTile(int x, int y) {
|
||||||
|
return this.tileList.get(y).get(x);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the tile id at position x,y
|
||||||
|
*
|
||||||
|
* @param x the x coordinate of the tile
|
||||||
|
* @param y the y coordinate of the tile
|
||||||
|
* @return the tile id at position x,y
|
||||||
|
*/
|
||||||
|
public int getTileId(int x, int y) {
|
||||||
|
return this.tileList.get(y).get(x).getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the tile at position x,y to id
|
||||||
|
*
|
||||||
|
* @param id the id of the new tile
|
||||||
|
* @param x the x coordinate of the tile
|
||||||
|
* @param y the y coordinate of the tile
|
||||||
|
*/
|
||||||
|
public void setTile(int id, int x, int y) {
|
||||||
|
this.tileList.get(y).set(x, tileSet.getTile(id));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* render the map on the screen
|
* render the map on the screen
|
||||||
*/
|
*/
|
||||||
@@ -67,9 +107,46 @@ public class TileMap {
|
|||||||
for (int j = 0; j < tileList.size(); j++) {
|
for (int j = 0; j < tileList.size(); j++) {
|
||||||
for (int i = 0; i < tileList.get(j).size(); i++) {
|
for (int i = 0; i < tileList.get(j).size(); i++) {
|
||||||
tile = tileList.get(j).get(i);
|
tile = tileList.get(j).get(i);
|
||||||
|
|
||||||
pos = new Vector2(i*tileSize.x,j*tileSize.y);
|
pos = new Vector2(i*tileSize.x,j*tileSize.y);
|
||||||
tile.render(spriteBatch, pos);
|
tile.render(spriteBatch, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convert world coord to tile map coord
|
||||||
|
*
|
||||||
|
* @param worldCoord world coordinate to convert
|
||||||
|
* @return tilemap coordinate
|
||||||
|
*/
|
||||||
|
public Vector2 toTileMapCoord(Vector2 worldCoord) {
|
||||||
|
|
||||||
|
Vector2 tileMapCoord = new Vector2();
|
||||||
|
Vector2 tileSize = tileSet.getTileSize();
|
||||||
|
|
||||||
|
tileMapCoord.x = (int) (worldCoord.x / (tileSize.x));
|
||||||
|
tileMapCoord.y = (int) (worldCoord.y / (tileSize.y));
|
||||||
|
|
||||||
|
return tileMapCoord;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* convert tilemap coord to world coord
|
||||||
|
*
|
||||||
|
* @param tileMapdCoord world coordinate to convert
|
||||||
|
* @return tilemap coordinate
|
||||||
|
*/
|
||||||
|
public Vector2 toWorldMapCoord(Vector2 tileMapCoord) {
|
||||||
|
|
||||||
|
Vector2 worldCoord = new Vector2();
|
||||||
|
Vector2 tileSize = tileSet.getTileSize();
|
||||||
|
|
||||||
|
worldCoord.x = (int) (tileMapCoord.x * tileSize.x);
|
||||||
|
worldCoord.y = (int) (tileMapCoord.y * tileSize.y);
|
||||||
|
|
||||||
|
return worldCoord;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package bzh.risotto.tilemap;
|
|||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
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.ArrayList;
|
||||||
|
|
||||||
@@ -23,6 +25,8 @@ public class TileSet {
|
|||||||
/** number of tiles in the tileset */
|
/** number of tiles in the tileset */
|
||||||
private final Vector2 tilesetSize;
|
private final Vector2 tilesetSize;
|
||||||
|
|
||||||
|
private Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor of the class
|
* Constructor of the class
|
||||||
* Loads an array of tile from the tileset
|
* Loads an array of tile from the tileset
|
||||||
@@ -52,13 +56,16 @@ public class TileSet {
|
|||||||
for (int i = 0; i < this.tilesetSize.y; i++) {
|
for (int i = 0; i < this.tilesetSize.y; i++) {
|
||||||
for (int j = 0; j < this.tilesetSize.x; j++) {
|
for (int j = 0; j < this.tilesetSize.x; j++) {
|
||||||
|
|
||||||
|
Vector2 p = new Vector2(80,80);
|
||||||
|
|
||||||
tile = new Tile(
|
tile = new Tile(
|
||||||
|
(int) (i*tilesetSize.x + j),
|
||||||
new TextureRegion(
|
new TextureRegion(
|
||||||
this.tilesTexture,
|
this.tilesTexture,
|
||||||
j*tileSize.x,
|
j*(int) tileSize.x,
|
||||||
i*tilesetSize.y,
|
i* (int) tileSize.y,
|
||||||
tileSize.x,
|
(int) tileSize.x,
|
||||||
tileSize.y
|
(int) tileSize.y
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
43
src/main/java/bzh/risotto/utils/Timer.java
Normal file
43
src/main/java/bzh/risotto/utils/Timer.java
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package bzh.risotto.utils;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
|
public class Timer {
|
||||||
|
|
||||||
|
private double duration;
|
||||||
|
private double startTime;
|
||||||
|
|
||||||
|
Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
|
public Timer(double duration) {
|
||||||
|
this.duration = duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
this.startTime = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
|
this.startTime = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFinished() {
|
||||||
|
return timeLeft() <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double timeLeft() {
|
||||||
|
|
||||||
|
if (this.startTime > 0) {
|
||||||
|
double res = this.startTime - System.currentTimeMillis() + (duration * 1000);
|
||||||
|
if (res > 0) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/main/java/bzh/risotto/utils/Utils.java
Normal file
28
src/main/java/bzh/risotto/utils/Utils.java
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package bzh.risotto.utils;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Utils {
|
||||||
|
|
||||||
|
public static List<List<Integer>> emptyMap(Vector2 size) {
|
||||||
|
|
||||||
|
List<List<Integer>> res = new ArrayList<>();
|
||||||
|
|
||||||
|
List<Integer> row;
|
||||||
|
for (int i = 0; i < size.y; i++) {
|
||||||
|
row = new ArrayList<>();
|
||||||
|
for (int j = 0; j < size.x; j++) {
|
||||||
|
|
||||||
|
int tileId = 0;
|
||||||
|
|
||||||
|
row.add(tileId);
|
||||||
|
}
|
||||||
|
res.add(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
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>
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 632 B After Width: | Height: | Size: 631 B |
Reference in New Issue
Block a user