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