亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? levelgenerator.java

?? 大量j2me源代碼
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:

/**
 * Generates a random level using a series of connected rooms.
 * @author Martin Wells
 */

public class LevelGenerator
{
   private static final int LEFT_DIR = 0;
   private static final int RIGHT_DIR = 1;
   private static final int UP_DIR = 2;
   private static final int DOWN_DIR = 3;

   private int width;
   private int height;
   private byte[][] tileMap;
   private int[] roomX;
   private int[] roomY;
   private int[] roomW;
   private int[] roomH;

   private int roomCount;
   private int playerStartX, playerStartY;

   public LevelGenerator()
   {
   }

   private void clear()
   {
      for (int ty = 0; ty < height; ty++)
         for (int tx = 0; tx < width; tx++)
            tileMap[ty][tx] = World.NO_TILE;
   }

   public int getPlayerStartX()
   {
      return playerStartX;
   }

   public int getPlayerStartY()
   {
      return playerStartY;
   }

   /**
    * Generates a new level using a room corridor system. The density of the
    * level is dictated by the level integer.
    * @param level A relative level on density for the level (the higher the
    * number the denser the level.
    * @return A new byte array containing the tiles for the newly generated
    * level.
    */
   public byte[][] generateLevel(int level)
   {
      // Set the size of the level relative to the level number provided.
      width = 30 + (level * 2);
      height = 30 + (level * 2);
      // Cap the level to a reasonable maximum.
      if (width > 100) width = 100;
      if (height > 100) height = 100;

      // Construct a new tile map based on this size and clear it.
      tileMap = new byte[height][width];
      clear();

      // The minRooms is used later to determine when to stop generating new
      // rooms. It's more of a target than an exact number though.
      int totalRooms = 10 + (level * 2);

      System.out.println("Generating level: " + level + " minRooms: " +
                         totalRooms + " width: " + width + " height: " + height);

      // To track all the rooms created in a level we use an array for each
      // room's x, y tile position, the width and height as well as whether the
      // room was a corridor joining two others. This is mostly used by code
      // to determine if there is enough space to place a new room.
      roomX = new int[totalRooms];
      roomY = new int[totalRooms];
      roomW = new int[totalRooms];
      roomH = new int[totalRooms];

      // The minimum size of each room.
      int minRoomHeight = 6;
      int minRoomWidth = 6;
      int maxRoomHeight = 10;
      int maxRoomWidth = 10;

      // Pick the size and location of the first room.
      int corner = Tools.getRand(0, 3);
      int roomStartX = 3;
      int roomStartY = 3;

      switch (corner)
      {
         // case 0 is top left (3,3) (which is already initialised)
         case 1: // top right
            roomStartX = width - maxRoomWidth;
            roomStartY = 3;
            break;
         case 2: // bottom right
            roomStartX = width - maxRoomWidth;
            roomStartY = height - maxRoomHeight;
            break;
         case 3: // bottom left
            roomStartX = 3;
            roomStartY = height - maxRoomHeight;
            break;
      }

      // Add the first room to the map.
      addRoom(level, roomStartX, roomStartY,
              Tools.getRand(minRoomWidth, maxRoomWidth),
              Tools.getRand(minRoomHeight, maxRoomHeight));

      // Set the location where the player's ship will start from.
      playerStartX = roomX[0] + (roomW[0] / 2);
      playerStartY = roomY[0] + (roomH[0] / 2);

      // The addRoom method will fill a room with other objects (such as enemy
      // fighter). This code clears anything that was added to near the player's
      // start point.
      for (int ty = 0; ty < 3; ty++)
         for (int tx = 0; tx < 3; tx++)
            tileMap[playerStartY - 1 + ty][playerStartX - 1 + tx] =
                    World.NO_TILE;

      // Each room added is spaced relative to the previous one so this is
      // an index to keep track of the last full room created (not the last
      // corridor connecting two rooms).
      int lastRoomIndex = 0;

      // Since the code randomly tries different rooms there are cases where
      // a new room is not valid (too big etc). In this case the code will
      // loop around for another go. In order to stop the generation process
      // going for too long the 'tries' counter stops execution after a
      // reasonable number of tries have been executed.
      int tries = 0;

      // Used inside the loop when creating new rooms.
      int newRoomX = 0;
      int newRoomY = 0;

      // Keep tracking of the number of rooms added to the map. Once the room
      // qouta has been reached the level is complete.
      roomCount = 1;

      // As rooms are added they may not fit. If not we try again using a
      // different (random) direction. This array is used to track what
      // directons have previously been tried.
      boolean[] dirsTried = new boolean[4];

      while (roomCount < totalRooms - 1 && tries < 100)
      {
         tries++;

         // Grab the info on the last room created.
         int lastRoomX = roomX[lastRoomIndex];
         int lastRoomY = roomY[lastRoomIndex];
         int lastRoomW = roomW[lastRoomIndex];
         int lastRoomH = roomH[lastRoomIndex];

         // Pick a random size for the new room.
         int newRoomW = Tools.getRand(minRoomWidth, maxRoomWidth);
         int newRoomH = Tools.getRand(minRoomHeight, maxRoomHeight);

         // If the all the previous directions have been tried we reset them
         // and start again.
         if (areAllTrue(dirsTried))
         {
            // reset the tried dirs to have another go
            for (int i = 0; i < 4; i++)
               dirsTried[i] = false;
         }

         // Pick a random dir from the ones that have not previously been tried.
         int dir = getRandDir(dirsTried);

         // Mark this direction as tried.
         dirsTried[dir] = true;

         // Figure the corridor dimensions to connect up this new room.
         int corridorWidth = Tools.getRand(4, 10);
         int corridorHeight = Tools.getRand(4, minRoomHeight - 2);
         if (dir == UP_DIR || dir == DOWN_DIR)
         {
            corridorWidth = Tools.getRand(4, minRoomWidth - 2);
            corridorHeight = Tools.getRand(4, 10);
         }

         // Positioning of the new room. Location is based on the direction
         // picked (randomly from a list of ones previously tried) plus distance
         // for a coridor to connect it up.

         // If the room is to the left or right.
         if (dir == LEFT_DIR || dir == RIGHT_DIR)
         {
            // First choose a new x position (it's relatively fixed based on the
            // position of the previous room and the width of the corridor
            // (already chosen above).
            if (dir == LEFT_DIR)  // to the left
               newRoomX = lastRoomX - newRoomW - corridorWidth + 2;
            if (dir == RIGHT_DIR) // to the right
               newRoomX = lastRoomX + lastRoomW + corridorWidth - 2;

            // Next determine the vertical position of the new room. This code
            // ensures enough space is left availble to fit in the corridor
            // (positioned on the left or right).
            int lowPoint = Math.max(1, lastRoomY + corridorHeight - newRoomH);
            int highPoint = lastRoomY + lastRoomH - corridorHeight;
            newRoomY = Tools.getRand(lowPoint, highPoint);
         }

         // If the room is above or below.
         if (dir == UP_DIR || dir == DOWN_DIR)
         {
            // First choose a new y position (it's relatively fixed based on the
            // position of the previous room and the height of the corridor
            // (already chosen above).
            if (dir == UP_DIR)
               newRoomY = lastRoomY - corridorHeight - newRoomH + 2;
            if (dir == DOWN_DIR)
               newRoomY = lastRoomY + lastRoomH + corridorHeight - 2;

            // Next determine the horizontal position of the new room. This code
            // ensures enough space is left availble to fit in the corridor
            // (positioned on the above or below).
            int lowPoint = Math.max(1, lastRoomX + corridorWidth - newRoomW);
            int highPoint = lastRoomX + lastRoomW - corridorWidth;
            newRoomX = Tools.getRand(lowPoint, highPoint);
         }

         // Check to see if this new room is within the dimensions of the map.
         if (Tools.isRectWithinRect(0, 0, width - 1, height - 1,
                                    newRoomX, newRoomY, newRoomW, newRoomH))
         {
            // Check the room is not too close (or overlapping) another room.
            if (!isRectNearRoom(newRoomX, newRoomY, newRoomW, newRoomH))
            {
               // Clear to add this room to the map.
               addRoom(level, newRoomX, newRoomY, newRoomW, newRoomH);

               // Add the corridor connecting the new room to the last one.
               int corridorX = 0;
               int corridorY = 0;

               // Connect a new room either to the left or right.
               if (dir == LEFT_DIR || dir == RIGHT_DIR)
               {
                  if (dir == LEFT_DIR)
                     corridorX = lastRoomX - corridorWidth + 1;
                  if (dir == RIGHT_DIR)
                     corridorX = lastRoomX + lastRoomW - 1;

                  corridorY = Tools.getRand(Math.max(lastRoomY, newRoomY),
                                            Math.min(lastRoomY + lastRoomH -
                                                     corridorHeight,
                                                     newRoomY + newRoomH -
                                                     corridorHeight));
               }

               // Connect a new room either above or below.
               if (dir == UP_DIR || dir == DOWN_DIR)

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人免费在线播放视频| 欧美喷潮久久久xxxxx| 老司机精品视频线观看86| 91视视频在线观看入口直接观看www| 69p69国产精品| 日韩主播视频在线| 91精品国产欧美一区二区18| 青青草精品视频| 久久久不卡网国产精品一区| 丁香激情综合国产| 亚洲永久免费av| 欧美一二三区精品| 国产激情精品久久久第一区二区| 国产精品久久久久7777按摩 | 综合分类小说区另类春色亚洲小说欧美| 国产伦精品一区二区三区视频青涩| 国产人成一区二区三区影院| 99久久久无码国产精品| 亚洲福利一二三区| 欧美r级电影在线观看| 成人免费视频caoporn| 亚洲精品国产第一综合99久久 | 亚洲成人av资源| 日韩精品中文字幕在线不卡尤物| 国产成人午夜99999| 亚洲永久精品国产| 国产午夜精品久久| 欧美日韩免费高清一区色橹橹| 久久av资源网| 亚洲精品高清在线| 久久亚洲欧美国产精品乐播 | 福利视频网站一区二区三区| 一区二区三区电影在线播| 日韩一区二区电影| 91视频在线观看| 久久成人久久鬼色| 一区二区三区视频在线看| 精品久久一区二区| 欧美三级中文字| 成人午夜av电影| 免费观看30秒视频久久| 亚洲欧美日韩国产手机在线 | av一区二区三区黑人| 麻豆精品一区二区| 亚洲日本免费电影| 国产日韩欧美麻豆| 日韩欧美高清dvd碟片| 在线一区二区三区做爰视频网站| 国产精品一区二区视频| 日韩高清不卡一区| 一区二区三区在线播| 欧美韩日一区二区三区四区| 日韩欧美国产系列| 欧美放荡的少妇| 色成人在线视频| 成av人片一区二区| 国产在线播放一区二区三区| 午夜视频在线观看一区二区| 亚洲日本一区二区| 亚洲四区在线观看| 中文字幕电影一区| 中文字幕欧美日韩一区| 精品少妇一区二区三区日产乱码| 欧美绝品在线观看成人午夜影视| 色综合久久中文字幕综合网| 粉嫩13p一区二区三区| 国产一区二区在线视频| 久久99最新地址| 美腿丝袜亚洲色图| 首页国产丝袜综合| 午夜精品123| 视频一区视频二区中文字幕| 亚洲一区二区欧美| 午夜精品福利久久久| 婷婷六月综合网| 亚洲大尺度视频在线观看| 亚洲最新在线观看| 亚洲一区二区三区自拍| 亚洲综合图片区| 一区二区激情视频| 亚洲二区视频在线| 日韩电影在线观看一区| 美女网站在线免费欧美精品| 另类调教123区| 国产一区在线视频| 成人一级片在线观看| 丁香桃色午夜亚洲一区二区三区| 国产91在线观看| av电影在线观看完整版一区二区| 91色婷婷久久久久合中文| 色综合色狠狠综合色| 欧美日韩一区二区欧美激情| 欧美浪妇xxxx高跟鞋交| 日韩欧美色综合网站| 久久精品一区二区三区不卡| 欧美极品美女视频| 一区二区高清视频在线观看| 五月天激情综合| 精品一区二区三区视频在线观看 | 日韩精品专区在线影院重磅| 亚洲精品在线电影| 国产精品短视频| 亚州成人在线电影| 韩日精品视频一区| 99国产精品视频免费观看| 欧美日韩大陆一区二区| 精品成人一区二区| 中文字幕日韩av资源站| 午夜不卡av免费| 国产成人精品亚洲777人妖 | 91麻豆精品久久久久蜜臀| 欧美mv日韩mv亚洲| 亚洲乱码国产乱码精品精的特点| 日韩影院精彩在线| 波多野结衣在线一区| 欧美日本一区二区三区四区| 久久久综合精品| 一区二区三区成人在线视频| 国产一区二区三区电影在线观看| 91伊人久久大香线蕉| 日韩精品一区二区三区视频在线观看| 中文字幕精品一区二区精品绿巨人 | 国产美女精品人人做人人爽| 色中色一区二区| 337p日本欧洲亚洲大胆精品| 一区二区三区四区激情| 国产一区二区三区观看| 欧美日韩国产美女| 国产精品久久久久久久蜜臀 | 国产欧美日韩视频一区二区| 亚洲一区二区精品3399| 国产成人福利片| 91精品国产欧美一区二区| 亚洲欧美一区二区三区久本道91 | 亚洲成人资源在线| eeuss国产一区二区三区| 日韩欧美一级片| 亚洲福利视频一区| 99久免费精品视频在线观看| 精品国产自在久精品国产| 亚洲电影第三页| 一本色道久久综合精品竹菊| 国产亚洲综合在线| 美腿丝袜一区二区三区| 欧美二区三区91| 午夜视频一区在线观看| 欧美中文字幕不卡| 亚洲色欲色欲www| 成人永久免费视频| 久久久久久97三级| 精品在线免费视频| 欧美一区二区三区免费在线看 | 一区二区三区四区在线| kk眼镜猥琐国模调教系列一区二区| 欧美不卡一区二区三区四区| 视频一区二区三区中文字幕| 欧美午夜精品免费| 洋洋av久久久久久久一区| 在线精品视频小说1| 亚洲最新视频在线观看| 在线精品视频一区二区三四 | 强制捆绑调教一区二区| 欧美日韩成人一区| 亚洲第一成年网| 欧美日韩高清一区二区三区| 五月天亚洲精品| 制服丝袜日韩国产| 日本sm残虐另类| 日韩精品一区二区三区视频在线观看 | 欧美三级三级三级爽爽爽| 一区二区三区成人在线视频| 欧美亚洲图片小说| 亚洲超碰精品一区二区| 欧美精品18+| 蜜桃视频在线观看一区| 亚洲精品一区二区精华| 国产在线精品一区二区夜色| 久久久91精品国产一区二区精品| 国产69精品久久久久777| 18成人在线观看| 精品视频一区 二区 三区| 亚洲18女电影在线观看| 精品国产欧美一区二区| 国产成人av自拍| 亚洲女爱视频在线| 欧美日韩高清一区二区不卡| 麻豆国产一区二区| 国产片一区二区三区| 色系网站成人免费| 日韩专区在线视频| xnxx国产精品| 99re这里只有精品视频首页| 亚洲成人免费av| 26uuu欧美| 色av成人天堂桃色av| 免费在线观看成人| 中文字幕第一区二区| 欧美日韩另类一区| 国产大片一区二区| 亚洲综合色成人|