Inheritance: StateElement
Beispiel #1
0
        public Flask(ContentManager Content)
        {
            System.Xml.Serialization.XmlSerializer ax = new System.Xml.Serialization.XmlSerializer(ItemSequence.GetType());

            Stream txtReader = Microsoft.Xna.Framework.TitleContainer.OpenStream(PrinceOfPersiaGame.CONFIG_PATH_CONTENT + PrinceOfPersiaGame.CONFIG_PATH_SEQUENCES + Enumeration.Items.flask.ToString().ToUpper() + "_sequence.xml");
            //TextReader txtReader = File.OpenText(PrinceOfPersiaGame.CONFIG_PATH_CONTENT + PrinceOfPersiaGame.CONFIG_PATH_SEQUENCES + tileType.ToString().ToUpper() + "_sequence.xml");

            ItemSequence = (List<Sequence>)ax.Deserialize(txtReader);

            foreach (Sequence s in ItemSequence)
            {
                s.Initialize(Content);
            }

            //Search in the sequence the right type
            Sequence result = ItemSequence.Find((Sequence s) => s.name == Enumeration.StateTile.normal.ToString().ToUpper());

            if (result != null)
            {
                //AMF to be adjust....
                result.frames[0].SetTexture(Content.Load<Texture2D>(PrinceOfPersiaGame.CONFIG_ITEMS + result.frames[0].value));

                Texture = result.frames[0].texture;
            }

            //change statetile element
            StateTileElement stateTileElement = new StateTileElement();
            stateTileElement.state = Enumeration.StateTile.normal;
            itemState.Add(stateTileElement);

            itemAnimation.PlayAnimation(ItemSequence, itemState.Value());
        }
Beispiel #2
0
        public void Add(StateTileElement stateElement)
        {
            if (data.Count == iSize)
            {
                data.Dequeue();
            }

            data.Enqueue(stateElement);
        }
Beispiel #3
0
        public Tile(RoomNew room, ContentManager Content, Enumeration.TileType tileType, Enumeration.StateTile state, Enumeration.Items eitem, Enumeration.TileType NextTileType__1)
        {
            this.room    = room;
            nextTileType = NextTileType__1;

            System.Xml.Serialization.XmlSerializer ax = new System.Xml.Serialization.XmlSerializer(m_tileSequence.GetType());

            Stream txtReader = Microsoft.Xna.Framework.TitleContainer.OpenStream(PrinceOfPersiaGame.CONFIG_PATH_CONTENT + PrinceOfPersiaGame.CONFIG_PATH_SEQUENCES + tileType.ToString().ToUpper() + "_sequence.xml");

            //TextReader txtReader = File.OpenText(PrinceOfPersiaGame.CONFIG_PATH_CONTENT + PrinceOfPersiaGame.CONFIG_PATH_SEQUENCES + tileType.ToString().ToUpper() + "_sequence.xml");


            m_tileSequence = (List <Sequence>)ax.Deserialize(txtReader);

            foreach (Sequence s in m_tileSequence)
            {
                s.Initialize(Content);
            }

            //Search in the sequence the right type
            Sequence result = m_tileSequence.Find((Sequence s) => s.name == state.ToString().ToUpper());

            if (result != null)
            {
                //AMF to be adjust....
                result.frames[0].SetTexture(Content.Load <Texture2D>(PrinceOfPersiaGame.CONFIG_TILES[0] + result.frames[0].value));

                collision = result.collision;
                Texture   = result.frames[0].texture;
            }
            Type = tileType;


            //change statetile element
            StateTileElement stateTileElement = new StateTileElement();

            stateTileElement.state = state;
            tileState.Add(stateTileElement);
            tileAnimation.PlayAnimation(m_tileSequence, tileState.Value());

            //load item
            switch (eitem)
            {
            case Enumeration.Items.flask:
                item = new Flask(Content);
                break;     // TODO: might not be correct. Was : Exit Select

            case Enumeration.Items.flaskbig:
                item = new FlaskBig(Content);
                break;     // TODO: might not be correct. Was : Exit Select

            case Enumeration.Items.sword:
                item = new Sword(Content);
                break;     // TODO: might not be correct. Was : Exit Select
            }
        }
