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

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

?? world.java

?? 大量j2me源代碼
?? JAVA
字號:
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class World
{
   public static final int TILE_HEIGHT=16;
   public static final int TILE_WIDTH=16;
	public static final int TILE_HALF_HEIGHT = TILE_HEIGHT / 2;
	public static final int TILE_HALF_WIDTH = TILE_WIDTH / 2;

   private ImageSet tiles;
   private int tilesDeep = 2;
   private int tilesWide = 50;
   private int tilesHigh = 50;
   private byte[][][] tileMap;
   private Actor[] actorZMap;   // linked list of references to actors updated
                                 // whenever an actor moves (if tile changes)

   private int viewWidth;
   private int viewHeight;

	// tile types
	public static final byte NO_TILE = 0;

	public static final byte GRASS1_TILE = 1;
	public static final byte GRASS2_TILE = 2;
	public static final byte GRASS3_TILE = 3;

	public static final byte TREE_TILE = 4;

   private int viewX;
   private int viewY;

   private long lastCycleTime;
	private Tank playerTank;

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

      tiles = new ImageSet(5);   // 3 x grass, 1 x barrier, 1 x tree

      // add the grass to the world tiles
      Image grassImage = ImageSet.loadClippedImage("/grass.png", 0, 0);
      Image[] grassImages = ImageSet.extractFrames(grassImage, 0, 0, 1, 3, 16, 16);
      for (int i=0; i < 3; i++)
         tiles.addState(new Image[]{grassImages[i]}, 0);

      // add the tree
      Image treeImage = ImageSet.loadClippedImage("/tree.png", 0, 0);
      tiles.addState(new Image[]{treeImage}, 0);

      // setup the map
      tileMap = new byte[tilesDeep][tilesHigh][tilesWide];
      actorZMap = new Actor[tilesHigh];

      // setup the map with grass on the ground layer
      for (int ty=0; ty < tilesHigh; ty++)
      {
         for (int tx=0; tx < tilesWide; tx++)
         {
            // fill with normal grass
            tileMap[0][ty][tx] = (byte)Tools.getRand(GRASS1_TILE, GRASS2_TILE);

            // then randomly add some special grass
            if (Tools.getRand(0, 10)==0)
               tileMap[0][ty][tx] = GRASS3_TILE;

             //now add some trees
            if (Tools.getRand(0, 25)==0)
               tileMap[1][ty][tx] = TREE_TILE;
         }
      }

   }

	public final Tank getPlayerTank()
	{
		return playerTank;
	}

	public final void setPlayerTank(Tank a)
	{
		playerTank = a;

      // clear away any tree tiles around the tank so we are clear when we start
      int sx = getTileX(playerTank.getX());
      int sy = getTileY(playerTank.getY());

      for (int i=0; i < 9; i++)
         tileMap[1][sy+(i/3)][sx+(i%3)] = NO_TILE;

	}

   public final void setView(int viewXArg, int viewYArg)
   {
      viewX = viewXArg;
      viewY = viewYArg;
   }

	public final boolean checkCollision(Actor hitter, int x, int y, int w, int h)
	{
		// test if this actor object has hit a tile on layer 1 (we ignore layer 0)
      // we look at all the tiles under the actor (we do a <= comparison so we
      // include the bounding edge of the actor's rectangle
      for (int iy=y; iy <= y+h; iy += TILE_HEIGHT)
      {
         for (int ix=x; ix <= x+w; ix += TILE_WIDTH)
         {
            if (getTile(1, ix, iy) > 0)
            {
               hitter.onCollision(null);
               return true;
            }
         }
      }

      // now test if this actor hit another actor in this or an adjacent
      // sector
      int sector = getTileY(y);
      Actor weHit = checkSectorCollision(hitter, sector, x, y, w, h);
      if (sector + 1 < actorZMap.length && weHit == null)
         weHit = checkSectorCollision(hitter, sector+1, x, y, w, h);
      if (sector - 1 >= 0 && weHit == null)
         weHit = checkSectorCollision(hitter, sector-1, x, y, w, h);

      if (weHit != null)
      {
         hitter.onCollision(weHit);
         return true;
      }

		return false;
	}

   private Actor checkSectorCollision(Actor hitter, int sector, int x, int y, int w, int h)
   {
      // check to see if we hit another actor in this sector (we ignore ourselves)
      Actor a = actorZMap[sector];
      while (a != null)
      {
         if (a.isCollidingWith(x, y, w, h) && a != hitter)
            return a;
         a = a.getNextInZMap();
      }
      return null;
   }

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

      lastCycleTime = System.currentTimeMillis();
   }

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

	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 byte getTile(int depth, 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[depth][ y / TILE_WIDTH ][ x / TILE_WIDTH ];
	}


   public final void render(Graphics g)
   {
		try
		{
			int startX = (viewX / TILE_WIDTH) - 5;
			int startY = (viewY / TILE_HEIGHT) - 5;
			int tw = ((Math.abs(viewX) + viewWidth) / TILE_WIDTH) + 5;
			int th = ((Math.abs(viewY) + viewHeight) / TILE_HEIGHT) + 5;

			if (tw > tilesWide) tw = tilesWide;
			if (th > tilesHigh) th = tilesHigh;

			int t=0;
			int xpos=0;
			int ypos=0;

         for (int td=0; td < tilesDeep; td++)
         {
            for (int ty=startY; ty < th; ty++)
            {
               for (int tx=startX; tx < tw; tx++)
               {
                  if (ty >= 0 && tx >= 0)
                  {
                     t = tileMap[td][ty][tx];

                     // quick abort if it's nothing and we抮e only doing the
                     // ground layer (no actors to worry about)
                     if (td == 0 && t == NO_TILE) continue;

                     xpos = (tx * TILE_WIDTH)- viewX;
                     ypos = (ty * TILE_HEIGHT) - viewY;

                     if (t > 0)
                     {
                        if (t == TREE_TILE)
                           tiles.draw(g, t-1, 0, xpos-16, ypos-42);
                        else
                           tiles.draw(g, t-1, 0, xpos, ypos);
                     }

                     // if this is the second pass then we draw the actors
                     // at this z-order
                     if (td==1)
                     {
                        Actor a = actorZMap[ty];
                        while (a != null)
                        {
                           // debug rectangle
                           //g.setColor(0xff0000);
                           //g.drawRect(a.getX()-viewX, a.getY()-viewY, a.getWidth(), a.getHeight());

                           a.render(g, viewX, viewY);
                           a = a.getNextInZMap();
                        }
                     }
                  }
               }
            }
			}

		}
		catch (Exception e)
		{
			System.out.println("App exception: " + e);
			e.printStackTrace();
		}
   }

   /**
    * Called by the actor class to notify us an actor changed position. We
    * use this to move the actor to a diff z-order position if their y-tile
    * position changed.
    */

   public void notifyActorMoved(Actor a, int oldX, int oldY, int x, int y)
   {
      // figure out the z-order positions (Y tile position)
      int oldYTilePos = getTileY(oldY);
      int yTilePos = getTileY(y);

      // if they have indeed moved to another sector (vertical row) then
      // we need to move them from one linked list to another
      if (oldYTilePos != yTilePos)
      {
         // go through all the actors in this sector's list until you find
         // this one - try the very fast case first (one item in list)
         if (actorZMap[oldYTilePos] == a && a.getNextInZMap() == null)
            actorZMap[oldYTilePos]=null;
         else
         {
            if (actorZMap[oldYTilePos] != null)
            {
               // we assume in this case that there must be at least two entries
               // in this linked list (since the above test failed)
               Actor actorToRemove = actorZMap[oldYTilePos];
               while (actorToRemove != a && actorToRemove != null)
                  actorToRemove = actorToRemove.getNextInZMap();

               // if there was an entry matching the actor
               if (actorToRemove != null)
               {
                  // set my next's prev to my prev (thus replacing me)
                  if (actorToRemove.getNextInZMap() != null)
                     actorToRemove.getNextInZMap().setPrevInZMap(actorToRemove.getPrevInZMap());
                  // set my prev's next to my next
                  if (actorToRemove.getPrevInZMap() != null)
                     actorToRemove.getPrevInZMap().setNextInZMap(actorToRemove.getNextInZMap());

                  // replace the head of the list if it was removed
                  if (actorZMap[oldYTilePos] == actorToRemove)
                     actorZMap[oldYTilePos] = actorToRemove.getNextInZMap();

                  // **NOTE: we don't bother updating a's next and prev because it will
                  // be fixed up when we add it into another list (this is a move
                  // function, not a remove)
               }
            }
         }

         // add the actor into the new spot. do the empty list case first
         // (the most common case).
         if (actorZMap[yTilePos] == null)
         {
            a.setNextInZMap(null);
            a.setPrevInZMap(null);
            actorZMap[yTilePos] = a;
         } else
         {
            // one or more, find the tail of the list and append this ref
            Actor tail = actorZMap[yTilePos];
            while (tail.getNextInZMap() != null)
               tail = tail.getNextInZMap();
            tail.setNextInZMap(a);

            a.setPrevInZMap(tail);
            a.setNextInZMap(null);
         }
      }

   }

}














