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

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

?? world.java

?? 《J2ME Game Programming》隨書光盤源代碼
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
/**
 * A game world (or level) contains two layers of entities: unmoving tiles
 * drawn in the background and dynamic actors drawn over the top. Levels are
 * generated usign the LevelGenerator. Note that certain tile types can
 * become Actors when they are encountered by the player.
 */

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.rms.*;
import java.io.*;

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 tilesWide;
   private int tilesHigh;
   private int viewWidth;
   private int viewHeight;

   // tile types
   public static final byte NO_TILE = 0;
   public static final byte START_REAL_TILE = 1;
   public static final byte WALL_TILE = 1;
   public static final byte GATEWAY_TILE = 2;
   public static final byte END_REAL_TILE = 2;
   // activator tiles "become" an actor when the player gets in range
   // they're used so we don't have to bother with cycling actors in the
   // world before the player has encountered them.
   public static final byte START_ACTIVATOR_TILE = 100;
   public static final byte DRONE_ACTIVATOR_TILE = 100;
   public static final byte TURRET_ACTIVATOR_TILE = 101;
   public static final byte FIGHTER_ACTIVATOR_TILE = 102;
   public static final byte END_ACTIVATOR_TILE = 102;

   private int viewX;
   private int viewY;

   private int startX;				// start position on tilemap
   private int startY;
   private int levelNum;				// current levelNum player is on

   private Sprite gatewaySprite;	// graphics for gateway to next level

   private byte[][] tileMap;

   private ActorPool enemyShipPool;
   private ActorPool bulletPool;		// given their transient lives we use a pre-built
   // pool of objects
   private long lastCycleTime;
   private Ship playerShip;			// a link to the player's object

   private boolean wantLevelOver;

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

      levelNum = 1;
