Beispiel #1
0
        private void InitGame()
        {
            _player.Init();
            _player.onFire        = OnFire;
            _player.onDie         = OnDie;
            _player.onUpdateLives = OnUpdateLives;
            StartCoroutine(Timer(Const.OBJECT_CREATE_INTERVAL));

            _scoreTxt = _hud.transform.Find("ScoreTxt").GetComponent <Text>();
        }
Beispiel #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;
        }