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

? 歡迎來(lái)到蟲(chóng)蟲(chóng)下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲(chóng)蟲(chóng)下載站

?? world.java

?? 《J2ME Game Programming》隨書(shū)光盤(pán)源代碼
?? JAVA
字號(hào):

import net.jscience.math.kvm.MathFP;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;


public class World
{
   public static final int TILE_WIDTH=32;
   public static final int TILE_HEIGHT=32;

   public static final int TILE_WIDTH_FP = MathFP.toFP(TILE_WIDTH);
   public static final int TILE_HEIGHT_FP = MathFP.toFP(TILE_HEIGHT);

	public static final int TILE_HALF_HEIGHT = TILE_HEIGHT / 2;
	public static final int TILE_HALF_WIDTH = TILE_WIDTH / 2;

   private int tilesWide = 20;
   private int tilesHigh = 20;
   private byte[][] tileMap;

   private int viewWidth;
   private int viewHeight;

	// tile types
	public static final byte NO_TILE = 0;
   private long lastCycleTime;

   // raytracer
   private int columnsPerDegree;

   static int[] lookupDistortionFP;

   private int projWallHeight;

   static int WALL_HEIGHT = TILE_WIDTH*2;  // makes walls twice as high as
                                           // they are wide
   static int PROJ_PLANE_HEIGHT = 128;
   static int PROJ_PLANE_HEIGHT_CENTER = PROJ_PLANE_HEIGHT/2;
   static int EDGE_IGNORE_FP = MathFP.toFP(5);
   static int HORIZON_DISTANCE_FP = MathFP.toFP(TILE_WIDTH * 10 * 2);

   private int focalDistance;
   private int fovColumns;
   private int halfFovColumns;   // precalced cause we use it a bit

   private Image background;
   private Actor player;

   // lookup table for trig values (0 to 359)
   public static int[] lookupCosFP = new int[360];
   public static int[] lookupSinFP = new int[360];
   public static int[] lookupTanFP = new int[360];

   // static init
   {
      for (int i = 0; i < 360; i++)
      {
         // build an array of precalculated trig values (much faster to just
         // look them up here) note we add 0.01 to avoid all divide by zero
         // cases.
         lookupCosFP[i] = MathFP.cos(MathFP.add(MathFP.toFP("0.01"), Actor.getRadiansFPFromAngle(i)));
         lookupSinFP[i] = MathFP.sin(MathFP.add(MathFP.toFP("0.01"), Actor.getRadiansFPFromAngle(i)));
         lookupTanFP[i] = MathFP.tan(MathFP.add(MathFP.toFP("0.01"), Actor.getRadiansFPFromAngle(i)));
      }
  }


   public World(int viewWidthArg, int viewHeightArg, Actor p)
   {
      player = p;
      viewWidth = viewWidthArg;
      viewHeight = viewHeightArg;

      // calculate field of view (60 degrees is ideal, but we need to base
      // it on how many columns we can display in terms of pixels
      columnsPerDegree = viewWidth / 60;
      fovColumns = viewWidth / columnsPerDegree;
      halfFovColumns = fovColumns / 2;

      // calculate the focal distance
      int distFP = MathFP.div( MathFP.toFP(viewWidth/2), lookupTanFP[halfFovColumns] );
      focalDistance = MathFP.toInt(distFP);

      projWallHeight =  MathFP.toFP(WALL_HEIGHT * focalDistance);

      //#ifdef debug
      System.out.println("Focal distance: " + focalDistance);
      System.out.println("FOV columns: " + fovColumns);
      System.out.println("Degrees per column: " + columnsPerDegree);
      //#endif

      // precalculate the distortion values
      lookupDistortionFP = new int[fovColumns+1];
      for (int i = -halfFovColumns; i <= halfFovColumns; i++)
         lookupDistortionFP[i+halfFovColumns] =
                 MathFP.div(MathFP.toFP(1),
                 MathFP.cos(Actor.getRadiansFPFromAngle(i)));

      // some pretty clouds
      background = ImageSet.loadClippedImage("/background.png", 0, 0);

      // setup the map
      tileMap = new byte[20][20];

      // side walls
      for (int tx=0; tx < 20; tx++)
      {
         tileMap[0][tx] = 1;
         tileMap[19][tx] = 1;
      }

      // top and bottom walls
      for (int ty=0; ty < 20; ty++)
      {
         tileMap[ty][0] = 1;
         tileMap[ty][19] = 1;
      }

      // pillars every four tiles
      for (int ty=0; ty < 20; ty+=4)
         for (int tx=0; tx < 20; tx+=4)
            tileMap[ty][tx] = 1;

   }

