Hi. I was just wondering if there was a way to make states if your game extends Basicgame and not StateBasedGame? If not then can you use .tmx files as maps with a state based game?
If so then why can't my character move? Here's the code:
Code:
package javagame;
import org.lwjgl.input.Mouse;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
import org.newdawn.slick.tiled.TiledMap;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Renderable;
import org.newdawn.slick.SlickException;
public class Play extends BasicGameState{
Animation angel, movingUp, movingDown, movingLeft, movingRight;
Image world;
TiledMap grassmap;
int[] duration = {200,200};
float angelPositionX = 0;
float angelPositionY = 0;
float shiftX = angelPositionX + 20;
float shiftY = angelPositionY + 20;
public Play(int state){
}
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
//world = new Image("res/world.png");
Image[] walkUp = {new Image("res/angelback.png"), new Image("res/angelback.png")};
Image[] walkDown = {new Image("res/Angel.png"), new Image("res/Angel.png")};
Image[] walkLeft = {new Image("res/angelLeft.png"), new Image("res/angelLeft.png")};
Image[] walkRight = {new Image("res/angelRight.png"), new Image("res/angelRight.png")};
grassmap = new TiledMap("res/grassmap.tmx");
movingUp = new Animation(walkUp, duration, true);
movingDown = new Animation(walkDown, duration, true);
movingLeft = new Animation(walkLeft, duration, true);
movingRight = new Animation(walkRight, duration, true);
angel = movingDown;
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
//X, Y, Scale float
//world.draw(angelPositionX, angelPositionY);
g.drawString("X: "+angelPositionX+"\nY: "+angelPositionY, 10, 25);
grassmap.render(0, 0);
angel.draw(shiftX, shiftY);
//if((angelPositionX>-100 && angelPositionY>-100) && (angelPositionX<100 && angelPositionY<100)){
//g.drawString("You should visit the time temple!", 400, 300);
}
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
Input input = gc.getInput();
if(input.isKeyDown(Input.KEY_UP))
{
angel = movingUp;
angel.update(delta);
angelPositionY -= delta *.1f;
}
else if (input.isKeyDown(Input.KEY_DOWN))
{
angel = movingDown;
angel.update(delta);
angelPositionY += delta * 0.1f;
}
else if (input.isKeyDown(Input.KEY_LEFT))
{
angel = movingLeft;
angel.update(delta);
angelPositionX -= delta * 0.1f;
}
else if (input.isKeyDown(Input.KEY_RIGHT))
{
angel = movingRight;
angel.update(delta);
angelPositionX += delta * 0.1f;
}
if(input.isKeyDown(Input.KEY_ESCAPE)){
sbg.enterState(3);
}
}
public int getID(){
return 1;
}
}
Please help!