Ejemplo n.º 1
0
        public override void LoadContent()
        {
            base.LoadContent();
            _menuBackground.LoadContent();
            _menuBackground.Width = YnG.Width;
            _notesIcon.LoadContent();
            _menuIcon.LoadContent();
            _narationText.LoadContent();
            _narationText.Position = new Vector2(Yna.Engine.Helpers.ScreenHelper.GetScaleX(50), YnG.Height - _narationText.ScaledHeight - Yna.Engine.Helpers.ScreenHelper.GetScaleY(90));

            foreach (KeyValuePair <string, YnEntity> pair in _itemImages)
            {
                pair.Value.LoadContent();
            }
        }
Ejemplo n.º 2
0
        public void showSplash(string assetName)
        {
            _showSplash = true;

            if (_splash == null)
            {
                _splash = new YnEntity("Splashes/" + assetName);
            }
            else
            {
                _splash.AssetName = "Splashes/" + assetName;
            }

            _splash.LoadContent();
            _splash.SetFullScreen();
        }
Ejemplo n.º 3
0
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
            _ambianceManager.Update(gameTime);

            _narationTimer.Update(gameTime);

            if (_deadlySceenOfDeath)
            {
                // Le joueur est là où il ne devrait pas!
                // Fondu qui va bien
                _deathAlpha += 0.01F;

                if (_deathAlpha >= 1.0F && _ambianceManager.TransitionDone())
                {
                    // Le joueur est mort : TP sur le banc
                    _deathAlpha = 0.0F;
                    SetData(ImlostGame.Scenes ["scene_1"]);
                }
            }
            else
            {
                if (_showSplash)
                {
                    // Splash affiché, on le masque si on clique n'importe où
                    if (YnG.Mouse.JustClicked(MouseButton.Left) || GetTouchState() ||
                        YnG.Keys.JustPressed(Keys.C) || YnG.Keys.JustPressed(Keys.NumPad0) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.Y))
                    {
                        _showSplash = false;
                    }
                }
                else
                {
                    _menuIcon.Update(gameTime);
                    _notesIcon.Update(gameTime);

                    //Gestion du curseur par manette xbox360
                    if (GamePad.GetState(PlayerIndex.One).IsConnected)
                    {
#if !LINUX
                        Mouse.SetPosition(YnG.Mouse.X + (int)YnG.Gamepad.RightStickValue(PlayerIndex.One).X * 20, YnG.Mouse.Y - (int)YnG.Gamepad.RightStickValue(PlayerIndex.One).Y * 20);
#endif
                    }

                    if (MouseInRectangle(_menuIcon.Rectangle) && YnG.Mouse.JustClicked(MouseButton.Left) || GetTouchState() ||
                        YnG.Keys.JustPressed(Keys.C) || YnG.Keys.JustPressed(Keys.NumPad0) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.Y))
                    {
                        // Click sur le menu
                        // TODO
                    }

                    // Images sur la scène
                    List <YnEntity> safeList = new List <YnEntity>(_itemsOnScreen);
                    foreach (YnEntity img in safeList)
                    {
                        img.Update(gameTime);
                    }

                    if (YnG.Mouse.MouseState.LeftButton == ButtonState.Pressed && !_dragging)
                    {
                        foreach (YnEntity img in _itemImages.Values)
                        {
                            if (MouseInRectangle(img.Rectangle))
                            {
                                _dragging = true;

                                _draggedImage = new YnEntity(img.AssetName);
                                _draggedImage.LoadContent();
                            }
                        }
                    }

                    if (YnG.Mouse.Released(MouseButton.Left) && _dragging)
                    {
                        _draggedImage.Position = new Vector2(YnG.Mouse.X - _draggedImage.Width / 2, YnG.Mouse.Y - _draggedImage.Height / 2);

                        if (YnG.Mouse.Released(MouseButton.Left))
                        {
                            // Drop
                            List <YnEntity> safeList2 = new List <YnEntity>(_itemsOnScreen);
                            foreach (YnEntity img in safeList2)
                            {
                                if (img.Rectangle.Intersects(_draggedImage.Rectangle))
                                {
                                    // Intersection
                                    DoDrop(_draggedImage, img);
                                }
                            }
                        }
                    }

                    if (_dragging)
                    {
                        _draggedImage.Position = new Vector2(YnG.Mouse.X - _draggedImage.Width / 2, YnG.Mouse.Y - _draggedImage.Height / 2);
                    }

                    if (YnG.Mouse.Released(MouseButton.Left))
                    {
                        _dragging = false;
                    }

                    // Déplacement au clavier, et manette Xbox360
                    if ((YnG.Keys.JustPressed(Keys.Z) || YnG.Keys.JustPressed(Keys.Up) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.LeftThumbstickUp)) &&
                        _sceneData.TopScene != String.Empty)
                    {
                        GoUp();
                    }
                    else if ((YnG.Keys.JustPressed(Keys.S) || YnG.Keys.JustPressed(Keys.Down) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.LeftThumbstickDown)) &&
                             _sceneData.BottomScene != String.Empty)
                    {
                        GoDown();
                    }
                    else if ((YnG.Keys.JustPressed(Keys.Q) || YnG.Keys.JustPressed(Keys.Left) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.LeftThumbstickLeft)) &&
                             _sceneData.LeftScene != String.Empty)
                    {
                        GoLeft();
                    }
                    else if ((YnG.Keys.JustPressed(Keys.D) || YnG.Keys.JustPressed(Keys.Right) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.LeftThumbstickRight)) &&
                             _sceneData.RightScene != String.Empty)
                    {
                        GoRight();
                    }
                    else if (YnG.Keys.JustPressed(Keys.Escape) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.Back))
                    {
                        YnG.Exit();
                    }

                    if (YnG.Mouse.JustClicked(MouseButton.Left) || GetTouchState() ||
                        YnG.Keys.JustPressed(Keys.C) || YnG.Keys.JustPressed(Keys.NumPad0) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.Y))
                    {
                        // Click sur le bouton de menu
                        int mx = YnG.Mouse.X;
                        int my = YnG.Mouse.Y;
                        if (MouseInRectangle(_menuHitbox) || TouchInRectangle(_menuHitbox) ||
                            YnG.Keys.JustPressed(Keys.C) || YnG.Keys.JustPressed(Keys.NumPad0) || YnG.Gamepad.JustPressed(PlayerIndex.One, Buttons.Y))
                        {
                            // Afficher ou masquer le menu
                            // 97 => hauteur du menu
                            // 25 => hauteur de la poignée
                            int delta = 97 - 25;
                            if (_menuIsShown)
                            {
                                // Déplacement de la hitbox vers le haut
                                _menuHitbox.Y += delta;

                                // Déplacement du background vers le haut
                                _menuBackground.Y += delta;
                            }
                            else
                            {
                                // Déplacement de la hitbox vers le bas
                                _menuHitbox.Y -= delta;

                                // Déplacement du background vers le bas
                                _menuBackground.Y -= delta;
                            }
                            _menuIsShown = !_menuIsShown;

                            _menuIcon.Visible  = _menuIsShown;
                            _notesIcon.Visible = _menuIsShown;

                            // Un peu brutasse comme méthode...
                            // On cache tout
                            foreach (KeyValuePair <string, YnEntity> pair in _itemImages)
                            {
                                pair.Value.Visible = false;
                            }

                            // Et on ne raffiche que ce qui est dans l'inventaire du joueur
                            int itemPadding = 20;
                            int nbItems     = _inventory.Count;
                            int x           = YnG.Width / 2 - (56 * nbItems) / 2;
                            if (nbItems > 1)
                            {
                                x -= ((nbItems - 1) * itemPadding) / 2;
                            }

                            foreach (InventoryItem item in _inventory)
                            {
                                if (_menuIsShown)
                                {
                                    _itemImages [item.Code].Visible = true;

                                    // Replacement de l'élément, centré en bas, de gauche à droite
                                    Vector2 pos = new Vector2(x, YnG.Height - 63);
                                    _itemImages [item.Code].Position = pos;

                                    x += 56 + itemPadding;
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
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;
            }
        }