WOW! I FIXED IT OUT! MAP IS LOADING PERFECT.
I only need help: My sprite of player and camera dont move (only player change anim when using diff. directions) but X and Y of player is changing.
My Play code:
Code:
public class Play extends BasicGameState{
Animation player, movingUp, movingDown, movingLeft, movingRight; //4 animations,
Image worldMap;
public Map map;
boolean quit = false;
int[] duration = {200,200}; //duration or length of the frame
float playerPositionX = 0; //player will start at coordinates 0,0
float playerPositionY = 0;
float shiftX = playerPositionX + 320; //this will shift the screen so player appears in middle
float shiftY = playerPositionY + 160; //half the length and half the width of the screen
public Play(int state){
}
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
map = new Map();
//worldMap = new Image("res/world.png");
Image[] walkUp = {new Image("res/GFX/Animes/charB.png"), new Image("res/GFX/Animes/charB.png")}; //these are the images to be used in the "walkUp" animation
Image[] walkDown = {new Image("res/GFX/Animes/char.png"), new Image("res/GFX/Animes/char.png")};
Image[] walkLeft = {new Image("res/GFX/Animes/charL.png"), new Image("res/GFX/Animes/charL.png")};
Image[] walkRight = {new Image("res/GFX/Animes/charR.png"), new Image("res/GFX/Animes/charR.png")};
movingUp = new Animation(walkUp, duration, false); //each animation takes array of images, duration for each image, and autoUpdate (just set to false)
movingDown = new Animation(walkDown, duration, false);
movingLeft = new Animation(walkLeft, duration, false);
movingRight = new Animation(walkRight, duration, false);
player = movingDown; //by default as soon as game loads, player will be facing down
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
map.paint(g);
//worldMap.draw(playerPositionX, playerPositionY); //draw the map at 0,0 to start
player.draw(shiftX,shiftY); //draw player at 320, 160 (center of the screen)
g.drawString("player X: "+playerPositionX+"\nplayer Y: "+playerPositionY, 400, 20); //indicator to see where player is in his world
//when they press escape
if(quit==true){
g.drawString("Resume (R)", 250, 100);
g.drawString("Main Menu (M)", 250, 150);
g.drawString("Quit Game (Q)", 250, 200);
g.drawString("Game Menu (G)", 250, 250);
if(quit==false){
g.clear();
}
}
}
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
Input input = gc.getInput();
//during the game if the user hits the up arrow...
if(input.isKeyDown(Input.KEY_W)){
player = movingUp; //change bucky to up image
playerPositionY += delta * .1f; //increase the Y coordinates of bucky (move him up)
if(playerPositionY>162){
playerPositionY -= delta * .1f; //dont let him keep going up if he reaches the top
}
}
if(input.isKeyDown(Input.KEY_S)){
player = movingDown;
playerPositionY -= delta * .1f;
if(playerPositionY<-9000){
playerPositionY += delta * .1f;
}
}
if(input.isKeyDown(Input.KEY_A)){
player = movingLeft;
playerPositionX += delta * .1f;
if(playerPositionX>324){
playerPositionX -= delta * .1f;
}
}
////////////POBIERZ X,Y/////////////
/* if (input.isKeyDown(Input.KEY_LALT)) {
int x = Container.getInput().getMouseX();
y= MouseInfo.getPointerInfo().getLocation().y;
System.out.println("x: " + String.valueOf(x) + " y: " + String.valueOf(y));
}*/
///////////////////////////////
if(input.isKeyDown(Input.KEY_D)){
player = movingRight;
playerPositionX -= delta * .1f;
if(playerPositionX<-8040){
playerPositionX += delta * .1f;
}
}
//escape
if(input.isKeyDown(Input.KEY_ESCAPE)){
quit = true;
}
//when they hit escape
if(quit==true){
if(input.isKeyDown(Input.KEY_R)){
quit = false;
}
if(input.isKeyDown(Input.KEY_M)){
sbg.enterState(0);
try{
Thread.sleep(250);
}catch(InterruptedException e){
e.printStackTrace();
}
}
if(input.isKeyDown(Input.KEY_G)){
sbg.enterState(3);
try{
Thread.sleep(250);
}catch(InterruptedException e){
e.printStackTrace();
}
}
if(input.isKeyDown(Input.KEY_Q)){
System.exit(0);
}
}
}
public int getID(){
return 1;
}
}