Im stumped on this one...
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;
import java.io.*;
import java.util.*;
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
//also used for local mapID
static int tileRow;
static int tileColumn;
///////////////////////////////
int terrainStore;
//local map ID stuff
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");
}
//loaded outside of methods <test>
mapWorld[][] tilesAct = new mapWorld[mapWorld.mapHeight][mapWorld.mapWidth];
public void preRenderLoad() throws IOException {
//opens scanner; defines string to use
Scanner load = new Scanner(new File("C:\\Users\\Daniel\\Desktop\\Aldaron\\mapWorld\\MapSave\\default"));
String loadInstance;
for(int sizeCheck = 0; sizeCheck < mapWorld.mapHeight; sizeCheck++) {
//sets the string to the line
loadInstance = load.nextLine();
for(int sizeCheck2 = 0; sizeCheck < mapWorld.mapWidth; sizeCheck2++) {
//seperates #s via tokenization; stores in wordCurrent; changes it to an int
StringTokenizer tileTypeGet = new StringTokenizer(loadInstance, ".");
String wordCurrent = tileTypeGet.nextToken();
int wordToInt = Integer.getInteger(wordCurrent);
//sets each tile's constructor; gives terrain and render type
tilesAct[sizeCheck][sizeCheck2] = new mapWorld(wordToInt);
}
}
load.close();
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
SpriteSheet Tiles = new SpriteSheet(new Image("C:\\Users\\Daniel\\Desktop\\Aldaron\\mapLocal\\Tiles\\sheetReal.png"), 20, 20);
//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>
Tiles.startUse();
for(int x = 0; x < mapWorld.mapHeight; x++) {
for(int y = 0; y < mapWorld.mapWidth; y++) {
//int renderType;
//switch(tilesAct[x][y].tileType) {
//case(0):
Tiles.renderInUse(x * 20 + mapWorld.baseX, mapWorld.baseY - y * 20, tilesAct[x][y].tileType(), 0);
tilesAct[x][y].uniqStoreTest = x + y;
//break;
//case(1):
//break;
//case(2):
//break;
//default:
//}
}
}
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_M)) {
sbg.enterState(Aldaron.menuMain);
}
if(input.isKeyDown(input.KEY_ENTER)) {
sbg.enterState(Aldaron.renderLocal);
}
}
}
Im trying to load info from the text file using tokenization and use that to set tile type, needless to say it doesnt work, giving a nullpointerexception at at 114 (or the renderinuse part). Im exhausted so I cant explain more, but all help appreciated, this one has been annoying me for a while now. I can update it later, thanks again.