Slick Forums

Discuss the Slick 2D Library
It is currently Sat Dec 14, 2019 6:05 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: problem with a new game
PostPosted: Mon Oct 22, 2012 1:44 am 
Offline

Joined: Mon Oct 22, 2012 1:31 am
Posts: 25
hello. im a newb to game design(and newb-intermediate with java) especialy with slick, and i am just tryin to get used to it by making a simple state based game (using legend of zelda link to the pasts sprites)
i looked at a few tutorials, copyed some code and tryed to make something.
but now im stuck at a brick wall, i have an error for some reason when i try to... do anything, no idea why or anything. im just going crazy, so heres my code:

the main class:
Code:
package zelda;

import org.newdawn.slick.*;
import org.newdawn.slick.state.*;

public class engine extends StateBasedGame{
   
   public static final String gameName = "zelda mock";
   public static final int menu = 0;
   public static final int testLevel = 1;
   
   public engine(String gameName) throws SlickException{
      super(gameName);
      this.addState(new Menu(menu));
      this.addState(new TestLevel(testLevel));
   }
   public void initStatesList(GameContainer gc) throws SlickException{
      this.getState(menu).init(gc, this);
      this.getState(testLevel).init(gc, this);
      this.enterState(menu);
   }
   

   public static void main(String[] args) {

      AppGameContainer appgc;
      try{
         appgc = new AppGameContainer(new engine(gameName));
         appgc.setDisplayMode(640, 360, false);
         appgc.start();
      }catch(SlickException e){
      e.printStackTrace();
      }

   }

}




the test map state:
Code:
package zelda;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
import org.newdawn.slick.Animation;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;


public class TestLevel extends BasicGameState{   
   
   Animation link, movingUp, movingDown, movingRight, movingLeft;
   Image testMap;
   boolean quit = false;
   int[] duration = {200,200};
   float linkPostionX = 0;
   float linkPostionY = 0;
   float shiftX = linkPostionX + 360;
   float shiftY = linkPostionY + 160;

   

   public TestLevel(int state)throws SlickException{
   
   }
   
   public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
      testMap = new Image("res/TestMap.png");
      
      Image[] walkUp = {new Image("res/link-front/link-front1.png"),new Image("res/link-front/link-front2.png"),new Image("res/link-front/link-front3.png"),new Image("res/link-front/link-front4.png"),new Image("res/link-front/link-front5.png"),new Image("res/link-front/link-front6.png") ,new Image("res/link-front/link-front7.png")};
      movingUp = new Animation(walkUp, duration, false);
      link = movingUp;

   }
   
   public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
      testMap.draw(linkPostionX, linkPostionY);
      testMap.draw(linkPostionX, linkPostionY);
      link.draw(shiftX, shiftY);
   }
   
   public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
       Input input = gc.getInput();
       if(input.isKeyDown(Input.KEY_DOWN)){
            link = movingDown;
            linkPostionY -= delta * .1f;
            if(linkPostionY<-600){
               linkPostionY += delta * .1f;
            }
         }
   }
   
   public int getID(){
      return 1;
   }
}



theres also a menu state but that is irelavant, so whats suposed to happen is that you press down and he goes down (going to add other directions later)
but what happens is that if you press up nothing happens and any other directions crash the game and give this error:


Sun Oct 21 17:15:48 PDT 2012 INFO:Slick Build #274
Sun Oct 21 17:15:48 PDT 2012 INFO:LWJGL Version: 2.8.4
Sun Oct 21 17:15:48 PDT 2012 INFO:OriginalDisplayMode: 1600 x 1200 x 32 @60Hz
Sun Oct 21 17:15:48 PDT 2012 INFO:TargetDisplayMode: 640 x 360 x 0 @0Hz
Sun Oct 21 17:15:48 PDT 2012 INFO:Starting display 640x360
Sun Oct 21 17:15:48 PDT 2012 INFO:Use Java PNG Loader = true
Sun Oct 21 17:15:48 PDT 2012 INFO:Controllers not available
Sun Oct 21 17:15:50 PDT 2012 ERROR:null
java.lang.NullPointerException
at zelda.TestLevel.render(TestLevel.java:42)
at org.newdawn.slick.state.StateBasedGame.render(StateBasedGame.java:199)
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:681)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:408)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:318)
at zelda.engine.main(engine.java:30)
Sun Oct 21 17:15:50 PDT 2012 ERROR:Game.render() failure - check the game code.
org.newdawn.slick.SlickException: Game.render() failure - check the game code.
at org.newdawn.slick.GameContainer.updateAndRender(GameContainer.java:684)
at org.newdawn.slick.AppGameContainer.gameLoop(AppGameContainer.java:408)
at org.newdawn.slick.AppGameContainer.start(AppGameContainer.java:318)
at zelda.engine.main(engine.java:30)


WTF! eclipse gives me no errors and as far as i can tell they is no issues, could someone just direc me to what might be or is wrong?
ps: im using the newest java, slick, and lwjgl, along with the spartan framework cuz i heard it was cool, even though no associated code is used here


Top
 Profile  
 
PostPosted: Mon Oct 22, 2012 8:23 am 
Offline
Regular
User avatar

Joined: Mon Feb 07, 2011 8:48 pm
Posts: 182
Location: United Kingdom
Well, first thing that I notice is you haven't initialised movingDown which is used for a reference assignment in the if (input.isKeyDown(Input.KEY_DOWN)), this is then going to assign link a null reference and your link.draw(shiftX, shiftY) call will throw a null pointer.

You are also asking teshMap to draw twice for some reason? I am assuming that you meant to check Input.KEY_UP and reference movingUp as that is the only direction you instantiate in the init() method.

The debug states the error is being thrown in TestLevel.render(), specifically line 42, which is consistent with the above. Learning to read your debug output is essential and you will be doing it *a lot*!!!

Liam

_________________
Mirage Realms - A free, retro, 2D MMORPG being developed using Slick2D and TWL


Top
 Profile  
 
PostPosted: Mon Oct 22, 2012 3:36 pm 
Offline

Joined: Mon Oct 22, 2012 1:31 am
Posts: 25
thanks, i later saw those issues and fixed them before you even posted(i have to stop freaking out and just look at the damn error)
now im on to making him slash hs sword :mrgreen:


Top
 Profile  
 
PostPosted: Mon Oct 22, 2012 4:14 pm 
Offline

Joined: Mon Oct 22, 2012 1:31 am
Posts: 25
ok new issue, how do i make an animation go to the end, then switch back to what is was previously, ive got the switch back to previous down, but i dont know hoe to do the rest, its basicully for him slashing, then moving back into walking


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