Beispiel #1
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;
        }
Beispiel #2
0
        public override void CommitGameStates()
        {
            lock (gameStatesToCommit)
            {
                for (int i = 0; i < gameStatesToCommit.Count; ++i)
                {
                    GameData gameState = gameStatesToCommit[i];
                    if (gameState != null)
                    {
                        switch (gameState.Type)
                        {
                            case GameData.GameDataType.Movement:
                                GameState.entities[gameState.TransformData.EntityID].transform = gameState.TransformData.GetMatrix();
                                break;
                            /*case GameData.GameDataType.PlayerTransform:
                                GameState.entities[players[gameState.TransformData.EntityID].EntityID].transform = gameState.TransformData.GetMatrix();
                                break;*/
                            case GameData.GameDataType.NewEntity:
                                //hack, need to use something more than TransformData
                                //assuming TestMan for now

                                TestMan testMan = new TestMan(GameState.root, false, gameState.EntityData.transformData.EntityID);
                                testMan.transform = gameState.EntityData.transformData.GetMatrix();
                                break;
                            case GameData.GameDataType.EntityStateChange:
                                EntityStateData esd = gameState.EntityStateData;
                                Entity e = GameState.entities[esd.EntityID];

                                if (e is MobileEntity)
                                {
                                    esd.apply((MobileEntity)e);
                                }
                                else
                                {
                                    esd.apply(e);
                                }

                                break;
                            default:
                                // throw new NotImplementedExption("Received unexpected gamestate");
                                break;
                        }

                    }
                }
                gameStatesToCommit.Clear();
            }
            return;
        }
Beispiel #3
0
        /// <summary>
        /// After choosing the level and number of players, start the game by sending everyone the level and a player ID
        /// </summary>
        public void SetupAndSendGameState(int levelID)
        {
            Level level = new Level(GameState.root, LevelPack.levels[levelID]);

            // Create players in personal state
            for (int i = 0; i < players.Length; i++)
            {
                SpawnPointEntity sp = level.spawnPoints[i];
                TestMan tm = new TestMan(sp);
            /*=======
            // Send level and a player ID to each client
            for (int i = 0; i < players.Length; i += 1)
            {
                Player player = GetPlayer(i);
                if (player != null)
                {
                    Network.SendGameData(new GameData(GameData.GameDataType.InitClientState, player.PlayerID, levelID), PlayerToConnectionID(player));

                    // Create a new testman at the given spawn point for each player
                    SpawnPointEntity sp = level.spawnPoints[i];
                    TestMan tm = new TestMan(sp);
                }
            >>>>>>> master*/
            }
            return;
        }