Ejemplo n.º 1
0
        public override void Initialize()
        {
            base.Initialize();

            background.Rectangle = new Rectangle(0, 0, YnG.Width, YnG.Height);

            timer.Start();
        }
Ejemplo n.º 2
0
        public void UpdateNbCrystals()
        {
            nbItemsCollected++;
            itemsCounter.Text = String.Format("{0} / {1}", new object[] { nbItemsCollected, itemsCount });

            if (!highlightTimer.Enabled)
            {
                itemsCounter.Color = Color.Yellow;
                highlightTimer.Start();
            }
        }
Ejemplo n.º 3
0
        public SplashState(string name)
            : base(name)
        {
            splashScreen = new YnEntity(Assets.TextureSplashScreen);
            Add(splashScreen);

            waitTimer            = new YnTimer(1500, 0);
            waitTimer.Completed += (s, e) => stateManager.SetActive("menu", true);
            waitTimer.Start();
            Add(waitTimer);
        }
Ejemplo n.º 4
0
        public override void Revive()
        {
            base.Revive();

            for (int i = 0; i < _recycled.Length; i++)
            {
                _recycled[i].Clear();
            }

            Clear();

            spawnTimer.Start();
        }
Ejemplo n.º 5
0
        public void Shoot(int type)
        {
            if (_canShoot)
            {
                if (type == 1)
                {
                    PrimaryWeapon weapon;

                    int[] minMax = GetStartEndValues();

                    for (int i = minMax[0]; i <= minMax[1]; i++)
                    {
                        if (_recycled.Count > 0)
                        {
                            weapon = Members.ElementAt(_recycled.Pop()) as PrimaryWeapon;
                            weapon.Reset(_player.Rectangle, i);
                        }
                        else
                        {
                            weapon = new PrimaryWeapon(_primaryWeaponDescription, _player.Rectangle, i);
                            weapon.SetOrigin(SpriteOrigin.Center);
                            weapon.Viewport = _player.Viewport;
                            weapon.Killed  += weapon_Killed;
                            Add(weapon);
                        }

                        weapon.Rotation = MathHelper.ToRadians(_primaryWeaponDescription.Rotations[i]);

                        _shootTimer.Interval = weapon.Interval;
                    }
                }
                else
                {
                    AddSecondaryWeapon();
                }

                _canShoot = false;

                _shootTimer.Start();
            }
        }
Ejemplo n.º 6
0
 public override void ReceiveDamage(Color color)
 {
     Color = color;
     _timerFired.Start();
 }
Ejemplo n.º 7
0
        public SoloPlayerState(SpaceShipType type, LevelType levelType)
            : base("solostate", true)
        {
            _levelType = levelType;

            if (_levelType == LevelType.Interior)
            {
                background = new InteriorBackground();
            }
            else
            {
                background = new SpaceBackground();
            }

            Add(background);

            // Les bonus sont en dessous de tout
            bonusGroup = new YnGroup();
            Add(bonusGroup);

            // Joueur
            _player                   = new SpacePlayer(PlayerIndex.One, Registry.SpaceShipDescriptions[(int)type]);
            _player.Viewport          = background.PlayableViewport;
            _player.Killed           += new EventHandler <EventArgs>(_player_Killed);
            _player.PlayerReallyDead += new EventHandler <EventArgs>(_player_PlayerReallyDead);
            Add(_player);

            Registry.Players = new SpacePlayer[] { _player };
            Registry.ScoreManager.CurrentGameScore = _player.GameScore;

            // Gestionnaire d'ennemies
            _ennemyManager             = new EnnemyManager();
            _ennemyManager.EnnemyDied += new EventHandler <EnnemyDeadEventArgs>(alienManager_EnnemyDied);
            Add(_ennemyManager);

            // Interface
            gameUI = new GameUI(Registry.Players);
            Add(gameUI);

            // Gestionnaire de message
            messageBoxManager = new MessageBoxManager();
            Add(messageBoxManager);

            messageBoxManager.MessageBoxStart.CloseRequested += messageBoxStart_CloseRequested;
            messageBoxManager.MessageBoxPause.CloseRequested += messageBoxPause_CloseRequested;
            messageBoxManager.MessageBoxEnd.CloseRequested   += messageBoxEnd_CloseRequested;

            // Timers
            _startGameTimer            = new YnTimer(2500, 0);
            _startGameTimer.Completed += startGameTimer_Completed;
            _startGameTimer.Start();

            _looseTimer            = new YnTimer(5000, 0);
            _looseTimer.Completed += endTimer_Completed;

            // FX
            fxManager = new FxManager();
            Add(fxManager);

            // audio
            Registry.AudioManager.VocalRate = 0;

            // Registry

            Registry.GameStatus  = gameStatus;
            Registry.ActiveState = this;
            Registry.Ennemies    = _ennemyManager;
            Registry.GameUI      = gameUI;
            Registry.Background  = background;
            Registry.FX          = fxManager;

            ChangeGameStatus(GameStatus.Starting);
        }
