Question

Can anyone explain me why the code on the line with //HERE! isn't running, for osme reason the for loop isn't running at all, no error message or anything I use Eclipse, and the latest version of Slick and LWJGL package main;

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

public class Game extends BasicGameState{

   //All the player related variables
   //Such as location, direction, health, etc.
   public static int playerLocX = 0;
   public static int playerLocY = 0;
   public static int playerDir = 1;
   public static int playerHealth = 20;

   //All the locations used during gameplay
   //Such as the destination, collectables, achievements, switches etc.
   public static int gameDestX = 9000;
   public static int gameDestY = 9000;

   //All the laws that can changed
   //0 is default setting, 1 to # is diffrent options
   //such as direction, speed, flamable, etc.
   public static int lawStuff = 0;

   //Here is the actual level saved
   //Because it is such a mess of numbers I moved it
   //to the bottom of the variables
   int[][] level = {
           {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
           {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
           {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
           {0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
           {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
           {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
           {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
           {0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
           {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
           {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
           {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
           {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
           {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
           {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
           {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
           {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
           {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
           {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
           {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
           {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
       }
   ;

   public Game(int state){
   }

   public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{

   }

   public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException{
       Image background     = new Image("res/background.png");
       Image gameBackground = new Image("res/gameBackground.png");
       Image playerDir0     = new Image("res/playerF0.png");
       Image playerDir1     = new Image("res/playerF1.png");
       Image block1         = new Image("res/block1.png");

       for(int x = 0; x < gc.getWidth(); x += background.getWidth()) {
             for(int y = 0; y < gc.getHeight(); y += background.getHeight()) {
                 background.draw(x, y);
             }
       }

       g.drawImage(gameBackground, 183, 100);

       for(int x=0; x>39; x++){
           for(int y=0; y>19; y++){
               g.drawString("Yey",10,10); //HERE!
               if(level[x][y]==1){
                   g.drawImage(block1, 183+x*25, 100+x*25);
                   g.drawString("> " + level[1][0], 30, 30);
               }
           }
       }
   }

   public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
       Input input = gc.getInput();
       if(input.isKeyDown(Input.KEY_RETURN)){sbg.enterState(0);}
   }

   public int getID(){
      return 1;
   }
}
Was it helpful?

Solution

for(int y=0; y>19;y++)

Since y is 0, it is not greater than 19 and the loop will not execute. Same goes for x

What you want is

for(int x=0; x<40; x++){
   for(int y=0; y<20; y++){
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top