Пример #1
0
 //初始步骤
 public void initialize()
 {
     Debug.Log("Gaming initialize");
     isGaming = true;
     life     = 1;
     score    = 0;
     //如果是在线游戏
     if (gameStatus == Constant.GAME_ONLINE)
     {
         //初始化本地玩家状态对象
         playerStatus = new PlayerStatus(playerInfo.id);
         //获取第一页地图
         if (platformInfoQueue.Count <= Constant.MIN_COUNT_OF_PLATFROM_INFO_QUEUE)
         {
             HTTPUtil.getPlatformInfo();
         }
         //初始化远程玩家doodle对象
         playerNum = team.players.Length;
         if (playerNum >= 2)
         {
             playerStatuses = new PlayerStatus[playerNum - 1];
             remoteDoodle   = Doodle.create(getTeamPlayerDoodleType());
             remoteDoodle.gameObject.name = "RemoteDoodle";
             remoteDoodle.isDirvedLocal   = false;
         }
         StatusWorker.work();
     }
     //初始化本地玩家doodle对象
     doodle = Doodle.create(
         doodleType
         );
     //完成初始化
     isInitialized = true;
     UIManager.INSTANCE.loadPlayerPanel();
 }
Пример #2
0
 void Update()
 {
     if (isInitialized)
     {
         //在线游戏时,定时推送和获取用户状态
         if (gameStatus == Constant.GAME_ONLINE)
         {
             //检查地图信息队列,如果数量小于设定的最小值,则从服务器下载地图信息,并加入队列
             if (platformInfoQueue.Count <= Constant.MIN_COUNT_OF_PLATFROM_INFO_QUEUE)
             {
                 HTTPUtil.getPlatformInfo();
             }
             //更新本地玩家的状态
             playerStatus.c = playerInfo.coin;
             playerStatus.l = life;
             playerStatus.x = doodle.transform.position.x;
             playerStatus.y = doodle.transform.position.y;
             playerStatus.d = (int)(doodle.transform.localScale.x / Mathf.Abs(doodle.transform.localScale.x));
             try {
                 if (playerNum >= 2)
                 {
                     //绘制远程玩家doodle
                     remoteDoodle.transform.Translate(
                         new Vector3(playerStatuses [0].x, playerStatuses [0].y, 0F)
                         -
                         remoteDoodle.transform.position
                         );
                     Debug.Log("playerStatuses [0].d " + playerStatuses [0].d);
                     if (playerStatuses [0].d < 0)
                     {
                         remoteDoodle.changeSkinDirection();
                     }
                 }
             } catch (System.Exception e) {
                 Debug.Log(e.Message);
             }
         }
         //判断死亡和游戏结束
         if (isGaming)
         {
             //生成地面
             spawnPlatform();
             //判定生命
             if (doodle.transform.position.y <
                 Camera.main.transform.position.y -
                 Constant.SCENE_HEIGHT / 2 ||
                 life <= 0)
             {
                 //生命减1
                 life--;
                 //判断生命是否大于等于1
                 if (life >= 1)
                 {
                     doodle.rebirth();
                 }
                 else
                 {
                     //生命小于1,游戏结束
                     finalize();
                 }
             }
         }
     }
 }