?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲欧美日韩精品久久久久| 日韩一二在线观看| 亚洲图片你懂的| 一道本成人在线| 亚洲尤物在线视频观看| 91精品欧美一区二区三区综合在| 午夜久久久影院| 精品动漫一区二区三区在线观看| 国产一区二区精品久久| 国产精品久久777777| 91国偷自产一区二区开放时间 | 奇米影视一区二区三区小说| 91精品国产品国语在线不卡| 国内久久精品视频| 国产精品传媒视频| 欧美电影在线免费观看| 国产一区二区福利视频| 中文字幕在线观看不卡| 欧美三级日韩在线| 国产精品一色哟哟哟| 亚洲免费伊人电影| 日韩一区二区三区四区| 顶级嫩模精品视频在线看| 亚洲麻豆国产自偷在线| 欧美一区二区精品在线| 丁香婷婷综合色啪| 亚洲在线视频网站| 久久在线观看免费| 欧美主播一区二区三区| 精品一区二区三区日韩| 中文字幕视频一区| 欧美一区二区在线播放| 不卡的av在线播放| 久久国产精品第一页| 亚洲精品久久久久久国产精华液 | 日韩精品在线一区| 北岛玲一区二区三区四区| 蜜桃一区二区三区在线| 亚洲三级电影网站| 国产偷国产偷亚洲高清人白洁| 91福利视频在线| 国产精品18久久久久久久久 | 精品在线视频一区| 亚洲影院在线观看| 国产女人aaa级久久久级| 欧美一区二区精美| 91麻豆免费观看| 国产成人午夜电影网| 免费一区二区视频| 亚洲123区在线观看| 亚洲三级小视频| 国产欧美视频一区二区| 日韩亚洲欧美高清| 欧美色综合久久| 91网站在线观看视频| 国产高清一区日本| 国产自产高清不卡| 美腿丝袜一区二区三区| 亚洲成人精品在线观看| 综合激情成人伊人| 国产精品国产a| 国产视频一区二区在线观看| 日韩一区二区在线看| 欧美综合欧美视频| 色哟哟日韩精品| 91网站视频在线观看| www.久久精品| 97精品国产露脸对白| 成人午夜在线视频| 不卡在线视频中文字幕| 成人一区二区视频| 成人国产在线观看| a4yy欧美一区二区三区| www.亚洲色图.com| 99re6这里只有精品视频在线观看| 国产成人免费av在线| 国产成人精品在线看| 国产成人aaa| 成人av电影在线观看| 成人午夜精品在线| 成人精品视频网站| aaa亚洲精品| 欧美这里有精品| 欧美三级在线播放| 91精品婷婷国产综合久久性色| 91精品国产综合久久香蕉麻豆| 欧美精品久久一区二区三区| 日韩一区二区中文字幕| 精品国产乱码久久久久久浪潮| 久久在线观看免费| 亚洲欧洲色图综合| 亚洲香肠在线观看| 免费成人在线观看视频| 国产麻豆精品久久一二三| 成人午夜免费电影| 欧美网站大全在线观看| 日韩一级黄色大片| 国产欧美日韩综合| 亚洲线精品一区二区三区| 青娱乐精品视频在线| 国产乱人伦偷精品视频免下载| 成人av电影免费观看| 在线视频欧美区| 日韩午夜小视频| 国产精品狼人久久影院观看方式| 一区二区三区日韩精品| 日产国产高清一区二区三区| 国产精品99久| 欧美性大战久久久久久久| 日韩三级伦理片妻子的秘密按摩| 精品欧美一区二区在线观看| 中文字幕 久热精品 视频在线| 亚洲黄色性网站| 美腿丝袜亚洲三区| 不卡一区中文字幕| 欧美一区二区免费视频| 中日韩免费视频中文字幕| 亚洲自拍偷拍欧美| 国产一区在线视频| 色偷偷88欧美精品久久久| 精品免费视频一区二区| 亚洲欧洲国产日韩| 韩国精品久久久| 99国产精品久久久久久久久久| 日韩三级免费观看| 亚洲夂夂婷婷色拍ww47 | 久久福利资源站| 色综合久久天天综合网| 精品国产乱码久久久久久夜甘婷婷 | 国产精品一区在线观看乱码| 91久久线看在观草草青青| 精品国产人成亚洲区| 一区二区三区四区不卡在线| 国产精品一区在线观看你懂的| 欧美三级韩国三级日本三斤| 欧美激情中文不卡| 美女网站色91| 欧美午夜在线观看| 国产精品午夜免费| 国产在线观看一区二区| 欧美日韩国产精品自在自线| 国产精品理论在线观看| 精品亚洲国产成人av制服丝袜| 精品视频在线免费观看| 亚洲色图欧美在线| 成人美女视频在线观看18| 精品国产sm最大网站免费看| 三级一区在线视频先锋 | 丁香婷婷深情五月亚洲| 日韩欧美国产电影| 亚洲一卡二卡三卡四卡| 成人av动漫网站| 亚洲国产精品高清| 国产精品一区二区久久精品爱涩| 欧美不卡123| 日本亚洲天堂网| 91精品在线一区二区| 亚洲成人资源网| 欧美亚男人的天堂| 亚洲一区二区不卡免费| 91麻豆精东视频| 亚洲人成小说网站色在线| 99久久夜色精品国产网站| 中文字幕不卡一区| www.久久精品| 玉米视频成人免费看| 在线观看欧美黄色| 亚洲va韩国va欧美va| 欧美高清视频不卡网| 青青草原综合久久大伊人精品| 欧美精品乱码久久久久久| 日本在线不卡一区| 精品国产乱码久久| 国产精品一二三区| 国产精品传媒入口麻豆| 91福利精品视频| 午夜精品视频一区| 日韩欧美成人激情| 国产成人av网站| 亚洲欧美日本韩国| 欧美电影在线免费观看| 久久精品国产免费看久久精品| 久久亚洲私人国产精品va媚药| 国产精品亚洲а∨天堂免在线| 国产精品久久久久影院色老大| 91在线观看高清| 亚洲成人7777| 日韩亚洲国产中文字幕欧美| 久久精工是国产品牌吗| 国产精品情趣视频| 欧美亚洲国产一区二区三区va | 精品福利av导航| av在线不卡网| 亚洲成a人片综合在线| 精品国产一区二区三区久久影院| 成人久久久精品乱码一区二区三区| 怡红院av一区二区三区| 欧美不卡一二三| 色悠悠久久综合| 久久99精品国产麻豆婷婷洗澡|