Пример #1
0
        public Tile(Room room, Enumeration.TileType tileType, Enumeration.StateTile state, Enumeration.Items eitem, Enumeration.TileType NextTileType)
        {
            tileAnimation = new AnimationSequence(this);
            this.room     = room;
            nextTileType  = NextTileType;

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

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

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


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

            foreach (Sequence s in tileSequence)
            {
                s.Initialize();
            }

            //Search in the sequence the right type
            Sequence result = tileSequence.Find(delegate(Sequence s)
            {
                return(s.name.ToUpper() == state.ToString().ToUpper());
            });

            if (result != null)
            {
                //AMF to be adjust....
                result.frames[0].SetTexture((Texture2D)Maze.Content[PoP.CONFIG_TILES + result.frames[0].value]);
                //result.frames[0].SetTexture(Content.Load<Texture2D>(PrinceOfPersiaGame.CONFIG_TILES + 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(tileSequence, tileState);

            //load item
            switch (eitem)
            {
            case Enumeration.Items.flask:
                item = new Flask();
                break;

            case Enumeration.Items.sword:
                item = new Sword();
                break;
            }
        }
Пример #2
0
        public void Add(StateTileElement stateElement)
        {
            if (data.Count == iSize)
            {
                data.Dequeue();
            }

            data.Enqueue(stateElement);
        }
Пример #3
0
        public Sword()
        {
            System.Xml.Serialization.XmlSerializer ax = new System.Xml.Serialization.XmlSerializer(ItemSequence.GetType());

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

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


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

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

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

            if (result != null)
            {
                //AMF to be adjust....
                result.frames[0].SetTexture((Texture2D)Maze.Content[PoP.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);
        }
        public void UpdateFrameTile(float elapsed, ref Position position, ref SpriteEffects spriteEffects, ref TileState tileState)
        {
            float TimePerFrame = 0;

            TimePerFrame = frameRate + sequence.frames[frameIndex].delay; //0.1
            tileState.Value().Name = string.Empty;
            TotalElapsed += elapsed;

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


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

                //Taking name of the frame usefull for kill or other interactions..
                tileState.Value().Name = sequence.frames[frameIndex].name;

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

                            Sequence result = lsequence.Find(delegate(Sequence s)
                            {
                                return(s.name.ToUpper() == par.ToUpper());
                            });
                            sequence   = result;
                            frameIndex = 0;
                            tileState.Add(StateTileElement.Parse(par));
                        }
                    }
                }

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

                position.Value = new Vector2(position.X + (sequence.frames[frameIndex].xOffSet * flip), position.Y + sequence.frames[frameIndex].yOffSet);
            }
            else if (firstTime == true)
            {
                int flip;
                if (spriteEffects == SpriteEffects.FlipHorizontally)
                {
                    flip = 1;
                }
                else
                {
                    flip = -1;
                }

                position.Value = new Vector2(position.X + (sequence.frames[frameIndex].xOffSet * flip), position.Y + sequence.frames[frameIndex].yOffSet);
                firstTime      = false;

                //Play Sound
                sequence.frames[frameIndex].PlaySound();
            }
        }
        /// <summary>
        /// Begins or continues playback of an animation.
        /// </summary>
        ///

        public void PlayAnimation(List <Sequence> lsequence, TileState tileState)
        {
            StateTileElement stateTileElement = tileState.Value();
            string           stateName        = stateTileElement.state.ToString();


            // Start the new animation.
            if (stateTileElement.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(delegate(Sequence s)
            {
                return(s.name.ToUpper() == stateName.ToUpper());
            });

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

            //cloning for avoid reverse pemanently...
            sequence = result.DeepClone();

            if (stateTileElement.Stoppable != null)
            {
                foreach (Frame f in sequence.frames)
                {
                    f.stoppable = (bool)stateTileElement.Stoppable;
                }
            }

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

            //Check if reverse movement and reverse order and sign x,y
            if (stateTileElement.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 (stateTileElement.Reverse == Enumeration.SequenceReverse.FixFrame)
            {
                int newIndex = this.FrameSpriteCount() - this.frameIndex;
                //fix bug result20140830
                if (sequence.frames[newIndex].type == Enumeration.TypeFrame.COMMAND)
                {
                    frameIndex = newIndex - 1;
                }
                else
                {
                    frameIndex = newIndex;
                }
            }
            else
            {
                frameIndex = 0;
            }

            firstTime = true;

            //Taking name of the frame usefull for hit combat..
            stateTileElement.Name = sequence.frames[frameIndex].name;

            if (sequence.raised == true)
            {
                stateTileElement.Raised = true;
            }
            else
            {
                stateTileElement.Raised = sequence.frames[frameIndex].raised;
            }


            //ASSIGN FRAME only for debug purpose
            stateTileElement.Frame = frameIndex;
        }