//tileMap = new int[tilesHigh][tilesWide];

      // load up the tileMap
      Image tileGraphics = ImageSet.loadClippedImage("/world.png", 0, 0, 16, 16);
      tiles = new ImageSet(1);
      tiles.addState(new Image[]{tileGraphics}, 0);

      // construct the objects pools for ships and bullets
      Ship ships[] = new Ship[20];
      for (int i = 0; i < ships.length; i++)
         ships[i] = new Ship(this);
      enemyShipPool = new ActorPool(ships);

      Bullet bullets[] = new Bullet[20];
      for (int i = 0; i < bullets.length; i++)
         bullets[i] = new Bullet(this);
      bulletPool = new ActorPool(bullets);

      gatewaySprite = new Sprite(Ship.getShieldImageSet(), 0, 0);
   }

   /**
    * Generate a new level (creates a new map, resets all actors then saves
    * the level data to RMS)
    */
   public void generateLevel()
   {
      restart();
      LevelGenerator lg = new LevelGenerator();
      tileMap = lg.generateLevel(levelNum);

      tilesWide = tileMap[0].length;
      tilesHigh = tileMap.length;

      startX = lg.getPlayerStartX();
      startY = lg.getPlayerStartY();

      playerShip.setStartingPos(startX * TILE_WIDTH, startY * TILE_HEIGHT);
      playerShip.setX(startX * TILE_WIDTH);
      playerShip.setY(startY * TILE_HEIGHT);

      // save the level to the RMS
      saveLevel();
   }

   public int getLevelNum()
   {
      return levelNum;
   }

   public void setLevelNum(int levelNum)
   {
      this.levelNum = levelNum;
   }

   public final Bullet getBulletFromPool()
   {
      return (Bullet) bulletPool.getNextFree();
   }

   public final void releaseBullet(Bullet b)
   {
      b.deactivate();
      bulletPool.release(b);
   }

   public final Ship getEnemyShipFromPool()
   {
      return (Ship) enemyShipPool.getNextFree();
   }

   public final void releaseShip(Ship s)
   {
      s.deactivate();
      enemyShipPool.release(s);
   }

   /**
    * @return The player's Actor.
    */
   public final Ship getPlayerShip()
   {
      return playerShip;
   }

   /**
    * @param a The Actor object that represents the player in the game.
    */
   public final void setPlayerShip(Ship a)
   {
      playerShip = a;
   }

   /**
    * Set the current view port position (relative to world coordinates).
    * @param viewXArg The x position of the view.
    * @param viewYArg The y position of the view.
    */
   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
      final int t1 = getTile(x, y);

      if (w == 1 && h == 1)
      {
         // faster version if the object is one pixel
         if (t1 >= START_REAL_TILE && t1 <= END_REAL_TILE)
         {
            hitter.onCollision(null);
            return true;
         }
      }
      else
      {
         // otherwise we check all four corners
         final int t2 = getTile(x + w, y);
         final int t3 = getTile(x, y + h);
         final int t4 = getTile(x + w, y + h);

         if ((t1 >= START_REAL_TILE && t1 <= END_REAL_TILE) ||
                 (t2 >= START_REAL_TILE && t2 <= END_REAL_TILE) ||
                 (t3 >= START_REAL_TILE && t3 <= END_REAL_TILE) ||
                 (t4 >= START_REAL_TILE && t4 <= END_REAL_TILE))
         {
            if (t1 == GATEWAY_TILE || t2 == GATEWAY_TILE ||
                    t3 == GATEWAY_TILE || t4 == GATEWAY_TILE)
            {
               if (hitter == playerShip)
               {
                  GameScreen.getGameScreen().notifyLevelOver();
               }
            }
            else
            {
               hitter.onCollision(null);
               return true;
            }
         }
      }

      // if this is the playerShip then we check if we hit another
      // enemy ship (we don't care if enemy ships hit each other)
      if (hitter == playerShip)
      {
         Actor a = enemyShipPool.getFirstUsed();
         while (a != null)
         {
            if (a.isCollidable() && a.isCollidingWith(playerShip))
            {
               a.onCollision(playerShip);
               playerShip.onCollision(a);
               return true;
            }
            a = a.getNextLinked();
         }
      }

      // if this is a bullet then we test if its hit any of the enemy ships
      // (we do the playerShip at the end)
      if (hitter.isBullet())
      {
         // if i was fired by the player, then test against enemy
         if (hitter.getOwner().getType() == Actor.PLAYER_SHIP)
         {
            Actor a = enemyShipPool.getFirstUsed();
            while (a != null)
            {
               if (a.isCollidable() && a.isCollidingWith(hitter))
               {
                  // enemy bullets only hit enemy ships
                  hitter.onCollision(a);
                  a.onCollision(hitter);
                  return true;
               }
               a = a.getNextLinked();
            }
         }
         else
         {
            // bullet fired by an enemy, test against the player
            if (playerShip.isCollidable() && playerShip.isCollidingWith(hitter))
            {
               hitter.onCollision(playerShip);
               playerShip.onCollision(hitter);
               return true;
            }
         }
      }
      return false;
   }

   protected final void cycle(long msSinceLastCycle)
   {
      if (msSinceLastCycle > 0)
      {
         // cycle all the (used) ship objects from the enemyShipPool
         Actor a = enemyShipPool.getFirstUsed();
         while (a != null)
         {
            a.cycle(msSinceLastCycle);
            a = a.getNextLinked();
         }

         gatewaySprite.cycle(msSinceLastCycle);
         playerShip.cycle(msSinceLastCycle);

         //if (GameScreen.getGameScreen().getLevelNum() > 1)
         //	System.out.println("pos=" + playerShip.getX() + ", " + playerShip.getY());

         // now cycle all the bullets (we only cycle used ones)
         Actor bullet = bulletPool.getFirstUsed();
         while (bullet != null)
         {
            bullet.cycle(msSinceLastCycle);
            bullet = bullet.getNextLinked();
         }
      }

      lastCycleTime = System.currentTimeMillis();

      if (wantLevelOver)
      {
         GameScreen.getGameScreen().notifyLevelOver();
         wantLevelOver = false;
      }
   }


   /**
    * Restart the level
    */
   public void restart()
   {
      // reset all the ships (used only of course)
      Ship s = (Ship) enemyShipPool.getFirstUsed();
      while (s != null)
      {
         Actor next = s.getNextLinked();

         // Final check used to remove any inactive or exploding actors.
         // This can happen sometimes if actors were not given enough time
         // to complete their death sequence before this restart method was
         // called. For example, if the player collides with an enemy ship
         // before dying it wont have time to finish its exploding state and
         // suicide before we get this call in here. Without this check we
         // could end up with floating, half-dead phantom objects.
         if (!s.isVisible() || s.isExploding())
            releaseShip(s);
         else
            s.reset();

         s = (Ship) next;
      }
      playerShip.reset();

      // release all the bullets
      Actor a = bulletPool.getFirstUsed();
      while (a != null)
      {
         Actor next = a.getNextLinked();
         releaseBullet((Bullet) a);
         a = next;
      }

   }

   /**
    * Clear all actors from the levelNum
    */
   public void clear()
   {
      // reset all the ships (used only of course)
      Actor a = enemyShipPool.getFirstUsed();
      while (a != null)
      {
         Actor next = a.getNextLinked();
         releaseShip((Ship) a);
         a = next;
      }
      playerShip.reset();

      // release all the bullets
      a = bulletPool.getFirstUsed();
      while (a != null)
      {
         Actor next = a.getNextLinked();
         releaseBullet((Bullet) a);
         a = next;
      }

   }

   public final int getTileAtX(int x)
   {
      return x / TILE_WIDTH;
   }

   public final int getTileAtY(int y)
   {
      return y / TILE_HEIGHT;
   }

   public final int getTileCenterPosX(int x)
   {
      return (getTileAtX(x) * TILE_WIDTH) + (TILE_WIDTH / 2);
   }

   public final int getTileCenterPosY(int y)
   {
      return (getTileAtY(y) * TILE_HEIGHT) + (TILE_HEIGHT / 2);

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成av人片一区二区| 国内精品久久久久影院薰衣草| 在线观看日韩电影| 亚洲va天堂va国产va久| 欧美一级专区免费大片| 久久精品国产77777蜜臀| 国产亚洲视频系列| av欧美精品.com| 亚洲综合网站在线观看| 欧美日韩成人综合在线一区二区| 日本免费在线视频不卡一不卡二| 精品福利二区三区| 成人免费视频app| 亚洲综合免费观看高清在线观看 | 国产精品996| 亚洲国产精品99久久久久久久久| 91免费小视频| 日韩av中文在线观看| 久久久国产精品午夜一区ai换脸| av中文字幕亚洲| 天天影视网天天综合色在线播放| 久久先锋资源网| 欧洲精品视频在线观看| 麻豆久久一区二区| 亚洲乱码国产乱码精品精小说| 91精品国产欧美一区二区18| 国产iv一区二区三区| 亚洲不卡av一区二区三区| 久久青草国产手机看片福利盒子| 91在线观看地址| 久久国产精品一区二区| 亚洲人成网站色在线观看 | 日韩欧美一级二级三级| 91视视频在线直接观看在线看网页在线看 | 欧美一区二区在线播放| 国产成人在线色| 婷婷综合五月天| 中文字幕一区二区在线观看| 日韩一二三四区| 在线免费观看一区| 国产精品中文有码| 日韩电影一区二区三区| 亚洲欧美日韩精品久久久久| 亚洲精品一区二区精华| 欧美丝袜第三区| 99视频有精品| 国产精品一区二区男女羞羞无遮挡| 亚洲一二三专区| 国产精品热久久久久夜色精品三区 | 99精品久久久久久| 国产一区二区三区av电影| 亚洲成av人片一区二区| 亚洲精品视频免费看| 国产午夜亚洲精品不卡| 日韩三级.com| 欧美一区二区网站| 精品视频全国免费看| 91福利精品视频| 成人av综合在线| 成人午夜免费av| 国产乱人伦偷精品视频不卡| 蜜臀av性久久久久蜜臀av麻豆| 亚洲一区二区三区四区五区黄| 中文字幕一区二区三区精华液| 精品国产一区a| 日韩精品中文字幕在线不卡尤物 | 日本精品免费观看高清观看| 国产91在线观看| 国产乱人伦偷精品视频免下载| 久久99久久99| 黑人精品欧美一区二区蜜桃 | 中文字幕av一区二区三区高| 欧美xfplay| 精品国产在天天线2019| 精品国产免费人成在线观看| 日韩精品一区在线观看| 欧美变态口味重另类| 亚洲精品一区二区三区香蕉| 精品成人在线观看| 国产性天天综合网| 国产精品丝袜久久久久久app| 久久精品综合网| 国产精品剧情在线亚洲| 亚洲丝袜精品丝袜在线| 一二三四区精品视频| 亚洲制服欧美中文字幕中文字幕| 一区二区三区四区不卡视频| 亚洲在线视频免费观看| 午夜电影一区二区| 美国一区二区三区在线播放| 国产在线精品免费| 成人伦理片在线| 91精品国产综合久久久蜜臀粉嫩| 欧美性高清videossexo| 777奇米四色成人影色区| 精品成人一区二区三区| 亚洲国产精品成人综合| 一区二区三区精密机械公司| 日韩国产成人精品| 欧美久久久一区| 精品日韩欧美在线| 中文字幕 久热精品 视频在线| 欧美视频中文字幕| 五月婷婷另类国产| 激情综合色播激情啊| 成人国产免费视频| 欧美日韩一区二区三区四区| 欧美电影免费观看高清完整版在线观看| 久久综合色8888| 亚洲精品免费看| 久88久久88久久久| 色哟哟国产精品| 日韩一区二区视频在线观看| 国产精品久久久久婷婷| 亚洲va欧美va人人爽| 国产aⅴ精品一区二区三区色成熟| 色天天综合久久久久综合片| 欧美第一区第二区| 亚洲精品日产精品乱码不卡| 久久精品国产一区二区三| 成人黄色小视频| 日韩欧美综合一区| 亚洲专区一二三| 成人午夜av电影| 欧美一级日韩不卡播放免费| 亚洲三级视频在线观看| 麻豆成人91精品二区三区| 色一区在线观看| 国产欧美日韩亚州综合| 亚洲1区2区3区视频| 99精品视频在线观看免费| 日韩视频一区在线观看| 夜夜揉揉日日人人青青一国产精品| 激情综合网av| 717成人午夜免费福利电影| 亚洲天堂福利av| 丰满少妇在线播放bd日韩电影| 欧美一区中文字幕| 亚洲成人免费电影| 91视频精品在这里| 久久人人97超碰com| 免费在线观看日韩欧美| 欧美日韩激情一区| 亚洲欧美日韩中文字幕一区二区三区| 国产一区二区三区香蕉| 欧美精品久久天天躁| 亚洲你懂的在线视频| 成人美女在线视频| 2021国产精品久久精品| 麻豆精品新av中文字幕| 精品视频999| 亚洲成人自拍偷拍| 日本精品免费观看高清观看| 亚洲欧洲性图库| av午夜一区麻豆| 亚洲国产精品99久久久久久久久| 国产一区二区伦理片| 久久综合丝袜日本网| 久久99九九99精品| 久久中文娱乐网| 国产美女在线精品| 久久免费的精品国产v∧| 久久成人羞羞网站| 欧美精品一区二区三区一线天视频| 日韩电影在线观看网站| 欧美一卡二卡在线| 狠狠色丁香九九婷婷综合五月| 日韩精品中文字幕在线不卡尤物| 蜜桃久久久久久| 欧美大片一区二区三区| 久久av老司机精品网站导航| 日韩免费高清av| 国产精品影音先锋| 欧美性感一区二区三区| 欧美本精品男人aⅴ天堂| 精品系列免费在线观看| 日韩欧美美女一区二区三区| 精品一区二区三区在线视频| 欧美精品一区二| 国产成人综合亚洲网站| 国产精品国产成人国产三级| 色婷婷精品大视频在线蜜桃视频| 亚洲精品乱码久久久久久黑人| 欧美午夜一区二区| 日本在线不卡视频| 国产午夜精品福利| 97国产精品videossex| 午夜日韩在线观看| 日韩美女在线视频| 成人免费视频免费观看| 一区二区三区四区不卡视频| 91精品国产91综合久久蜜臀| 国产一区 二区| 国产精品护士白丝一区av| 欧美午夜精品久久久| 美女一区二区三区| 国产精品国产三级国产| 在线播放91灌醉迷j高跟美女| 捆绑调教一区二区三区| 国产精品天美传媒沈樵|