Beispiel #4
0
        public Flask(ContentManager Content)
        {
            System.Xml.Serialization.XmlSerializer ax = new System.Xml.Serialization.XmlSerializer(ItemSequence.GetType());

            Stream txtReader = Microsoft.Xna.Framework.TitleContainer.OpenStream(PrinceOfPersiaGame.CONFIG_PATH_CONTENT + PrinceOfPersiaGame.CONFIG_PATH_SEQUENCES + Enumeration.Items.flask.ToString().ToUpper() + "_sequence.xml");

            //TextReader txtReader = File.OpenText(PrinceOfPersiaGame.CONFIG_PATH_CONTENT + PrinceOfPersiaGame.CONFIG_PATH_SEQUENCES + tileType.ToString().ToUpper() + "_sequence.xml");


            ItemSequence = (List <Sequence>)ax.Deserialize(txtReader);

            foreach (Sequence s in ItemSequence)
            {
                s.Initialize(Content);
            }

            //Search in the sequence the right type
            Sequence result = ItemSequence.Find((Sequence s) => s.name == Enumeration.StateTile.normal.ToString().ToUpper());

            if (result != null)
            {
                //AMF to be adjust....
                result.frames[0].SetTexture(Content.Load <Texture2D>(PrinceOfPersiaGame.CONFIG_ITEMS + result.frames[0].value));

                Texture = result.frames[0].texture;
            }


            //change statetile element
            StateTileElement stateTileElement = new StateTileElement();

            stateTileElement.state = Enumeration.StateTile.normal;
            itemState.Add(stateTileElement);


            itemAnimation.PlayAnimation(ItemSequence, itemState.Value());
        }
