For some reason, when the player (angel) moves, it moves faster up and down than left and right. Here's the "Play.java" code:
Code:
package javagame;
import org.lwjgl.input.Mouse;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class Play extends BasicGameState{
Animation angel, movingUp, movingDown, movingLeft, movingRight;
Image world;
boolean quit = false;
int[] duration = {200,200};
float angelPositionX = 0;
float angelPositionY = 0;
float shiftX = angelPositionX + 500;
float shiftY = angelPositionY + 250;
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")};
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{
g.drawString("Play state", 410, 50);
//X, Y, Scale
world.draw(angelPositionX, angelPositionY);
angel.draw(shiftX, shiftY);
g.drawString("X: "+angelPositionX+"\nY: "+angelPositionY, 10, 25);
if((angelPositionX>-100 && angelPositionY>-100) && (angelPositionX<100 && angelPositionY<100)){
g.drawString("You should visit the time temple!", 400, 300);
if(quit==true){
g.drawString("Resume (R)", 250, 100);
g.drawString("Main Menu (M)", 250, 120);
g.drawString("Quit Game (Q)", 250, 140);
if(quit==false){
g.clear();
}
}
}
}
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
Input input = gc.getInput();
if(input.isKeyDown(Input.KEY_UP)){
angel = movingUp;
angelPositionY += delta *.3f;
if(angelPositionY>244){
angelPositionY -= delta *.4f;
}
}
if(input.isKeyDown(Input.KEY_DOWN)){
angel = movingDown;
angelPositionY -= delta *.3f;
if(angelPositionY<-686)
{
angelPositionY += delta * .4f;
}
}
if(input.isKeyDown(Input.KEY_LEFT)){
angel = movingLeft;
angelPositionX -= delta *.3f;
if(angelPositionX<505){
angelPositionX += delta * .4f;
}
}
if(input.isKeyDown(Input.KEY_RIGHT)){
angel = movingRight;
angelPositionX += delta *.3f;
if(angelPositionX>-937){
angelPositionX -= delta * .4f;
}
}
//Pause
if(input.isKeyDown(Input.KEY_ESCAPE)){
quit = true;
}
if(input.isKeyDown(Input.KEY_R)){
quit = false;
//Portal
/**
if((angelPositionX>-230 && angelPositionY>-320) && (angelPositionX<-290 && angelPositionY<390)){
sbg.enterState(3);
}
**/
}
}
public int getID(){
return 1;
}
}
Please help.