slick未在render中运行循环

sczxawaw  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(483)

谁能给我解释一下为什么代码在这里!没有运行,因为osme的原因for循环根本没有运行,没有错误消息或任何我使用的eclipse,以及最新版本的slick和lwjgl包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;
   }
}
kcwpcxri

kcwpcxri1#

for(int y=0; y>19;y++) 因为y是0,所以它不大于19,循环将不会执行。x也是一样
你想要的是

for(int x=0; x<40; x++){
   for(int y=0; y<20; y++){

相关问题