   protected final void cycle()
   {
      if (lastCycleTime > 0)
      {
         long msSinceLastCycle = System.currentTimeMillis() - lastCycleTime;
         player.cycle(msSinceLastCycle);
      }

      lastCycleTime = System.currentTimeMillis();
   }



	public final int getTileXCenter(int x)
	{
		return (getTileX(x) * TILE_WIDTH) + (TILE_WIDTH / 2);
	}

	public final int getTileYCenter(int y)
	{
		return (getTileY(y) * TILE_HEIGHT) + (TILE_HEIGHT / 2);
	}

	public final int getTileX(int x) { return x / TILE_WIDTH; }
	public final int getTileY(int y) { return y / TILE_HEIGHT; }

   public final byte getTile(int x, int y)
	{
		int tx = getTileX(x);
		int ty = getTileY(y);
		if (tx < 0 || tx >= tilesWide || ty < 0 || ty >= tilesHigh) return -1;
      return tileMap[ ty ][ tx ];
	}

   private boolean isWall(int px, int py)
   {
      if ( getTile( px, py ) == 1)
         return true;
      return false;
   }

   private boolean isOnMap(int px, int py)
   {
      if (px < 0 || py < 0) return false;
      if (px > TILE_WIDTH * tilesWide) return false;
      if (py > TILE_HEIGHT * tilesHigh) return false;
      return true;
   }

   private int angleChange(int a, int change)
   {
      int angle = a + change;
      if (angle > 359) angle -= 360;
      if (angle < 0) angle = 360 - Math.abs(angle);
      return angle;
   }

   private int getDistanceFP(int dxFP, int dyFP, int angle)
   {
      int distanceFP = 0;
      if ( MathFP.abs(dxFP) > MathFP.abs(dyFP) )
         distanceFP = MathFP.div(MathFP.abs(dxFP), lookupCosFP[angle]);
      else
         distanceFP = MathFP.div(MathFP.abs(dyFP), lookupSinFP[angle]);
      return MathFP.abs(distanceFP);
   }

   private static boolean lastHitWasVert=false;

