Exemple #1
0
        /// <summary>
        /// Test if two entities collinding
        /// </summary>
        /// <param name="entityA">Sprite 1</param>
        /// <param name="entityB">Sprite 2</param>
        /// <returns></returns>
        public static bool Collide(YnEntity entityA, YnEntity entityB)
        {
            Rectangle r1 = new Rectangle((int)(entityA.X - entityA.Origin.X), (int)(entityA.Y - entityA.Origin.Y), (int)entityA.ScaledWidth, (int)entityA.ScaledHeight);
            Rectangle r2 = new Rectangle((int)(entityB.X - entityB.Origin.X), (int)(entityB.Y - entityB.Origin.Y), (int)entityB.ScaledWidth, (int)entityB.ScaledHeight);

            return(r1.Intersects(r2));
        }
Exemple #2
0
        /// <summary>
        /// Wait
        /// </summary>
        /// <param name="gameTime">The game time</param>
        /// <param name="o">Unused here</param>
        public override void Update(GameTime gameTime, YnEntity o)
        {
            _elaspedTime += gameTime.ElapsedGameTime.Milliseconds;

            if (_elaspedTime >= _waitTime)
            {
                _scriptDone = true;
            }
        }
 /// <summary>
 /// Create an script animator for the given YnObject
 /// </summary>
 /// <param name="target"></param>
 public ScriptAnimator(YnEntity target)
 {
     _target = target;
     _scriptNodes = new List<BaseScriptNode>();
     _started = false;
     _running = false;
     _nodeIndex = 0;
     _repeatAnimation = false;
 }
Exemple #4
0
        /// <summary>
        /// Remove a new entity from the pool.
        /// </summary>
        /// <param name="entity">An entity to remove.</param>
        /// <returns>Return true if the entity has been removed, otherwise return false.</returns>
        public bool Remove(YnEntity entity)
        {
            int index = System.Array.IndexOf(_poolEntities, entity);

            if (index > -1)
            {
                _poolEntities[index] = null;
                return(true);
            }

            return(false);
        }
Exemple #5
0
        /// <summary>
        /// Try to replace a disabled entity by a newer.
        /// </summary>
        /// <param name="entity">An newer entity to replace.</param>
        /// <returns>Return true if the entity has been replaced, otherwise return false.</returns>
        public bool TryReplace(YnEntity entity)
        {
            int index = GetFirstDisabledEntityIndex();

            if (index > -1)
            {
                _poolEntities[index] = entity;
                return(true);
            }

            return(false);
        }
Exemple #6
0
        /// <summary>
        /// Gets the first disabled entity.
        /// </summary>
        /// <returns>Return the first disabled entity, otherwise return null.</returns>
        protected YnEntity GetFirstDisabledEntity()
        {
            _tempSearchedEntity = null;
            int i = 0;

            while (i < _maximumPoolSize && _tempSearchedEntity == null)
            {
                _tempSearchedEntity = _poolEntities[i].Enabled ? null : _poolEntities[i];
                i++;
            }

            return _tempSearchedEntity;
        }
Exemple #7
0
        /// <summary>
        /// Gets the first disabled entity.
        /// </summary>
        /// <returns>Return the first disabled entity, otherwise return null.</returns>
        protected YnEntity GetFirstDisabledEntity()
        {
            _tempSearchedEntity = null;
            int i = 0;

            while (i < _maximumPoolSize && _tempSearchedEntity == null)
            {
                _tempSearchedEntity = _poolEntities[i].Enabled ? null : _poolEntities[i];
                i++;
            }

            return(_tempSearchedEntity);
        }
Exemple #8
0
        /// <summary>
        /// Add an entity to the scene
        /// </summary>
        /// <param name="entity">An entitiy</param>
        public void Add(YnEntity entity)
        {
            if (Initialized && !entity.Initialized)
            {
                entity.Initialize();
            }

            if (AssetLoaded && !entity.AssetLoaded)
            {
                entity.LoadContent();
            }

            _scene.Add(entity);
        }
Exemple #9
0
        /// <summary>
        /// Test if an entity and a group of entities are colliding.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="group"></param>
        /// <returns></returns>
        public static bool CollideOneWithGroup(YnEntity entity, List <YnEntity> group)
        {
            bool collide = false;
            int  size    = group.Count;
            int  i       = 0;

            while (i < size && !collide)
            {
                collide = Collide(entity, group[i]);
                i++;
            }

            return(collide);
        }
Exemple #10
0
        /// <summary>
        /// Test if an entity and a group of entities are colliding.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="group"></param>
        /// <returns></returns>
        public static bool CollideOneWithGroup(YnEntity entity, List<YnEntity> group)
        {
            bool collide = false;
            int size = group.Count;
            int i = 0;

            while (i < size && !collide)
            {
                collide = Collide(entity, group[i]);
                i++;
            }

            return collide;
        }