Beispiel #5
0
        public Tile(RoomNew room, ContentManager Content, Enumeration.TileType tileType, Enumeration.StateTile state, Enumeration.Items eitem, Enumeration.TileType NextTileType__1)
        {
            this.room = room;
            nextTileType = NextTileType__1;

            System.Xml.Serialization.XmlSerializer ax = new System.Xml.Serialization.XmlSerializer(m_tileSequence.GetType());

            Stream txtReader = Microsoft.Xna.Framework.TitleContainer.OpenStream(PrinceOfPersiaGame.CONFIG_PATH_CONTENT + PrinceOfPersiaGame.CONFIG_PATH_SEQUENCES + tileType.ToString().ToUpper() + "_sequence.xml");
            //TextReader txtReader = File.OpenText(PrinceOfPersiaGame.CONFIG_PATH_CONTENT + PrinceOfPersiaGame.CONFIG_PATH_SEQUENCES + tileType.ToString().ToUpper() + "_sequence.xml");

            m_tileSequence = (List<Sequence>)ax.Deserialize(txtReader);

            foreach (Sequence s in m_tileSequence)
            {
                s.Initialize(Content);
            }

            //Search in the sequence the right type
            Sequence result = m_tileSequence.Find((Sequence s) => s.name == state.ToString().ToUpper());

            if (result != null)
            {
                //AMF to be adjust....
                result.frames[0].SetTexture(Content.Load<Texture2D>(PrinceOfPersiaGame.CONFIG_TILES[0] + result.frames[0].value));

                collision = result.collision;
                Texture = result.frames[0].texture;
            }
            Type = tileType;

            //change statetile element
            StateTileElement stateTileElement = new StateTileElement();
            stateTileElement.state = state;
            tileState.Add(stateTileElement);
            tileAnimation.PlayAnimation(m_tileSequence, tileState.Value());

            //load item
            switch (eitem)
            {
                case Enumeration.Items.flask:
                    item = new Flask(Content);
                    break; // TODO: might not be correct. Was : Exit Select

                case Enumeration.Items.flaskbig:
                    item = new FlaskBig(Content);
                    break; // TODO: might not be correct. Was : Exit Select

                case Enumeration.Items.sword:
                    item = new Sword(Content);
                    break; // TODO: might not be correct. Was : Exit Select

            }
        }
        /// <summary>
        /// Begins or continues playback of an animation.
        /// </summary>
        public void PlayAnimation(List <Sequence> lsequence, StateElement stateElement)
        {
            StatePlayerElement statePlayerElement = default(StatePlayerElement);
            StateTileElement   stateTileElement   = default(StateTileElement);
            string             stateName          = string.Empty;

            if (object.ReferenceEquals(typeof(StatePlayerElement), stateElement.GetType()))
            {
                statePlayerElement = (StatePlayerElement)stateElement;
                stateName          = statePlayerElement.state.ToString();
                StateName          = stateName;
            }
            else if (object.ReferenceEquals(typeof(StateTileElement), stateElement.GetType()))
            {
                stateTileElement = (StateTileElement)stateElement;
                stateName        = stateTileElement.state.ToString();
                StateName        = stateName;
            }
            else
            {
                stateName = stateElement.state.ToString();
                StateName = stateName;
            }

            // Start the new animation.
            if (stateElement.Priority == Enumeration.PriorityState.Normal & this.IsStoppable == false)
            {
                return;
            }

            //Check if the animation is already playing
            if (sequence != null && sequence.name == stateName)
            {
                return;
            }



            this.lsequence = lsequence;
            //Search in the sequence the right type
            Sequence result = lsequence.Find((Sequence s) => s.name == stateName.ToUpper());

            if (result == null)
            {
                //will be an error
                return;
            }

            //cloning for avoid reverse pemanently...
            sequence = result;

            if (stateElement.Stoppable != null)
            {
                foreach (Frame f in sequence.frames)
                {
                    f.stoppable = Convert.ToBoolean(stateElement.Stoppable);
                }
            }

            //For increase offset depend of the state previus; for example when running and fall the x offset will be increase.
            if (stateElement.OffSet != Vector2.Zero)
            {
                foreach (Frame f in sequence.frames)
                {
                    f.xOffSet = f.xOffSet + Convert.ToInt32(Math.Truncate(stateElement.OffSet.X));
                    f.yOffSet = f.yOffSet + Convert.ToInt32(Math.Truncate(stateElement.OffSet.Y));
                }
            }

            //Check if reverse movement and reverse order and sign x,y
            if (stateElement.Reverse == Enumeration.SequenceReverse.Reverse)
            {
                List <Frame> newListFrame   = new List <Frame>();
                List <Frame> newListCommand = new List <Frame>();

                foreach (Frame f in sequence.frames)
                {
                    if (f.type == Enumeration.TypeFrame.COMMAND)
                    {
                        newListCommand.Add(f);
                    }
                    else
                    {
                        f.xOffSet = -1 * f.xOffSet;
                        f.yOffSet = -1 * f.yOffSet;
                        newListFrame.Add(f);
                    }
                }
                newListFrame.Reverse();
                //add command
                foreach (Frame f in newListCommand)
                {
                    newListFrame.Add(f);
                }

                sequence.frames = newListFrame;
            }


            if (stateElement.Reverse == Enumeration.SequenceReverse.FixFrame)
            {
                this.m_frameIndex = this.FrameSpriteCount() - this.m_frameIndex;
            }
            else
            {
                this.m_frameIndex = 0;
            }

            this.firstTime = true;
        }
        public void UpdateFrameItem(float elapsed, ref Position position, ref SpriteEffects spriteEffects__1, ref TileState itemState)
        {
            float TimePerFrame = 0;

            TimePerFrame = frameRate + sequence.frames[m_frameIndex].delay;
            //0.1
            //TimePerFrame = 0.9f + sequence.frames[frameIndex].delay; //0.1
            TotalElapsed += elapsed;


            if (TotalElapsed > TimePerFrame)
            {
                //Play Sound
                sequence.frames[m_frameIndex].PlaySound();


                m_frameIndex  = Math.Min(m_frameIndex + 1, Frames.Count - 1);
                TotalElapsed -= TimePerFrame;



                if (sequence.frames[m_frameIndex].type != Enumeration.TypeFrame.SPRITE)
                {
                    //COMMAND
                    string[] aCommand   = sequence.frames[m_frameIndex].name.Split('|');
                    string[] aParameter = sequence.frames[m_frameIndex].parameter.Split('|');
                    for (int x = 0; x <= aCommand.Length - 1; x++)
                    {
                        if (aCommand[x] == Enumeration.TypeCommand.ABOUTFACE.ToString())
                        {
                            if (spriteEffects__1 == SpriteEffects.FlipHorizontally)
                            {
                                spriteEffects__1 = SpriteEffects.None;
                            }
                            else
                            {
                                spriteEffects__1 = SpriteEffects.FlipHorizontally;
                            }
                        }
                        else if (aCommand[x] == Enumeration.TypeCommand.GOTOFRAME.ToString())
                        {
                            string par    = aParameter[x];
                            int    result = sequence.frames.FindIndex((Frame f) => f.name == par);
                            m_frameIndex = result;
                        }
                        else if (aCommand[x] == Enumeration.TypeCommand.GOTOSEQUENCE.ToString())
                        {
                            string   par    = aParameter[x];
                            Sequence result = lsequence.Find((Sequence s) => s.name == par);
                            sequence     = result;
                            m_frameIndex = 0;
                            itemState.Add(StateTileElement.Parse(par));
                        }
                        else if (aCommand[x] == Enumeration.TypeCommand.IFGOTOSEQUENCE.ToString())
                        {
                            string par = string.Empty;
                            if (itemState.Value().IfTrue == true)
                            {
                                par = aParameter[0];
                            }
                            else
                            {
                                par = aParameter[1];
                            }

                            Sequence result = lsequence.Find((Sequence s) => s.name == par);
                            sequence     = result;
                            m_frameIndex = 0;
                            itemState.Add(StateTileElement.Parse(par));
                        }
                    }
                }

                int flip = 0;
                if (spriteEffects__1 == SpriteEffects.FlipHorizontally)
                {
                    flip = 1;
                }
                else
                {
                    flip = -1;
                }

                position.Value = new Vector2(position.X + (sequence.frames[m_frameIndex].xOffSet * flip), position.Y + sequence.frames[m_frameIndex].yOffSet);
            }
            else if (firstTime == true)
            {
                //Play Sound
                sequence.frames[m_frameIndex].PlaySound();


                int flip = 0;
                if (spriteEffects__1 == SpriteEffects.FlipHorizontally)
                {
                    flip = 1;
                }
                else
                {
                    flip = -1;
                }

                position.Value = new Vector2(position.X + (sequence.frames[m_frameIndex].xOffSet * flip), position.Y + sequence.frames[m_frameIndex].yOffSet);
                firstTime      = false;
            }
        }
        public void Add(StateTileElement stateElement)
        {
            if (data.Count == iSize)
            {
                data.Dequeue();
            }

            data.Enqueue(stateElement);
        }