   public final void render(Graphics g)
   {
      // draw the background
      g.drawImage(background, 0, 0, Graphics.TOP|Graphics.LEFT);

      /////////////////////////////////////////////////////////////////////////
      // RAYCASTING
      /////////////////////////////////////////////////////////////////////////

      int startingXFP = MathFP.toFP(player.getX());
      int startingYFP = MathFP.toFP(player.getY());
      int startingX = player.getX();
      int startingY = player.getY();

      int rayAngle=angleChange(player.getDirection(), halfFovColumns);
      int pixelColumn = 0;
      int destinationXFP=0,destinationYFP=0;
      int originXFP=0,originYFP=0;

      for (int castColumn=0; castColumn < fovColumns; castColumn++)
      {
         rayAngle = angleChange(rayAngle, -1);

         // --------------- HORIZONTAL RAY ------------------
         // try casting a horizontal line until we get a hit

         boolean gotHorizHit = false;
         int horizDistanceFP = 0;

         // if the ray can possibly hit a horizontal line
         if (rayAngle != 0 && rayAngle != 180)
         {
            // cast the first ray to the intersection point
            // figure out the coord of the vert tile line we're after
            // (based on whether we're looking left or right). Note we offset
            // by one pixel so we know we're *inside* a tile cell
            if (rayAngle > 180)
               originYFP = MathFP.toFP( (((startingY / TILE_HEIGHT) +1) * TILE_HEIGHT) + 1 );
            else
               originYFP = MathFP.toFP(((startingY / TILE_HEIGHT) * TILE_HEIGHT) - 1);

            destinationYFP = MathFP.sub(startingYFP, originYFP);
            destinationXFP = MathFP.div(destinationYFP, lookupTanFP[rayAngle]);
            originXFP = MathFP.add(startingXFP, destinationXFP);

            // get the distance to the first grid cell
            horizDistanceFP = getDistanceFP(destinationXFP, destinationYFP, rayAngle);

            while (!gotHorizHit)
            {
               // abort if we're past the horizon
               if (horizDistanceFP > HORIZON_DISTANCE_FP) break;

               // did we hit a wall?
               if (isWall(MathFP.toInt(originXFP), MathFP.toInt(originYFP)))
               {
                  gotHorizHit = true;
                  break;
               }

               // are we still on the map?
               if (!isOnMap(MathFP.toInt(originXFP), MathFP.toInt(originYFP)))
                  break;

               int lastXFP = originXFP;
               int lastYFP = originYFP;

               // project to the next point along
               if (rayAngle > 180)  // if ray going down
                  originYFP = MathFP.add(lastYFP, TILE_HEIGHT_FP);
               else                 // if ray going up
                  originYFP = MathFP.sub(lastYFP, TILE_HEIGHT_FP);

               destinationYFP = MathFP.sub(lastYFP, originYFP);
               destinationXFP = MathFP.div(destinationYFP, lookupTanFP[rayAngle]);

               // move out to the next tile position
               originXFP = MathFP.add(lastXFP, destinationXFP);

               // add the distance to our running total
               horizDistanceFP = MathFP.add(horizDistanceFP,
                                            getDistanceFP(destinationXFP, destinationYFP, rayAngle));
            }
         }

         if (gotHorizHit)
         {
            // got a hit, lets work out what position along the cell wall the
            // ray struck (disabled because it's not being used)
            //cellPos = MathFP.toInt(ixFP) % TILE_HEIGHT;
         }
         else
            // make sure we dont think this is the closest (otherwise it would
            // still be 0)
            horizDistanceFP = MathFP.toFP(99999);

         // --------------- VERTICAL RAY ------------------
         boolean gotVertHit = false;
         int vertDistanceFP = 0;

         // if the ray can possibly hit a vertical line
         if (rayAngle != 90 && rayAngle != 270)
         {
            // cast the first ray to the intersection point

            // figure out the coord of the vert tile line we're after
            // (based on whether we're looking left or right). Note we offset
            // by one pixel so we know we're *inside* a tile cell

            if (rayAngle < 90 || rayAngle > 270)   // if ray going right
               originXFP = MathFP.toFP((((startingX / TILE_WIDTH) +1) *
                                        TILE_WIDTH) + 1);
            else                             // if ray going left
               originXFP = MathFP.toFP(((startingX / TILE_WIDTH) *
                                        TILE_WIDTH) - 1);

            destinationXFP = MathFP.sub(originXFP, startingXFP);
            destinationYFP = MathFP.div(destinationXFP,
                                        lookupTanFP[angleChange(rayAngle,-90)]);
            originYFP = MathFP.add(startingYFP, destinationYFP);

            // get the distance to the first grid cell
            vertDistanceFP = getDistanceFP(destinationXFP, destinationYFP,
                                           rayAngle);

            while (!gotVertHit)
            {
               if (vertDistanceFP > HORIZON_DISTANCE_FP) break;

               // did we hit a wall?
               if (isWall(MathFP.toInt(originXFP), MathFP.toInt(originYFP)))
               {
                  gotVertHit = true;
                  break;
               }

               if (!isOnMap(MathFP.toInt(originXFP), MathFP.toInt(originYFP)))
                  break;

               int lastXFP = originXFP;
               int lastYFP = originYFP;

               // project to the next point along
               if (rayAngle < 90 || rayAngle > 270)   // if ray going right
                  originXFP = MathFP.add(lastXFP, TILE_WIDTH_FP);
               else
                  originXFP = MathFP.sub(lastXFP, TILE_WIDTH_FP);

               destinationXFP = MathFP.sub(originXFP, lastXFP);
               destinationYFP = MathFP.div(destinationXFP,
                                           lookupTanFP[angleChange(rayAngle,-90)]);
               originYFP = MathFP.add(lastYFP, destinationYFP);

               // extend out the distance (so we know when we're casting
               // beyond the world edge)
               vertDistanceFP = MathFP.add(vertDistanceFP, getDistanceFP(
                       destinationXFP, destinationYFP, rayAngle));
            }
         }

         if (gotVertHit)
         {
            // got a hit, lets work out what position along the cell wall the
            // ray struck
            //cellPos = MathFP.toInt(iyFP) % TILE_WIDTH;
         }
         else // make sure we dont think this is the closest
            vertDistanceFP = MathFP.toFP(99999);

         // -------------- DRAW WALL SLICE ------------------

         // since it's possible (especially with nearby walls) to get a ray
         // hit on both vertical and horizontal lines we have to figure out
         // which one to use (the closest)
         if (gotVertHit || gotHorizHit)
         {
            int distanceFP = MathFP.min(horizDistanceFP, vertDistanceFP);
            int diffFP = MathFP.abs(MathFP.sub(horizDistanceFP, vertDistanceFP));

            boolean wasVerticalHit = true;

            if (horizDistanceFP > vertDistanceFP)
               wasVerticalHit = false;

            if (diffFP <= EDGE_IGNORE_FP)
               // if distance is the same then we hit a corner, we assume the
               // previous dir hit so as to give us a smooth line along walls
               wasVerticalHit = lastHitWasVert;

            if (wasVerticalHit)
            {
               // VERTICAL EDGE
               if (diffFP > EDGE_IGNORE_FP) lastHitWasVert = true;
               g.setColor(0x777777);
            }
            else
            {
               // HORIZONTAL EDGE
               if (diffFP > EDGE_IGNORE_FP) lastHitWasVert = false;
               g.setColor(0x333333);
            }

            if (lookupDistortionFP[castColumn] > 0 && distanceFP > 0)
               // adjust for distortion
               distanceFP = MathFP.div(distanceFP, lookupDistortionFP[castColumn]);

            if (distanceFP > 0)
            {
               int wallHeight = MathFP.toInt(MathFP.div(projWallHeight, distanceFP));

               int bottomOfWall = PROJ_PLANE_HEIGHT_CENTER + (wallHeight/2);
               int topOfWall = PROJ_PLANE_HEIGHT - bottomOfWall;

               if (bottomOfWall >= PROJ_PLANE_HEIGHT)
                  bottomOfWall = PROJ_PLANE_HEIGHT-1;

               // draw the wall (pixel column)
               g.fillRect(pixelColumn, topOfWall, columnsPerDegree, wallHeight);
            }

            // and move across to the next column position
            pixelColumn += columnsPerDegree;
         }

      }

      //System.out.println("done ----------------------");
   }


}


