Ejemplo n.º 8
0
        public void ChangeGameStatus(GameStatus newStatus, bool restart = false)
        {
            if (newStatus == GameStatus.Loose)
            {
                // Audio
                Registry.AudioManager.MusicVolume = 0.2f;

                Registry.AudioManager.SpeakAsync("Mission failed ! You're ship has been destroyed !");

                // Interface
                gameUI.Kill();

                // Aliens
                _ennemyManager.Kill();

                // Joueurs
                if (_player.Active)
                {
                    _player.Kill();
                }

                // Messages
                _looseTimer.Start();
                messageBoxManager.ActiveMessageBox(MessageBoxType.End);
            }

            else if (newStatus == GameStatus.Paused)
            {
                _ennemyManager.Enabled = false;

                _player.Enabled = false;

                gameUI.Enabled = false;

                messageBoxManager.ActiveMessageBox(MessageBoxType.Pause);
            }

            else if (newStatus == GameStatus.Running)
            {
                _ennemyManager.Enabled = true;

                _player.Enabled = true;

                gameUI.Active = true;
                messageBoxManager.DesactiveMessageBoxes();
            }

            else if (newStatus == GameStatus.Starting)
            {
                Registry.AudioManager.SpeakAsync("Get ready !");

                _ennemyManager.Enabled = false;

                _player.Enabled = false;

                messageBoxManager.ActiveMessageBox(MessageBoxType.Start);
            }

            else if (newStatus == GameStatus.Success)
            {
                Registry.AudioManager.StopMusic();
                YnG.SwitchState(new ScoreState(true));
            }

            else if (newStatus == GameStatus.Quit)
            {
                Registry.AudioManager.StopMusic();
                YnG.SwitchState(new ScoreState(true));
            }

            else if (newStatus == GameStatus.Died)
            {
                Registry.AudioManager.StopMusic();
                YnG.SwitchState(new ScoreState(true));
            }

            gameStatus = newStatus;

            if (restart)
            {
                RestartScene();
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Initialise le nouvel objet de données
        /// </summary>
        /// <param name="data">Le conteneur de données</param>
        public void SetData(SceneData data)
        {
            _sceneData = data;

            // On cache le texte
            _narationText.Active = false;

            // Réinitialisation du DSOD : le Deadly Screen Of Death
            _deadlySceenOfDeath = false;

            if (_sceneData.LeftScene != String.Empty)
            {
                _goLeft.Visible = true;
            }
            else
            {
                _goLeft.Visible = false;
            }

            if (_sceneData.TopScene != String.Empty)
            {
                _goUp.Visible = true;
            }
            else
            {
                _goUp.Visible = false;
            }

            if (_sceneData.RightScene != String.Empty)
            {
                _goRight.Visible = true;
            }
            else
            {
                _goRight.Visible = false;
            }

            if (_sceneData.BottomScene != String.Empty)
            {
                _goDown.Visible = true;
            }
            else
            {
                _goDown.Visible = false;
            }

            if (!_visitedScreens.ContainsKey(data.Code))
            {
                _visitedScreens.Add(data.Code, false);
            }
            else
            {
                _visitedScreens [data.Code] = true;
            }

            if (_visitedScreens [data.Code] == false)
            {
                // Découverte de la zone : affichage d'un message TODO
                if (data.Message != String.Empty)
                {
                    string message = data.Message;
                    _narationText.Text   = message;
                    _narationText.Active = true;
                    _narationTimer.Start();
                    _vocalSynthetizer.SpeakAsync(message);
                }
            }

            if (GetMemberByName("background") != null)
            {
                _background.AssetName = data.Background;

                if (data.Code == "scene_18" && _ampoulePosee)
                {
                    _background.AssetName = data.Background + "_1";
                }

                _background.LoadContent();
                _background.SetFullScreen();
            }
            else
            {
                _background      = new YnEntity(data.Background);
                _background.Name = "background";
                Add(_background);

                _background.SetFullScreen();
            }

            if (_sceneData.LeftScene != String.Empty && GetMemberByName("go_left") == null)
            {
                Add(_goLeft);
            }

            if (_sceneData.TopScene != String.Empty && GetMemberByName("go_up") == null)
            {
                Add(_goUp);
            }

            if (_sceneData.RightScene != String.Empty && GetMemberByName("go_right") == null)
            {
                Add(_goRight);
            }

            if (_sceneData.BottomScene != String.Empty && GetMemberByName("go_down") == null)
            {
                Add(_goDown);
            }

            if (_sceneData.AmbienceZone > 0)
            {
                AmbianceManager.AmbianceZone zone = AmbianceManager.AmbianceZone.Outside;

                if (_sceneData.AmbienceZone == 2)
                {
                    zone = AmbianceManager.AmbianceZone.Hall;
                }
                if (_sceneData.AmbienceZone == 3)
                {
                    zone = AmbianceManager.AmbianceZone.Bathroom;
                }
                if (_sceneData.AmbienceZone == 4)
                {
                    zone = AmbianceManager.AmbianceZone.Stairs;
                }
                if (_sceneData.AmbienceZone == 5)
                {
                    zone = AmbianceManager.AmbianceZone.Room;
                }

                _ambianceManager.SetAmbianceZone(zone);
            }

            // 1 - on clean la scène
            _itemsOnScreen.Clear();

            foreach (SceneObject sceneObject in data.Objects)
            {
                if (sceneObject.AssetName != String.Empty)
                {
                    bool mustAddObject = true;
                    if ((ActionType)sceneObject.ActionID == ActionType.Pick)
                    {
                        // Ne pas ajouter les éléments déjà dans l'inventaire
                        foreach (InventoryItem item in _inventory)
                        {
                            if (item.Code == sceneObject.Name)
                            {
                                mustAddObject = false;
                            }
                        }
                    }

                    if (mustAddObject)
                    {
                        YnEntity imageObject = new YnEntity(sceneObject.AssetName);
                        imageObject.LoadContent();

                        imageObject.MouseClicked += (s, e) =>
                        {
                            if (sceneObject.SoundName != String.Empty)
                            {
                                YnG.AudioManager.PlaySound(sceneObject.SoundName, 1.0f, 1.0f, 1.0f);
                            }

                            if ((ActionType)sceneObject.ActionID == ActionType.Pick)
                            {
                                AddItem(sceneObject.Name);

                                if (sceneObject.Name.Equals("SceneObject_1"))
                                {
                                    _ticket1Ramasse = true;
                                    _ambianceManager.SetGuideSound(AmbianceManager.GuideSound.Carhonk);
                                }
                                if (sceneObject.Name.Equals("SceneObject_2"))
                                {
                                    _marteauRamasse = true;
                                    _ambianceManager.SetGuideSound(AmbianceManager.GuideSound.None);
                                }
                                if (sceneObject.Name.Equals("SceneObject_3"))
                                {
                                    _anneauRamasse = true;
                                }
                                if (sceneObject.Name.Equals("SceneObject_4"))
                                {
                                    _cleRecue = true;
                                }
                                if (sceneObject.Name.Equals("SceneObject_5"))
                                {
                                    _ampouleRamasse = true;
                                }
                                if (sceneObject.Name.Equals("SceneObject_6"))
                                {
                                    _diamantRamasse = true;
                                }
                                if (sceneObject.Name.Equals("SceneObject_7"))
                                {
                                    _diamantRamasse = true;
                                }

                                string temp  = sceneObject.Name.Split(new char[] { '_' })[1];
                                bool   valid = true;

                                try
                                {
                                    int c = int.Parse(temp);
                                }
                                catch (Exception ex)
                                {
                                    valid = false;
                                    Console.WriteLine(ex.Message);
                                }

                                if (valid)
                                {
                                    showSplash(sceneObject.Name);

                                    // Suppression de l'item de la scène
                                    YnEntity imgToDelete = null;

                                    foreach (YnEntity i in _itemsOnScreen)
                                    {
                                        if (i.AssetName == sceneObject.AssetName)
                                        {
                                            imgToDelete = i;
                                        }
                                    }

                                    _itemsOnScreen.Remove(imgToDelete);
                                }
                            }
                        };
                        _itemsOnScreen.Add(imageObject);

                        imageObject.X = (int)ScreenHelper.GetScaleX(sceneObject.X);
                        imageObject.Y = (int)ScreenHelper.GetScaleY(sceneObject.Y);
                    }
                }
            }

            // Si c'est une scène "mortelle" on passe un flag à true
            // TODO Ajouter ici les scènes mortelles
            if (data.Code == "scene_4")
            {
                _deadlySceenOfDeath = true;
                _ambianceManager.PlayDeath(AmbianceManager.TypeOfDeath.Ghost);
                _deathAlpha = 0.0F;
            }
        }
Ejemplo n.º 10
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            if (gameState == MazeGameState.Playing)
            {
                if (YnG.Keys.JustPressed(Keys.Escape) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.Back))
                {
                    gameState = MazeGameState.Terminated;
                    OnExitRequest(EventArgs.Empty);
                }

                soundTimer.Update(gameTime);

                elapsedPartyTime += gameTime.ElapsedGameTime.Milliseconds;

                timeTimer.Update(gameTime.ElapsedGameTime.Milliseconds);

                _gameHUD.Update(gameTime);
                _gameHUD.Time = timeTimer.ToString();

                control.Update(gameTime);
#if DEBUG
                if (YnG.Keys.JustPressed(Keys.F8))
                {
                    OnLevelFinished(new LevelFinishEventArgs(score, (_mazeLevel.Id + 1), false));
                }
#endif
                string collider = control.ValidatePosition(_mazeLevel.Walls);

                if (collider == "END")
                {
                    gameState = MazeGameState.Ending;
                    UpdateScore(50);
                }
                else if (collider == "WALL")
                {
                    if (YnG.AudioManager.SoundEnabled)
                    {
                        YnG.AudioManager.PlaySound("Audio/bat", 1.0f, 1.0f, 0.0f);
                        YnG.AudioManager.SoundEnabled = false;
                        soundTimer.Start();
                    }
                }

                groundPlayerBoundingSphere.Center = new Vector3(Camera.Position.X, 1, Camera.Position.Z);

                foreach (YnMeshModel model in _mazeLevel.Items)
                {
                    if (model.Active)
                    {
                        if (groundPlayerBoundingSphere.Intersects(model.BoundingSphere))
                        {
                            YnG.AudioManager.PlaySound("Audio/kristal", 1.0f, 1.0f, 0.0f);
                            UpdateScore((model as AnimatedItemMesh).Points);
                            _gameHUD.MiniMap.UpdateItemStatus(Camera.X, Camera.Z);
                            _gameHUD.UpdateNbCrystals();
                            model.Active = false;
                        }
                    }
                }

                if (_gameHUD.MiniMap.Enabled)
                {
                    _gameHUD.MiniMap.UpdatePlayerPosition(Camera.X, Camera.Z);
                }

                if (virtualPad.Enabled)
                {
                    virtualPad.Update(gameTime);
                }
            }
            else if (gameState == MazeGameState.Ending)
            {
                gameState = MazeGameState.Terminated;

                bool finishedGame = false;

                int nextLevel = (_mazeLevel.Id + 1);

                if (nextLevel > GameConfiguration.LevelCount)
                {
                    nextLevel    = 1;
                    finishedGame = true;
                }

                score.ElapsedTime = elapsedPartyTime;

                OnLevelFinished(new LevelFinishEventArgs(score, nextLevel, finishedGame));
            }
        }