Slick Forums

Discuss the Slick 2D Library
It is currently Tue May 21, 2013 3:48 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sun Jul 01, 2012 10:00 pm 
Offline

Joined: Thu Jun 21, 2012 3:27 pm
Posts: 27
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.


Top
 Profile  
 
PostPosted: Tue Jul 10, 2012 9:00 am 
Offline
User avatar

Joined: Wed Jun 20, 2012 8:10 pm
Posts: 54
There are two "speeds" in your game, are you sure it's not related?

Code:
angelPositionY += delta *.3f;
         if(angelPositionY>244){
            angelPositionY -= delta *.4f;
         }


Depending on where your person is on the screen the speed is different, it could explain the issue... No?

Also, some part of your codes are weird, for example :

Quote:
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();
}
}


When you test something to be true, you can just do if (quit), no need to add == true. Also and more important, if quit is tested true, you could never go into the quit == false part... (which also can be tested (!quit))

_________________
Seventeen


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group