Exemple #11
0
        /// <summary>
        /// Add a new entity to the pool.
        /// </summary>
        /// <param name="entity">An entity to add.</param>
        /// <returns>Return true if the entity has been added, otherwise return false.</returns>
        public bool TryAdd(YnEntity entity)
        {
            bool result     = false;
            int  validIndex = GetFirstNullIndex();

            if (validIndex > -1)
            {
                _poolEntities[validIndex] = entity;
                result = true;
            }
            else
            {
                result = TryReplace(entity);
            }

            return(result);
        }
Exemple #12
0
        public MenuState(string name)
            : base(name, true)
        {
            _background = new YnEntity("Backgrounds/Accueil");
            Add(_background);

            playRectangle = new Rectangle(
                (int)ScreenHelper.GetScaleX(135),
                (int)ScreenHelper.GetScaleY(265),
                (int)(ScreenHelper.GetScale().X * 226),
                (int)(ScreenHelper.GetScale().Y * 65));

            quitRectangle = new Rectangle(
                (int)ScreenHelper.GetScaleX(135),
                (int)ScreenHelper.GetScaleY(420),
                (int)(ScreenHelper.GetScale().X * 226),
                (int)(ScreenHelper.GetScale().Y * 65));
        }
Exemple #13
0
        /// <summary>
        /// Add a new object in the collecion
        /// </summary>
        /// <param name="sceneObject">An object or derivated from YnObject</param>
        public void Add(YnEntity sceneObject)
        {
            sceneObject.Parent = this;

            if (_initialized)
            {
                sceneObject.Initialize();
            }

            if (_assetsLoaded)
            {
                sceneObject.LoadContent();
            }

            UpdateRectangle();

            _entitiesList.Add(sceneObject);
        }
Exemple #14
0
 /// <summary>
 /// A basic entity who represent a graphic object on the 2D Scene
 /// </summary>
 public YnEntity()
     : base()
 {
     _dirty                 = false;
     _position              = Vector2.Zero;
     _rectangle             = Rectangle.Empty;
     _texture               = null;
     _assetName             = String.Empty;
     _assetLoaded           = false;
     _color                 = Color.White;
     _rotation              = 0.0f;
     _origin                = Vector2.Zero;
     _scale                 = Vector2.One;
     _alpha                 = 1.0f;
     _effects               = SpriteEffects.None;
     _layerDepth            = 1.0f;
     _parent                = null;
     _nbMouseEventObservers = 0;
 }
Exemple #15
0
        /// <summary>
        /// Moves the object until the target point is reached
        /// </summary>
        /// <param name="gameTime">The game time</param>
        /// <param name="o">The object to move</param>
        public override void Update(GameTime gameTime, YnEntity o)
        {
            Vector2 position = o.Position;

            if (position == _destination)
            {
                // The destination is reached by the object
                _scriptDone = true;
            }
            else
            {
                // Create the normalized vector aiming to the target point
                Vector2 direction = _destination - position;
                direction.Normalize();

                // Apply speed factor on the direction
                Vector2 newPosition = Vector2.Multiply(direction, _speed);

                // Move the object
                o.Translate(newPosition);
            }
        }
Exemple #16
0
        /// <summary>
        /// Remove an entity from the group
        /// </summary>
        /// <param name="sceneObject"></param>
        public void Remove(YnEntity sceneObject)
        {
            _entitiesList.Remove(sceneObject);

            UpdateRectangle();
        }
Exemple #17
0
 /// <summary>
 /// Test if two entities collinding
 /// </summary>
 /// <param name="entityA">Sprite 1</param>
 /// <param name="entityB">Sprite 2</param>
 /// <returns></returns>
 public static bool Collide(YnEntity entityA, YnEntity entityB)
 {
     Rectangle r1 = new Rectangle((int)(entityA.X - entityA.Origin.X), (int)(entityA.Y - entityA.Origin.Y), (int)entityA.ScaledWidth, (int)entityA.ScaledHeight);
     Rectangle r2 = new Rectangle((int)(entityB.X - entityB.Origin.X), (int)(entityB.Y - entityB.Origin.Y), (int)entityB.ScaledWidth, (int)entityB.ScaledHeight);
     return r1.Intersects(r2);
 }
Exemple #18
0
 /// <summary>
 /// Perform an iteration of the script
 /// </summary>
 /// <param name="gameTime">The game time</param>
 /// <param name="o">The object to perform the script on</param>
 public abstract void Update(GameTime gameTime, YnEntity o);
Exemple #19
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();
        }
