亚洲欧美第一页_禁久久精品乱码_粉嫩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久久香蕉国产日韩欧美9色| 亚洲色图清纯唯美| 色诱视频网站一区| 亚洲国产欧美另类丝袜| 日韩亚洲欧美高清| 国产精品一二一区| 日本一区二区三区dvd视频在线| 成人激情动漫在线观看| 亚洲欧美日韩中文字幕一区二区三区 | 中文在线一区二区| 成人激情午夜影院| 一区二区欧美视频| 日韩视频在线一区二区| 国产jizzjizz一区二区| 亚洲无线码一区二区三区| 91精品久久久久久蜜臀| 国产九色sp调教91| 亚洲精选在线视频| 欧美一卡在线观看| 成人av午夜电影| 亚洲福利视频一区二区| 精品国产欧美一区二区| eeuss鲁片一区二区三区在线观看 eeuss鲁片一区二区三区在线看 | 日韩久久久精品| 成人黄色av电影| 天堂一区二区在线免费观看| 久久久久97国产精华液好用吗| 91美女精品福利| 久久www免费人成看片高清| 欧美激情综合在线| 精品视频一区二区三区免费| 日本欧美一区二区在线观看| 日韩一区日韩二区| 日韩欧美中文字幕一区| www.日韩精品| 美脚の诱脚舐め脚责91| 国产精品久久久久婷婷二区次| 欧美区在线观看| 成人毛片老司机大片| 五月天中文字幕一区二区| 日本一区二区免费在线观看视频 | 亚洲综合激情小说| 久久色.com| 欧美妇女性影城| 99久久精品99国产精品| 国产一区久久久| 亚洲一区二区三区在线| 日本一区二区成人在线| 日韩久久久精品| 欧美日韩日日摸| 色综合激情五月| 成人免费观看男女羞羞视频| 久久国产精品免费| 午夜激情久久久| 亚洲精品日韩专区silk| 欧美激情在线观看视频免费| 欧美一级免费大片| 欧美日韩一区二区三区视频| 色综合久久中文字幕综合网| 国产精品99久久久久久有的能看| 日本视频一区二区三区| 日日嗨av一区二区三区四区| 亚洲男人天堂av网| 中文字幕一区二区三区av| 亚洲国产精品成人综合| 亚洲精品一线二线三线| 日韩一二三区视频| 欧美一激情一区二区三区| 欧美日韩一卡二卡| 欧美日韩一区二区三区高清| 欧美性生活影院| 色94色欧美sute亚洲13| av电影一区二区| www.日本不卡| 97se亚洲国产综合自在线| 不卡一区在线观看| 不卡视频在线观看| 99久久99久久精品国产片果冻| 成熟亚洲日本毛茸茸凸凹| 国产91精品久久久久久久网曝门| 国产激情视频一区二区在线观看| 国产在线精品一区二区不卡了 | 成人av在线播放网站| av在线不卡观看免费观看| www.av亚洲| 色噜噜狠狠成人中文综合| 欧美视频中文字幕| 欧美日韩国产精品成人| 日韩片之四级片| 久久精品一区二区三区av| 国产精品欧美久久久久一区二区| **欧美大码日韩| 最新欧美精品一区二区三区| 视频一区在线播放| 亚洲大片免费看| 视频在线观看91| 九九**精品视频免费播放| 国产一区在线观看麻豆| 成人福利视频在线看| 色综合网色综合| 欧美日韩精品综合在线| 精品国产区一区| 中文字幕中文字幕中文字幕亚洲无线| 一区二区三区在线影院| 五月婷婷激情综合| 国产精品中文字幕欧美| 99久久综合色| 欧美情侣在线播放| 国产亚洲精品福利| 亚洲欧美视频在线观看| 日韩avvvv在线播放| 国产一区二区久久| 91久久国产最好的精华液| 欧美一区三区二区| 久久久久久免费网| 一区二区三区在线视频播放| 美国十次综合导航| 97精品国产露脸对白| 日韩免费性生活视频播放| 国产精品国产三级国产普通话蜜臀| 亚洲成人免费在线| 国产成a人无v码亚洲福利| 欧美日韩在线播| 国产精品久久久久久久岛一牛影视| 亚洲成人动漫精品| 成人国产电影网| 日韩天堂在线观看| 亚洲影视资源网| 白白色亚洲国产精品| 精品久久人人做人人爽| 一区二区三区中文在线观看| 国产激情一区二区三区| 欧美精品777| 最好看的中文字幕久久| 国产一区二区三区四| 欧美精品色综合| 中文字幕亚洲欧美在线不卡| 久久99久国产精品黄毛片色诱| 色婷婷精品久久二区二区蜜臀av| 久久亚洲精华国产精华液| 亚洲综合成人在线视频| 色综合天天综合狠狠| 久久理论电影网| 日产精品久久久久久久性色| 9人人澡人人爽人人精品| 337p粉嫩大胆色噜噜噜噜亚洲| 亚洲va天堂va国产va久| 91蜜桃在线观看| 中文字幕一区二区三区在线播放| 国产一区二区视频在线| 欧美变态口味重另类| 成人av在线看| 国产午夜精品久久久久久免费视 | 久久国产精品色婷婷| 884aa四虎影成人精品一区| 亚洲欧美日韩综合aⅴ视频| www.在线成人| 中文字幕亚洲不卡| 成人午夜视频在线观看| 久久精品亚洲乱码伦伦中文| 激情深爱一区二区| 欧美tk丨vk视频| 美女国产一区二区| 精品欧美一区二区久久| 麻豆精品在线看| 欧美一级理论片| 久久av资源站| 亚洲精品一区二区三区福利 | 成人丝袜高跟foot| 国产日韩欧美a| 国产精品99久久久| 国产日产欧美一区二区视频| 成人网页在线观看| 综合久久久久久| 欧美日韩中字一区| 日韩精品欧美精品| 欧美一区二区在线观看| 麻豆精品久久久| 精品欧美一区二区久久| 国产电影一区二区三区| 欧美国产日韩a欧美在线观看| 成人开心网精品视频| 亚洲欧美偷拍三级| 欧美日韩不卡在线| 激情六月婷婷综合| 国产精品激情偷乱一区二区∴| 色婷婷av久久久久久久| 无吗不卡中文字幕| 欧美精品一区男女天堂| 春色校园综合激情亚洲| 一区二区三区在线视频观看| 日韩一区二区三区四区五区六区 | 国产精品国产三级国产有无不卡 | 国产精品久久免费看| 在线中文字幕不卡| 美腿丝袜亚洲三区|