コード例 #1
0
ファイル: Game.cs プロジェクト: seanlegg/Asteroids
        public void InitGame()
        {
            currentLevel = 0;

            // Initialize Asteroids
            asteroidManager.Init();

            // Initialize Players
            players.ForEach(delegate(Player p)
            {
                p.Init();
            });
        }
コード例 #2
0
        public void InitGame()
        {
            // Set the starting level
            level = 1;

            // Initialize Asteroids
            if (networkSession == null)
            {
                asteroidManager.Init();
            }
            else
            {
                // Only the host should initialise the asteroid manager
                if (networkSession.IsHost)
                {
                    asteroidManager.Init();
                    {
                        SendGameData();
                    }
                }
                else
                {
                    asteroidManager.Asteroids.Clear();
                }
            }

            // Initialize Players
            if (networkSession == null)
            {
                players.ForEach(delegate(Player p)
                {
                    p.Init();
                });
            }
            else
            {
                int hIndex      = 0; // HUD Region Index
                int spawnRegion = 0;

                foreach (NetworkGamer gamer in networkSession.AllGamers)
                {
                    Player p = gamer.Tag as Player;

                    // Initialise the player
                    p.Init();

                    // Bind the gameOver event to local players
                    if (gamer.IsLocal)
                    {
                        p.onGameOver += OnGameOver;
                    }

                    p.SpawnPosition = spawnPositions[spawnRegion];
                    p.Position      = p.SpawnPosition;

                    p.SpawnRotation = spawnRotations[spawnRegion];
                    p.Rotation      = p.SpawnRotation;

                    // Initialise the HUD
                    p.Score       = 0;
                    p.ScoreRegion = scoreRegions[hIndex];

                    spawnRegion++;
                    hIndex++;
                }
            }

            // Play the background music
            MediaPlayer.Play(backgroundMusic);
            MediaPlayer.Volume = 0.1f;
        }