Exemple #20
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;
            }
        }
Exemple #21
0
        /// <summary>
        /// Add a new entity in the group
        /// </summary>
        /// <param name="sceneObject">An array of objects or derivated from YnObject</param>
        public void Add(YnEntity[] sceneObject)
        {
            int size = sceneObject.Length;

            for (int i = 0; i < size; i++)
                Add(sceneObject[i]);
        }
Exemple #22
0
 /// <summary>
 /// A basic entity who represent a graphic object on the 2D Scene
 /// </summary>
 public YnEntity()
     : base()
 {
     _dirty = false;
     _position = Vector2.Zero;
     _rectangle = Rectangle.Empty;
     _texture = null;
     _assetName = String.Empty;
     _assetLoaded = false;
     _color = Color.White;
     _rotation = 0.0f;
     _origin = Vector2.Zero;
     _scale = Vector2.One;
     _alpha = 1.0f;
     _effects = SpriteEffects.None;
     _layerDepth = 1.0f;
     _parent = null;
     _nbMouseEventObservers = 0;
 }
Exemple #23
0
 /// <summary>
 /// Remove an entity to the scene
 /// </summary>
 /// <param name="entity">An entitiy</param>
 public void Remove(YnEntity entity)
 {
     _scene.Remove(entity);
 }
Exemple #24
0
        private void DoDrop(YnEntity dropped, YnEntity reciever)
        {
            string code = reciever.AssetName;
            string dcode = dropped.AssetName;
            Console.WriteLine(code + "-" + dcode);

            if (code == "Items/cadenas" && dcode == "Items/item_3")
            {
                // Supprimer le cadenas
                _cadenasCasse = true;
                YnEntity todelete = null;
                foreach (YnEntity img in _itemsOnScreen)
                {
                    if (img.AssetName == "Items/cadenas")
                        todelete = img;
                }
                _itemsOnScreen.Remove(todelete);
            }
            else if (code == "Items/masqueporte" && dcode == "Items/item_7")
            {
                _porteOuverte = true;
            }
            else if (code == "Items/douille" && dcode == "Items/item_6")
            {
                _ampoulePosee = true;
                SetData(ImlostGame.Scenes ["scene_18"]);
            }
        }
Exemple #25
0
        /// <summary>
        /// Try to replace a disabled entity by a newer.
        /// </summary>
        /// <param name="entity">An newer entity to replace.</param>
        /// <returns>Return true if the entity has been replaced, otherwise return false.</returns>
        public bool TryReplace(YnEntity entity)
        {
            int index = GetFirstDisabledEntityIndex();

            if (index > -1)
            {
                _poolEntities[index] = entity;
                return true;
            }

            return false;
        }
Exemple #26
0
        /// <summary>
        /// Add an entity to the scene
        /// </summary>
        /// <param name="entity">An entitiy</param>
        public void Add(YnEntity entity)
        {
            if (Initialized && !entity.Initialized)
                entity.Initialize();

            if (AssetLoaded && !entity.AssetLoaded)
                    entity.LoadContent();
       
            _scene.Add(entity);
        }
Exemple #27
0
        /// <summary>
        /// Add a new entity to the pool.
        /// </summary>
        /// <param name="entity">An entity to add.</param>
        /// <returns>Return true if the entity has been added, otherwise return false.</returns>
        public bool TryAdd(YnEntity entity)
        {
            bool result = false;
            int validIndex = GetFirstNullIndex();

            if (validIndex > -1)
            {
                _poolEntities[validIndex] = entity;
                result = true;
            }
            else
                result = TryReplace(entity);

            return result;
        }
Exemple #28
0
        /// <summary>
        /// Remove a new entity from the pool.
        /// </summary>
        /// <param name="entity">An entity to remove.</param>
        /// <returns>Return true if the entity has been removed, otherwise return false.</returns>
        public bool Remove(YnEntity entity)
        {
            int index = System.Array.IndexOf(_poolEntities, entity);

            if (index > -1)
            {
                _poolEntities[index] = null;
                return true;
            }

            return false;
        }
