|
@@ -1,22 +1,22 @@
|
|
|
-package ui.tile;
|
|
|
|
|
|
|
+package view.tile;
|
|
|
|
|
|
|
|
-import ui.GamePanel;
|
|
|
|
|
|
|
+import model.Tile;
|
|
|
|
|
+import model.tiles.BackgroundTile;
|
|
|
|
|
+import view.GamePanel;
|
|
|
|
|
|
|
|
-import javax.imageio.ImageIO;
|
|
|
|
|
import java.awt.*;
|
|
import java.awt.*;
|
|
|
-import java.awt.image.BufferedImage;
|
|
|
|
|
import java.io.BufferedReader;
|
|
import java.io.BufferedReader;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
import java.io.InputStreamReader;
|
|
import java.io.InputStreamReader;
|
|
|
-import java.nio.Buffer;
|
|
|
|
|
-import java.util.function.Consumer;
|
|
|
|
|
|
|
|
|
|
public class TileManager {
|
|
public class TileManager {
|
|
|
|
|
|
|
|
GamePanel gamePanel;
|
|
GamePanel gamePanel;
|
|
|
public Tile[] tile;
|
|
public Tile[] tile;
|
|
|
|
|
+ private int MaxTileNumber;
|
|
|
public int[][] mapTileNum;
|
|
public int[][] mapTileNum;
|
|
|
|
|
+ public Tile[][] mapTiles;
|
|
|
public int mapTileOverflow = 1;
|
|
public int mapTileOverflow = 1;
|
|
|
public TileManager(GamePanel gp){
|
|
public TileManager(GamePanel gp){
|
|
|
this.gamePanel = gp;
|
|
this.gamePanel = gp;
|
|
@@ -69,7 +69,6 @@ public class TileManager {
|
|
|
double screenX = worldX - gamePanel.camera.worldX + gamePanel.camera.screenX;
|
|
double screenX = worldX - gamePanel.camera.worldX + gamePanel.camera.screenX;
|
|
|
double screenY = worldY - gamePanel.camera.worldY + gamePanel.camera.screenY;
|
|
double screenY = worldY - gamePanel.camera.worldY + gamePanel.camera.screenY;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
if(worldX + gamePanel.tileSize*mapTileOverflow > gamePanel.camera.worldX - gamePanel.camera.screenX &&
|
|
if(worldX + gamePanel.tileSize*mapTileOverflow > gamePanel.camera.worldX - gamePanel.camera.screenX &&
|
|
|
worldX - gamePanel.tileSize*mapTileOverflow < gamePanel.camera.worldX + gamePanel.camera.screenX &&
|
|
worldX - gamePanel.tileSize*mapTileOverflow < gamePanel.camera.worldX + gamePanel.camera.screenX &&
|
|
|
worldY + gamePanel.tileSize*mapTileOverflow > gamePanel.camera.worldY - gamePanel.camera.screenY &&
|
|
worldY + gamePanel.tileSize*mapTileOverflow > gamePanel.camera.worldY - gamePanel.camera.screenY &&
|
|
@@ -90,14 +89,14 @@ public class TileManager {
|
|
|
|
|
|
|
|
public void getTileImage(){
|
|
public void getTileImage(){
|
|
|
try{
|
|
try{
|
|
|
- setupTile(0, "/tiles/grass.png");
|
|
|
|
|
- setupTile(1, "/tiles/wall.png");
|
|
|
|
|
- setupTile(2, "/tiles/water.png");
|
|
|
|
|
- setupTile(3, "/tiles/earth.png");
|
|
|
|
|
|
|
+ setupTile(0, "grass");
|
|
|
|
|
+ setupTile(1, "wall");
|
|
|
|
|
+ setupTile(2, "water");
|
|
|
|
|
+ setupTile(3, "earth");
|
|
|
|
|
|
|
|
- setupTile(4, "/tiles/tree.png", true, (tile) -> System.out.println("Clicked! x:"+ tile.worldX + ", y:" + tile.worldY));
|
|
|
|
|
|
|
+ setupTile(4, "tree");
|
|
|
|
|
|
|
|
- setupTile(5, "/tiles/sand.png");
|
|
|
|
|
|
|
+ setupTile(5, "sand");
|
|
|
|
|
|
|
|
}catch (IOException e){
|
|
}catch (IOException e){
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -105,16 +104,6 @@ public class TileManager {
|
|
|
}
|
|
}
|
|
|
private void setupTile(int index, String path) throws IOException {
|
|
private void setupTile(int index, String path) throws IOException {
|
|
|
tile[index] = new BackgroundTile();
|
|
tile[index] = new BackgroundTile();
|
|
|
- tile[index].setImage(path);
|
|
|
|
|
- }
|
|
|
|
|
- private void setupTile(int index, String path, boolean interactive, Consumer<Tile> consumer) throws IOException {
|
|
|
|
|
- if(!interactive){
|
|
|
|
|
- tile[index] = new BackgroundTile();
|
|
|
|
|
- }else{
|
|
|
|
|
- InteractiveTile t = new InteractiveTile();
|
|
|
|
|
- t.addOnClick(consumer);
|
|
|
|
|
- tile[index] = t;
|
|
|
|
|
- }
|
|
|
|
|
- tile[index].setImage(path);
|
|
|
|
|
|
|
+ tile[index].setImage("/tiles/" + path + ".png");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|