dig around empty tiles + reorganisation
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
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;
|
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package bzh.risotto;
|
package bzh.risotto.core;
|
||||||
|
|
||||||
|
import bzh.risotto.utils.Timer;
|
||||||
import com.badlogic.gdx.ApplicationListener;
|
import com.badlogic.gdx.ApplicationListener;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Input;
|
import com.badlogic.gdx.Input;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package bzh.risotto;
|
package bzh.risotto.core;
|
||||||
|
|
||||||
|
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package bzh.risotto;
|
package bzh.risotto.core;
|
||||||
|
|
||||||
|
import bzh.risotto.graphics.Animation;
|
||||||
|
import bzh.risotto.utils.Utils;
|
||||||
import bzh.risotto.tilemap.Tile;
|
import bzh.risotto.tilemap.Tile;
|
||||||
import bzh.risotto.tilemap.TileMap;
|
import bzh.risotto.tilemap.TileMap;
|
||||||
import bzh.risotto.tilemap.TileSet;
|
import bzh.risotto.tilemap.TileSet;
|
||||||
@@ -56,21 +58,21 @@ public class Minesweeper {
|
|||||||
|
|
||||||
TileSet tileSet = new TileSet("tileset.png", new Vector2(16,16), new Vector2(6,10));
|
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);
|
List<List<Integer>> map = loadMap(size);
|
||||||
this.tileMap = new TileMap(tileSet, map);
|
this.tileMap = new TileMap(tileSet, map);
|
||||||
this.tileMap.setTile(5,0,0);
|
|
||||||
|
|
||||||
tileSet = new TileSet("ui.png", new Vector2(16,16), new Vector2(5,3));
|
tileSet = new TileSet("ui.png", new Vector2(16,16), new Vector2(5,3));
|
||||||
this.overlayMap = new TileMap(tileSet, Utils.emptyMap(size));
|
this.overlayMap = new TileMap(tileSet, Utils.emptyMap(size));
|
||||||
|
|
||||||
this.minesMap = new MinesMap(new Vector2(10, 10), nbMines);
|
|
||||||
|
|
||||||
this.nbMines = nbMines;
|
this.nbMines = nbMines;
|
||||||
this.nbLeftOverMines = nbMines;
|
this.nbLeftOverMines = nbMines;
|
||||||
|
|
||||||
this.explosion = new Animation("explosion.png", new Vector2(16, 16), 5, 0.10);
|
this.explosion = new Animation("explosion.png", new Vector2(16, 16), 5, 0.10);
|
||||||
|
|
||||||
loadConstArrays();
|
loadConstArrays();
|
||||||
|
|
||||||
|
digFirstTile();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,6 +100,26 @@ public class Minesweeper {
|
|||||||
return res;
|
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
|
* Dig the gamemap at the coord
|
||||||
* convert grass tiles to dirt tiles, and make them visualy connect
|
* convert grass tiles to dirt tiles, and make them visualy connect
|
||||||
@@ -145,6 +167,34 @@ public class Minesweeper {
|
|||||||
|
|
||||||
int nbMines = minesMap.getCell(coord);
|
int nbMines = minesMap.getCell(coord);
|
||||||
this.overlayMap.setTile((nbMines+5), (int) coord.x, (int) coord.y);
|
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) {
|
public void mark(Vector2 worldCoord) {
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package bzh.risotto;
|
package bzh.risotto.graphics;
|
||||||
|
|
||||||
|
import bzh.risotto.utils.Timer;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
@@ -131,4 +131,22 @@ public class TileMap {
|
|||||||
return tileMapCoord;
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package bzh.risotto;
|
package bzh.risotto.utils;
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package bzh.risotto;
|
package bzh.risotto.utils;
|
||||||
|
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
|
||||||
Reference in New Issue
Block a user