Exemple #29
0
        public SceneState(string name)
            : base(name, false)
        {
            _vocalSynthetizer = new VocalSynthetizer();

            InitParcours();
            _menuIsShown = false;
            _visitedScreens = new Dictionary<string, bool>(); // 18 écrans
            _itemsOnScreen = new List<YnEntity>();

            _narationText = new YnText("Fonts/GameText", "Dummy");
            _narationText.Color = Color.DarkBlue;
            _narationText.Scale = new Vector2(1.5f) * Yna.Engine.Helpers.ScreenHelper.GetScale().X;

            _narationTimer = new YnTimer(3500);
            _narationTimer.Completed += (s, e) => _narationText.Active = false;

            _leftSceneHitbox = new Rectangle(0, _arrowHitboxSize, _arrowHitboxSize, YnG.Height - (97 - 25) - 2 * _arrowHitboxSize);
            _topSceneHitbox = new Rectangle(_arrowHitboxSize, 0, YnG.Width - 2 * _arrowHitboxSize, _arrowHitboxSize);
            _rightSceneHitbox = new Rectangle(YnG.Width - _arrowHitboxSize, _arrowHitboxSize, _arrowHitboxSize, YnG.Height - (97 - 25) - 2 * _arrowHitboxSize);
            _bottomSceneHitbox = new Rectangle(_arrowHitboxSize, YnG.Height - (97 - 25) - _arrowHitboxSize, YnG.Width - 2 * _arrowHitboxSize, _arrowHitboxSize);

            _menuHitbox = new Rectangle(YnG.Width / 2 - _buttonWidth / 2, YnG.Height - _buttonHeight, _buttonWidth, _buttonHeight);

            int padding = 30;
            int imageHalfSize = 30;
            int imageSize = imageHalfSize * 2;

            _goLeft = new YnEntity("Textures/icone-fleche-gauche", new Vector2(padding, YnG.Height / 2 - imageHalfSize));
            _goLeft.Visible = false;
            _goLeft.Name = "go_left";
            _goLeft.MouseClicked += (s, e) => GoLeft();

            _goUp = new YnEntity("Textures/icone-fleche-haut", new Vector2(YnG.Width / 2 - imageHalfSize, padding));
            _goUp.Visible = false;
            _goUp.Name = "go_up";
            _goUp.MouseClicked += (s, e) => GoUp();

            _goRight = new YnEntity("Textures/icone-fleche-droite", new Vector2(YnG.Width - padding - imageSize, YnG.Height / 2 - imageHalfSize));
            _goRight.Visible = false;
            _goRight.Name = "go_right";
            _goRight.MouseClicked += (s, e) => GoRight();

            _goDown = new YnEntity("Textures/icone-fleche-bas", new Vector2(YnG.Width / 2 - imageHalfSize, YnG.Height - padding - imageSize - 97 + 25));
            _goDown.Visible = false;
            _goDown.Name = "go_down";
            _goDown.MouseClicked += (e, s) => GoDown();

            _menuClosedY = YnG.Height - 25;
            _menuOpenedY = YnG.Height - 97;
            _menuBackground = new YnEntity("Textures/liste-inventaire", new Vector2(0, _menuClosedY));

            int iconPadding = 15;
            int x = iconPadding;
            int y = YnG.Height - 60;

            _menuIcon = new YnEntity("Textures/btn-menu", new Vector2(x, y));
            _menuIcon.Visible = false;
            _menuIcon.MouseClicked += (e, s) =>
            {
                if (!_menuIcon.Visible) return;
            };

            y = YnG.Height - 69;
            x = YnG.Width - iconPadding - 80;
            _notesIcon = new YnEntity("Textures/btn-notes", new Vector2(x, y));
            _notesIcon.Visible = false;
            _notesIcon.MouseClicked += (e, s) =>
            {
                if (!_notesIcon.Visible) return;

                // TODO Afficher les notes
                if (ImlostGame.Debug)
                    Console.WriteLine("Clicked on NOTES");
            };

            _inventory = new List<InventoryItem>();

            _itemImages = new Dictionary<string, YnEntity>();

            foreach (InventoryItem item in ImlostGame.InventoryItems.Values)
            {
                YnEntity img = new YnEntity(item.AssetName);
                img.Visible = false;
                _itemImages.Add(item.Code, img);
            }

            _ambianceManager = new AmbianceManager();
        }
Exemple #30
0
        /// <summary>
        /// Remove an entity from the group
        /// </summary>
        /// <param name="sceneObject"></param>
        public void Remove(YnEntity sceneObject)
        {
            _entitiesList.Remove(sceneObject);

            UpdateRectangle();
        }
Exemple #31
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;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #32
0
        /// <summary>
        /// Add a new object in the collecion
        /// </summary>
        /// <param name="sceneObject">An object or derivated from YnObject</param>
        public void Add(YnEntity sceneObject)
        {
            sceneObject.Parent = this;

            if (_initialized)
                sceneObject.Initialize();

            if (_assetsLoaded)
                sceneObject.LoadContent();

            UpdateRectangle();

            _entitiesList.Add(sceneObject);
        }
Exemple #33
0
 /// <summary>
 /// Remove an entity to the scene
 /// </summary>
 /// <param name="entity">An entitiy</param>
 public void Remove(YnEntity entity)
 {
     _scene.Remove(entity);
 }