亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
韩国三级电影一区二区| 亚洲精品v日韩精品| 久色婷婷小香蕉久久| 欧美一区二区在线视频| 免费成人在线播放| 精品少妇一区二区三区| 国产一区二区三区不卡在线观看| 久久综合99re88久久爱| 成人综合激情网| 中文字幕第一区| 色婷婷精品大在线视频| 日日嗨av一区二区三区四区| 日韩欧美色电影| 国产一区二区看久久| 国产精品久久久久久久久快鸭| 91黄视频在线观看| 日韩二区在线观看| 久久亚区不卡日本| 99在线精品免费| 婷婷开心激情综合| 国产偷v国产偷v亚洲高清| 91麻豆福利精品推荐| 亚洲综合清纯丝袜自拍| 日韩免费福利电影在线观看| 成人黄动漫网站免费app| 亚洲精品国产视频| 精品剧情v国产在线观看在线| 国产精品一区不卡| 亚洲一区二三区| 欧美tickling挠脚心丨vk| 成人国产一区二区三区精品| 亚洲成人av一区二区| 久久久久久毛片| 一本高清dvd不卡在线观看| 日本不卡的三区四区五区| 国产精品免费丝袜| 7777精品伊人久久久大香线蕉经典版下载 | 国产精品乱子久久久久| 欧美日韩三级在线| 国产寡妇亲子伦一区二区| 亚洲午夜精品在线| 国产精品日韩精品欧美在线| 欧美一区二区三区小说| 成人美女在线视频| 日本欧美一区二区三区乱码| 国产精品动漫网站| 日韩女优av电影| 欧美综合一区二区| 成av人片一区二区| 美女任你摸久久| 欧美探花视频资源| 日韩在线卡一卡二| 亚洲日本在线a| 26uuu精品一区二区在线观看| 欧美午夜理伦三级在线观看| kk眼镜猥琐国模调教系列一区二区| 美女视频黄久久| 日韩精品免费视频人成| 亚洲精品国产高清久久伦理二区| 国产清纯白嫩初高生在线观看91 | 午夜欧美在线一二页| 中文字幕亚洲视频| 国产欧美一区二区精品性色 | 日韩欧美一二三| 777午夜精品视频在线播放| 91福利在线看| 日本精品免费观看高清观看| av不卡在线播放| 国产不卡视频在线观看| 国产一区二区免费视频| 精品一区二区精品| 久草这里只有精品视频| 美腿丝袜亚洲三区| 人人狠狠综合久久亚洲| 日韩av一区二区三区| 亚洲444eee在线观看| 亚洲国产日韩一区二区| 亚洲品质自拍视频| 亚洲图片欧美激情| 亚洲免费观看高清完整版在线| 成人免费一区二区三区在线观看| 国产精品青草综合久久久久99| 久久久精品国产免费观看同学| 2023国产精华国产精品| 久久精品亚洲麻豆av一区二区| 欧美精品一区二区不卡 | 一本大道综合伊人精品热热| 91片黄在线观看| 91国偷自产一区二区三区成为亚洲经典 | 日韩欧美中文字幕公布| 91精品国产免费| 精品蜜桃在线看| 国产三区在线成人av| 国产午夜精品久久| 成人免费一区二区三区在线观看| 一区二区三区视频在线看| 一区二区三区在线观看网站| 亚洲国产成人tv| 日本成人中文字幕在线视频| 水蜜桃久久夜色精品一区的特点| 免费观看久久久4p| 国产精品一二三在| 97精品久久久久中文字幕| 91国偷自产一区二区开放时间| 欧美人与性动xxxx| 久久影音资源网| 亚洲人成伊人成综合网小说| 亚洲国产cao| 国内精品自线一区二区三区视频| 成人黄页毛片网站| 欧美日本视频在线| 亚洲色大成网站www久久九九| 亚洲精品欧美专区| 男男成人高潮片免费网站| 国产精品自在欧美一区| 色8久久精品久久久久久蜜| 欧美一区二区三区四区在线观看 | 精品久久人人做人人爱| 国产精品久线在线观看| 婷婷中文字幕综合| 成人激情图片网| 日韩午夜av电影| 国产精品国产自产拍高清av王其 | 中文字幕一区二区三区视频 | 精品国产乱码久久久久久影片| 国产精品久久久久久久久免费相片| 婷婷久久综合九色综合伊人色| 成人亚洲一区二区一| 538prom精品视频线放| 国产精品久久久久国产精品日日 | 欧美精品一区二区三| 亚洲色图一区二区三区| 精品一区二区三区日韩| 欧美影院精品一区| 欧美国产丝袜视频| 美女脱光内衣内裤视频久久网站 | 久久久国产午夜精品| 午夜视频久久久久久| 99精品在线免费| 久久亚洲私人国产精品va媚药| 夜色激情一区二区| 国产成人8x视频一区二区 | 日韩女优毛片在线| 亚洲一区二区三区视频在线播放 | 精品成人免费观看| 亚洲福利一区二区| 一本一道久久a久久精品 | 日本强好片久久久久久aaa| 成人免费高清在线| 91精品啪在线观看国产60岁| 中文字幕中文字幕中文字幕亚洲无线| 麻豆91在线播放免费| 91小视频免费观看| 久久精品水蜜桃av综合天堂| 亚洲成va人在线观看| 97精品国产露脸对白| 国产校园另类小说区| 日韩不卡在线观看日韩不卡视频| 99国产精品一区| 国产三级欧美三级日产三级99| 丝袜亚洲另类欧美综合| 91色视频在线| 中文字幕中文字幕一区二区| 国产自产v一区二区三区c| 欧美日韩视频一区二区| 一区二区三区四区国产精品| av毛片久久久久**hd| 国产婷婷色一区二区三区在线| 久草中文综合在线| 日韩欧美一卡二卡| 日韩极品在线观看| 欧美日韩和欧美的一区二区| 亚洲精品国产高清久久伦理二区| 国产成a人亚洲| 久久精品一级爱片| 精品一区二区三区视频| 精品美女在线播放| 精品无码三级在线观看视频| 日韩午夜中文字幕| 久久精品国产精品亚洲精品| 日韩三级电影网址| 美女www一区二区| 欧美成人精品高清在线播放| 久久99精品久久久久久动态图 | 天天综合天天做天天综合| 欧美性欧美巨大黑白大战| 一个色在线综合| 97精品超碰一区二区三区| 亚洲免费av观看| 91黄色免费观看| 亚洲.国产.中文慕字在线| 91精品福利在线一区二区三区| 日韩av在线发布| 久久在线观看免费| 国产成人精品影视| 中文字幕日本不卡| 色婷婷久久久久swag精品| 亚洲在线观看免费视频| 91麻豆精品国产91久久久更新时间 | 日韩国产精品久久久|