Esempio n. 1
0
        /// <summary>
        /// Create a new piece of GameData from a byte array representation.
        /// </summary>
        /// <param name="byteArray">A byte array to create a GameData packet from.</param>
        public GameData(byte[] byteArray)
        {
            using (MemoryStream memoryStream = new MemoryStream(byteArray))
            {
                using (BinaryReader binaryReader = new BinaryReader(memoryStream))
                {
                    Type = (GameDataType)binaryReader.ReadByte();
                    PlayerID = (int)binaryReader.ReadByte();
                    EventDetail = (int)binaryReader.ReadByte();

                    byte[] subData  = new byte[byteArray.Length - 3];
                    Array.ConstrainedCopy(byteArray, 3, subData, 0, byteArray.Length - 3);

                    if (Type == GameDataType.Movement)
                    {
                        TransformData = new TransformData(subData);
                    }
                    else if (Type == GameDataType.NewEntity)
                    {
                        EntityData = new EntityData(subData);
                    }
                    else if (Type == GameDataType.EntityStateChange)
                    {
                        EntityStateData = new EntityStateData(subData);
                    }
                }
            }

            return;
        }
Esempio n. 2
0
 /// <summary>
 /// Create a new GameData packet.
 /// </summary>
 /// <param name="gameDataType">The type associated with this packet.</param>
 /// <param name="playerId">The id of the player that performed the action.</param>
 /// <param name="eventDetail">The extra detail associated with this event.</param>
 public GameData(GameDataType gameDataType, int playerId = 0, int eventDetail = 0, TransformData transformData = null, EntityData entityData = null)
 {
     Type = gameDataType;
     PlayerID = playerId;
     EventDetail = eventDetail;
     TransformData = transformData;
     EntityData = entityData;
     return;
 }
Esempio n. 3
0
        /// <summary>
        /// After choosing the level and number of players, start the game.
        /// </summary>
        /// <param name="levelID">The ID of the level to initialize.</param>
        /// <param name="myPlayerID">The ID of the player character.</param>
        public void SetupGameState(int levelID, int myPlayerID)
        {
            Level level = new Level(GameState.root, LevelPack.levels[levelID]);

            SpawnPointEntity sp = level.spawnPoints[myPlayerID];
            TestMan tm = new TestMan(sp, true);
            players[myPlayerID].EntityID = tm.id;
            LocalPlayer.EntityID = players[myPlayerID].EntityID;    //hack?

            EntityData entityData = new EntityData(EntityData.EntityType.TestMan, tm.id, tm.transform);
            GameData gameData = new GameData(GameData.GameDataType.NewEntity, myPlayerID, 0, null, entityData);
            Network.SendGameData(gameData);
            return;
        }