Hej allesammen! Jeg har et problem med Slick og JLWGL. Ved ikke om nogen af jer har arbejdet med biblioteket før, men har problem i følgende kode:
- // JUMP
- else if(input.isKeyDown(Input.KEY_W))
- {
- do
- {
- if(ballPosY < defBallPosY + 10)
- {
- ballPosY -= delta * .1f;
- }
- else
- {
- ballPosY += delta * .1f;
- }
- }
- while(ballPosY != defBallPosY);
-
- ballPosY = defBallPosY; // Sætter default BalPosY
- }
Hvis jeg kører programmet og trykker W svarer programmet ikke... Hvilket jeg ikke helt forstår.
Her er resten af koden:
Game klassen
- package javagame;
-
- import org.newdawn.slick.*;
- import org.newdawn.slick.state.*;
-
- public class Game extends StateBasedGame
- {
-
- public static final String gamename = "Mini Game";
- public static final int menu = 0;
- public static final int play = 1;
-
- public Game(String gamename)
- {
- super(gamename);
- this.addState(new Menu(menu));
- this.addState(new Play(play));
- }
-
- public void initStatesList(GameContainer gc) throws SlickException
- {
- this.getState(menu).init(gc, this);
- this.getState(play).init(gc, this);
- this.enterState(menu);
- }
-
- public static void main(String[] args)
- {
- AppGameContainer appgc;
- try
- {
- appgc = new AppGameContainer(new Game(gamename));
- appgc.setDisplayMode(600, 400, false);
- appgc.start();
- }
- catch(SlickException e)
- {
- e.printStackTrace();
- }
- }
-
- }
Menu klassen:
- package javagame;
-
- import org.newdawn.slick.*;
- import org.newdawn.slick.state.*;
-
- public class Menu extends BasicGameState
- {
- Image ball, ballSqueezed, map;
- Animation roll, squeeze, purpBall;
-
- int[] duration = {200,200};
- int defBallPosX = 0; // DEFAULT
- int defBallPosY = 175; // DEFAULT
- int ballPosX = 0;
- int ballPosY = 175;
-
- public Menu(int state)
- {
-
- }
-
- public void init(GameContainer gc, StateBasedGame sbg) throws SlickException
- {
- map = new Image("res/WorldMap.png");
- ball = new Image("res/PurpBallNorm.png"); // X: 24px Y: 25px
- ballSqueezed = new Image("res/PurpBallSqueezed.png"); // X: 8px Y: 25px
-
- Image[] rollPics = {ball, ball};
- roll = new Animation(rollPics, duration, false);
-
- Image[] squeezePics = {ballSqueezed, ballSqueezed};
- squeeze = new Animation(squeezePics, duration, false);
-
- purpBall = roll;
- }
-
- public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException
- {
- map.draw();
-
- g.setColor(Color.black);
- g.drawLine(0, 200, 600, 200);
- g.drawLine(100, 200, 100, 180);
- g.drawLine(150, 200, 150, 180);
- g.drawLine(225, 200, 225, 180);
- g.drawLine(275, 180, 275, 160);
- g.drawLine(350, 180, 350, 160);
- g.drawLine(400, 200, 400, 180);
- g.drawLine(450, 200, 450, 180);
- g.drawLine(500, 180, 500, 160);
- g.drawLine(550, 200, 550, 180);
-
- purpBall.draw(ballPosX, ballPosY);
- }
-
- public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException
- {
- Input input = gc.getInput();
-
- // FORWARD
- if(input.isKeyDown(Input.KEY_D))
- {
- ballPosX += delta *.1f;
- }
- // BACKWARD
- else if(input.isKeyDown(Input.KEY_A))
- {
- ballPosX -= delta * .1f;
- }
- // JUMP
- else if(input.isKeyDown(Input.KEY_W))
- {
- do
- {
- if(ballPosY < defBallPosY + 10)
- {
- ballPosY -= delta * .1f;
- }
- else
- {
- ballPosY += delta * .1f;
- }
- }
- while(ballPosY != defBallPosY);
-
- ballPosY = defBallPosY;
- }
- }
-
- public int getID()
- {
- return 0;
- }
- }