@Thobal: that's wicked.
anyways, So I got my tiled-map displayed properly, now I am having some trouble getting information about each tile to display properly:
Here's the map rendering/displaying class:
package aldaron;
import java.util.Arrays; //unused
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image; //unused
import org.newdawn.slick.Input; //unused
import org.newdawn.slick.SlickException;
import org.newdawn.slick.XMLPackedSheet; //unused
import org.newdawn.slick.SpriteSheet;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.state.BasicGameState;
public class renderWorld extends BasicGameState {
int stateID = -1;
//Images
Image controls = null;
Image cursor = null;
Image tileDisplayPanel = null;
//for cursor rendering
int currentX = mapWorld.baseX;
int currentY = mapWorld.baseY;
int maxX = 20 * (mapWorld.mapWidth - 1) + mapWorld.baseX;
int maxY = mapWorld.baseY - 20;
//Y-axis inverted
int minX = mapWorld.baseX;
int minY = mapWorld.baseY - (20 * (mapWorld.mapHeight - 1));
//tile information data retrieval
int tileRow = 0;
int tileColumn = 0;
renderWorld( int stateID )
{
this.stateID = stateID;
}
@Override
public int getID() {
return stateID;
}
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
controls = new Image("C:\\Users\\Daniel\\Desktop\\Aldaron\\Menu\\controls.png");
cursor = new Image("C:\\Users\\Daniel\\Desktop\\Aldaron\\mapWorld\\Tiles\\cursorAct.png");
tileDisplayPanel = new Image("C:\\Users\\Daniel\\Desktop\\Aldaron\\mapWorld\\MenuParts\\tileDisplayPanel.png");
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
//renders menu stuff
tileDisplayPanel.draw(470, 20);
//renders tiled map and characters
//mapWorld.mapSize = 5; //i.e. this is a 5*5 map; 25 tiles <<Null>>
SpriteSheet Tiles = new SpriteSheet(new Image("C:\\Users\\Daniel\\Desktop\\Aldaron\\mapLocal\\Tiles\\sheetReal.png"), 20, 20);
mapWorld[] currentTile;
mapWorld[] rowNum;
mapWorld[][] tilesAct = new mapWorld[mapWorld.mapHeight][mapWorld.mapWidth];
Tiles.startUse();
for(int x = 0; x < mapWorld.mapHeight; x++) {
rowNum = tilesAct[x];
for(int y = 0; y < mapWorld.mapWidth; y++) {
currentTile = tilesAct[y];
Tiles.renderInUse(x * 20 + mapWorld.baseX, mapWorld.baseY - y * 20, 0, 0);
tilesAct[x][y].typeStore = 1;
if((x == 7 && y == 7) || (x == 6 && y == 6) || (x == 6 && y == 7) || (x == 7 && y == 6)) {
Tiles.renderInUse(x*20 + mapWorld.baseX, mapWorld.baseY - y*20, 1, 0);
tilesAct[x][y].typeStore = 2;
}
tilesAct[x][y].uniqStoreTest = x + (x * y);
}
}
Tiles.endUse();
//map cursor rendering
Input input = gc.getInput();
cursor.draw(currentX , currentY);
if(input.isKeyPressed(input.KEY_RIGHT) && currentX < maxX) {
currentX = currentX + 20;
tileRow = tileRow + 1;
}
if(input.isKeyPressed(input.KEY_LEFT) && currentX > minX) {
currentX = currentX - 20;
tileRow = tileRow - 1;
}
if(input.isKeyPressed(input.KEY_UP) && currentY > minY) {
currentY = currentY - 20;
tileColumn = tileColumn + 1;
}
if(input.isKeyPressed(input.KEY_DOWN) && currentY <= maxY) {
currentY = currentY + 20;
tileColumn = tileColumn - 1;
}
//options/controls menu
//Input input = gc.getInput(); <<unused>>
if(input.isKeyDown(input.KEY_SLASH)) {
g.fillRect(475, 25, 300, 550);
controls.draw(475, 25);
g.drawString("test1", 510, 60);
g.drawString("test2", 510, 80);
g.drawString("test3", 510, 100);
g.drawString("test4", 510, 120);
g.drawString("test5", 510, 140);
g.drawString("test6", 510, 160);
g.drawString("test7", 510, 180);
g.drawString("test8", 510, 200);
g.drawString("test9", 510, 220);
}
//Selected Tile information
g.drawString("Terrain: " + tilesAct[tileRow][tileColumn].terrainType(), 480, 60);
g.drawString("Description: " + tilesAct[tileRow][tileColumn].uniqStoreTest, 480, 100);
g.drawString("terrain debug: " + tilesAct[0][0].terrainType(), 480, 520);
}
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
Input input = gc.getInput();
if(input.isKeyDown(input.KEY_ESCAPE)) {
gc.exit();
}
if(input.isKeyDown(input.KEY_M)) {
sbg.enterState(Aldaron.menuMain);
}
}
}
and here is the class which most tile and map information is stored:
package aldaron;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
public class mapWorld {
//stores test/coordinate variables
//baseX & baseY determine the location of the on-screen map
public static int baseX = 90;
public static int baseY = 500;
public static float defSc = 1;
//////////////////////////////////////
public static int realX;
public static int realY;
public static float globalSc;
public static int uniqStoreTest;
//tileType stores Image info
public static int tileType;
//mapSize sets mapSize; only for use generically.
public static int mapHeight = 14; // # of rows & columns <<Urgent: can't always be 5; just for cursor test>>
public static int mapWidth = 14;
//meh unused
public static int typeStore;
public static String descriptStore;
public mapWorld(boolean isDisplayed) {
//checks if displayed
boolean storeDisp = isDisplayed;
}
public static String terrainType() {
String type = "<<NULL>>";
switch(typeStore) {
case(0):
type = "test";
case(1):
type = "grasslands";
case(2):
type = "mountains";
}
return type;
}
//public static Image Image() throws SlickException {
// //stores image <<unused>>
//
// Image mapImg = null;
//
// switch(tileType) {
//
// case(0):
//
// case(1):
//
// mapImg = "C:\\Users\\Daniel\\Desktop\\Aldaron\\mapWorld\\Tiles\\grass.png";
//
// case(2):
//
// }
//
// return mapImg;
//
//}
}
I did some debugging, but it's proved to be inconclusive. I do not know what the problem is, but I'll try to explain my thoughts as clearly as possible:
The trouble begins at line 69, in the Render method, where the tiles are drawn and each tile's corresponding information-storage instantiated object (these stored in the tilesAct 2dimensional array, consisting of the mapWorld class i.e. the other posted class) is given information regarding type of tile and a description (which for now displays what SHOULD be a unique number) however, regardless of what tile is the map cursor is over the same information is displayed, the actual code for rendering that information starts a line 147. So, I am thinking that the information isn't being stored uniquely because I'm using static variables, but im not sure that makes any sense, and frankly im baffled (its possible a simple mistake) and any help would be appreciated.
If you need more information, or the classes are confusing/difficult-to-read/poorly-documented-&-poorly-explained please do not hesitate to ask, again all help appreciated, thanks.
EDIT: I will edit this with a picture in a second.
here it is:
as you can see the selected square's type is showing as mountains (when it is grasslands, all tiles do this), that ID is the same for all the tiles. Terrain Debug shows the type set for the tile in tilesAct[0][0] i.e. the bottom left
EDITEDIT: Im using LWJGL with slick2D, so sorry if you guys don't understand some of that.