Slick Forums

Discuss the Slick 2D Library
It is currently Tue May 21, 2013 1:06 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Main menu in BasicGame?
PostPosted: Wed Jul 04, 2012 2:33 pm 
Offline

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


Top
 Profile  
 
PostPosted: Wed Jul 04, 2012 5:10 pm 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
Of course you can use Tiled in StateBasedGame too. Both BasicGame and StateBasedGame implement Game, the basic definition of a game in Slick2D. This runs in a container (e.g. AppGameContainer). So just go with StateBasedGame. It more suitable for a complex game :)

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
PostPosted: Wed Jul 04, 2012 6:37 pm 
Offline

Joined: Thu Jun 21, 2012 3:27 pm
Posts: 27
R.D. wrote:
Of course you can use Tiled in StateBasedGame too. Both BasicGame and StateBasedGame implement Game, the basic definition of a game in Slick2D. This runs in a container (e.g. AppGameContainer). So just go with StateBasedGame. It more suitable for a complex game :)

Can you figure out why I can't move? The character is just stuck at the top left of the screen. He turns up, down, left and right but he doesn't move.


Top
 Profile  
 
PostPosted: Wed Jul 04, 2012 7:27 pm 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
Because you don't change the position of the shiftX and shiftY fields. You just set them once in the definition. Put you must update them too ;) (your draw the angel at shiftX, shiftY and these values do not change if angelPosition changes)

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
PostPosted: Wed Jul 04, 2012 8:38 pm 
Offline

Joined: Thu Jun 21, 2012 3:27 pm
Posts: 27
R.D. wrote:
Because you don't change the position of the shiftX and shiftY fields. You just set them once in the definition. Put you must update them too ;) (your draw the angel at shiftX, shiftY and these values do not change if angelPosition changes)

Thanks a lot! :D

_________________
http://ReinventGaming.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 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