亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
美女视频免费一区| 91精品黄色片免费大全| 欧美不卡在线视频| 亚洲一级二级三级在线免费观看| 国产a精品视频| 国产日韩欧美精品电影三级在线| 蜜桃久久av一区| 日韩欧美国产一区二区在线播放| 久久综合色综合88| 九一九一国产精品| 日韩欧美国产精品| 老司机精品视频一区二区三区| 91在线观看下载| 国产精品成人一区二区三区夜夜夜| 国产一区二区三区免费在线观看| 欧美一区二区免费| 一区二区三区四区av| va亚洲va日韩不卡在线观看| 中文字幕日韩精品一区 | 亚洲成人动漫精品| 欧美一区二区三区人| 国产在线精品一区二区夜色| 欧美国产国产综合| 欧美三级一区二区| 狠狠色丁香婷综合久久| 亚洲乱码国产乱码精品精的特点| 欧美精品国产精品| 国产成人免费视频一区| 亚洲男人的天堂网| 精品国产一区二区国模嫣然| 99久久精品国产一区| 日韩精品欧美成人高清一区二区| 欧美精品一区二区三区蜜桃 | 午夜精品久久一牛影视| 久久久久97国产精华液好用吗| av激情成人网| 免费xxxx性欧美18vr| 亚洲国产激情av| 欧美精品v国产精品v日韩精品 | 视频在线观看一区| 亚洲国产高清不卡| 日韩一级免费观看| 92国产精品观看| 黑人巨大精品欧美一区| 亚洲国产综合在线| √…a在线天堂一区| 精品99一区二区三区| 欧美日韩一二三区| 91美女片黄在线观看91美女| 国内外精品视频| 日韩经典一区二区| 亚洲国产视频一区| 欧美国产97人人爽人人喊| 777色狠狠一区二区三区| 91网址在线看| 成人一区二区三区视频在线观看| 蜜臀av一级做a爰片久久| 亚洲自拍都市欧美小说| 亚洲视频精选在线| 国产精品免费视频观看| 国产亚洲综合在线| 日韩欧美一区二区三区在线| 欧洲av一区二区嗯嗯嗯啊| av网站免费线看精品| 国产成人午夜99999| 美女国产一区二区| 美女网站在线免费欧美精品| 视频一区在线视频| 日精品一区二区三区| 丝袜诱惑制服诱惑色一区在线观看| 亚洲色图欧美在线| 成人免费在线视频| 中文字幕一区三区| 国产精品萝li| 中文字幕中文字幕在线一区 | 久久国内精品自在自线400部| 亚洲成人自拍偷拍| 亚洲一区二区三区视频在线| 最新不卡av在线| 亚洲精品老司机| 亚洲精品免费电影| 亚洲香蕉伊在人在线观| 一区二区三区中文字幕| 一区二区三区日韩欧美精品| 亚洲免费在线播放| 亚洲图片欧美综合| 青娱乐精品视频| 日本午夜精品视频在线观看| 日韩av一二三| 国内精品不卡在线| 国产成人综合亚洲网站| 成人黄色av电影| 色婷婷狠狠综合| 欧美视频一区二区三区四区 | 日韩精品一区二区三区老鸭窝 | 久国产精品韩国三级视频| 日本亚洲电影天堂| 国产一区二区精品久久91| 国产成人精品网址| 不卡av在线免费观看| 欧美亚洲一区二区三区四区| 欧美欧美午夜aⅴ在线观看| 欧美一区二区三区影视| 欧美精品一区二区不卡| 国产精品免费观看视频| 亚洲国产美女搞黄色| 奇米精品一区二区三区四区| 国产在线精品不卡| 91老司机福利 在线| 欧美日韩精品免费观看视频| 精品国偷自产国产一区| 久久人人爽爽爽人久久久| 国产精品剧情在线亚洲| 亚洲国产aⅴ天堂久久| 极品少妇一区二区| 成人精品小蝌蚪| 欧美久久久久久蜜桃| 国产偷v国产偷v亚洲高清| 中文字幕一区二区三| 天堂一区二区在线免费观看| 国产成人综合网| 欧美日韩一二三区| 精品日韩一区二区三区免费视频| 中文一区二区在线观看| 日韩电影在线看| 风间由美一区二区av101| 精品视频在线免费看| 久久久久久97三级| 亚洲已满18点击进入久久| 国产精品亚洲一区二区三区妖精 | 久久理论电影网| 亚洲综合久久久| 成人免费av资源| 日韩欧美国产一二三区| 夜夜操天天操亚洲| 成人网页在线观看| 欧美xxxxxxxx| 亚洲成av人**亚洲成av**| 成人av网站免费| xvideos.蜜桃一区二区| 亚洲国产视频网站| eeuss鲁一区二区三区| 精品国产123| 日韩av午夜在线观看| 欧美偷拍一区二区| 亚洲美女免费视频| www.日韩精品| 中文字幕欧美国产| 国产馆精品极品| 久久一留热品黄| 精品一区二区三区在线观看国产| 欧美日韩成人一区| 洋洋av久久久久久久一区| 成人h动漫精品一区二区| 久久综合视频网| 狠狠狠色丁香婷婷综合激情| 欧美一二三区在线| 奇米一区二区三区| 欧美一区二区三区播放老司机| 亚洲一区二区三区视频在线| 91久久精品一区二区| 亚洲欧美国产高清| 97精品超碰一区二区三区| 亚洲欧洲99久久| 94色蜜桃网一区二区三区| 国产精品乱人伦中文| 国产精品一区2区| 久久九九国产精品| 成人福利在线看| 性做久久久久久免费观看欧美| 色综合色狠狠综合色| 亚洲欧美韩国综合色| 在线国产亚洲欧美| 亚洲gay无套男同| 制服丝袜在线91| 九色综合国产一区二区三区| 久久久久亚洲蜜桃| 国产91丝袜在线播放0| 国产精品三级久久久久三级| 99麻豆久久久国产精品免费优播| 亚洲欧美在线另类| 欧美日韩视频在线观看一区二区三区| 亚洲一区电影777| 91精品国产手机| 国产麻豆成人传媒免费观看| 欧美国产激情一区二区三区蜜月| 99re视频精品| 日韩不卡一区二区三区 | 成人av在线网| 亚洲小说欧美激情另类| 欧美一区二区免费视频| 国产成人免费网站| 亚洲伦理在线精品| 日韩一本二本av| 国产丶欧美丶日本不卡视频| 亚洲人亚洲人成电影网站色| 欧美人与性动xxxx| 国产一区二区三区最好精华液| 18涩涩午夜精品.www| 欧美情侣在线播放|