?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
不卡的电视剧免费网站有什么| 欧美国产精品一区二区三区| 色婷婷精品久久二区二区蜜臂av| 99久久夜色精品国产网站| 成人开心网精品视频| 成人一区在线看| 欧美亚洲图片小说| 在线观看欧美黄色| 欧美一区二区三区系列电影| 欧美午夜一区二区| 欧美精品一区二区三区视频| 亚洲女同一区二区| 粉嫩久久99精品久久久久久夜| 欧美日本国产一区| 亚洲视频一区二区在线观看| 一区二区三区在线观看视频| 秋霞午夜鲁丝一区二区老狼| 波多野结衣中文字幕一区 | 99综合影院在线| 精品国产乱码久久| 午夜视频在线观看一区二区三区 | 欧美xxxxxxxxx| 亚洲福利电影网| 日本久久电影网| 国产精品全国免费观看高清| 日本欧美一区二区在线观看| 色综合久久综合网欧美综合网| 久久精品亚洲麻豆av一区二区 | 色婷婷久久久久swag精品 | 91黄色在线观看| 亚洲欧美另类久久久精品2019| 久久疯狂做爰流白浆xx| 欧美美女视频在线观看| 亚洲一线二线三线视频| 在线观看国产日韩| 亚洲国产aⅴ成人精品无吗| 日本道色综合久久| 亚洲福利视频导航| 欧美一级二级三级蜜桃| 青青国产91久久久久久| 久久综合狠狠综合| www.欧美.com| 婷婷久久综合九色国产成人| 91精品国产综合久久国产大片| 五月天一区二区三区| 日韩欧美一区电影| 国产91精品欧美| 亚洲综合av网| www国产精品av| 日本韩国精品一区二区在线观看| 亚洲mv大片欧洲mv大片精品| 欧美一级一区二区| 国产不卡免费视频| 午夜精品久久久久久久久| 久久久夜色精品亚洲| 欧美丝袜第三区| 国产高清不卡二三区| 一级特黄大欧美久久久| 国产亚洲短视频| 欧美日韩大陆在线| 成人福利视频网站| 久久99国产精品久久| 亚洲成a人片在线不卡一二三区| 精品国产1区2区3区| 欧美日韩卡一卡二| 91麻豆福利精品推荐| 国产盗摄一区二区| 蜜桃av一区二区| 亚洲成人1区2区| 午夜在线成人av| 亚洲一区二区三区四区的| 国产精品色噜噜| 精品国产污网站| 2欧美一区二区三区在线观看视频 337p粉嫩大胆噜噜噜噜噜91av | 亚洲综合一区二区精品导航| 欧美激情在线一区二区| 国产日韩成人精品| 中文字幕va一区二区三区| 日本一区二区三级电影在线观看| 精品日韩在线观看| 欧美不卡视频一区| 精品国产sm最大网站| 精品国产自在久精品国产| 精品处破学生在线二十三| 精品国产一二三区| 国产精品毛片大码女人| 亚洲三级小视频| 午夜视频一区二区| 久草这里只有精品视频| 欧美三级中文字| 欧美大胆人体bbbb| 亚洲色图在线播放| www.欧美精品一二区| 欧美视频在线不卡| 国产色产综合产在线视频| 依依成人综合视频| 久久99精品久久久久| www.亚洲激情.com| 精品国产乱子伦一区| 亚洲欧美激情在线| 黄色精品一二区| 欧美午夜电影一区| 国产午夜精品一区二区三区视频| 亚洲免费成人av| 成人一区二区三区视频在线观看| 在线免费观看成人短视频| 久久久九九九九| 免费的国产精品| 欧美在线你懂得| 亚洲区小说区图片区qvod| 国产在线精品不卡| 日韩视频国产视频| 日本午夜一区二区| 欧亚洲嫩模精品一区三区| 国产精品久久久久久久久免费桃花 | 中文字幕日韩精品一区 | 日韩一级高清毛片| 性欧美大战久久久久久久久| 在线视频一区二区三| 亚洲精品伦理在线| 精品国产伦一区二区三区免费| 麻豆国产欧美日韩综合精品二区| 91视频91自| 亚洲午夜精品在线| 欧美久久久久久久久| 亚洲影院免费观看| 欧美日韩不卡一区| 青青草97国产精品免费观看无弹窗版| 色婷婷激情久久| 美女久久久精品| 久久亚洲综合av| 99精品视频一区二区三区| 视频一区欧美精品| 欧美精品精品一区| 国产一区二区免费在线| 欧美激情一区在线观看| 99精品视频一区| 蜜臂av日日欢夜夜爽一区| www欧美成人18+| 在线观看一区日韩| 国产美女一区二区| 日韩黄色小视频| 久久久www成人免费毛片麻豆| 不卡一二三区首页| 日本中文字幕一区二区有限公司| 久久久久国产精品麻豆| 欧美主播一区二区三区| 久久国产精品99久久人人澡| 自拍av一区二区三区| 日韩欧美久久久| 欧美日韩在线直播| 99国产一区二区三精品乱码| 美女mm1313爽爽久久久蜜臀| 国产精品福利影院| 国产校园另类小说区| 精品国产伦一区二区三区观看体验 | 中文一区二区完整视频在线观看| 欧洲在线/亚洲| 91色乱码一区二区三区| 丁香五精品蜜臀久久久久99网站 | 欧美一级视频精品观看| 91精品办公室少妇高潮对白| 国产高清精品网站| 国产一区二区福利视频| 久久精品国产久精国产爱| 亚洲成人精品一区二区| 亚洲国产日产av| 婷婷久久综合九色综合绿巨人| 洋洋成人永久网站入口| 亚洲午夜精品久久久久久久久| 色哟哟精品一区| 欧美色成人综合| 欧美一区二区二区| 日韩女优av电影| 久久久午夜精品理论片中文字幕| 2020国产精品| 成人欧美一区二区三区小说| 中文字幕佐山爱一区二区免费| 亚洲视频免费观看| av激情综合网| 欧美日韩你懂得| 久久久91精品国产一区二区精品 | 91福利小视频| 337p亚洲精品色噜噜| 欧美电视剧在线看免费| 国产精品久久久久一区二区三区共| 国产精品免费网站在线观看| 亚洲精品欧美激情| 久久成人综合网| 丰满岳乱妇一区二区三区| 色综合久久天天综合网| 日韩一区二区在线观看| 亚洲国产精品传媒在线观看| 亚洲欧美日韩电影| 国产乱国产乱300精品| 制服丝袜一区二区三区| 亚洲视频1区2区| 国产剧情一区在线| 中文字幕中文字幕在线一区| 亚洲影视在线播放|