Esempio n. 1
0
        /// <param name="commandLine">Format : addenemy type relativex relativey bonus pattern flag1,flag2 flip</param>
        public bool ParseLine(string commandLine, Vector2 screenResolution)
        {
            string[] tokens = commandLine.Split(' ');

            if (tokens.Length < 4)
            {
                return(false);
            }

            //Convert relative position to absolute
            Vector2 location = TGPAConvert.RelativeToAbsoluteLoc(tokens[2], tokens[3], screenResolution);

            //Enemy creation
            String optionalParameter = "";

            if (tokens.Length == 5)
            {
                optionalParameter = tokens[4];
            }

            this.Enemy = BackgroundActiveElement.String2BackgroundActiveElement(tokens[1], location, optionalParameter);

            return(true);
        }
        /// <param name="commandLine">Format : addenemy type relativex relativey bonus pattern flag1,flag2 flip</param>
        public bool ParseLine(string commandLine, Vector2 screenResolution)
        {
            string[] tokens = commandLine.Split(' ');

            if (tokens.Length != 8)
            {
                return(false);
            }

            MovePattern pattern = null;

            //Convert relative position to absolute
            Vector2 location = TGPAConvert.RelativeToAbsoluteLoc(tokens[2], tokens[3], screenResolution);

            //Flip
            SpriteEffects flip = SpriteEffects.None;

            if (tokens[7].Equals(SpriteEffects.FlipHorizontally.ToString()))
            {
                flip = SpriteEffects.FlipHorizontally;
            }
            else if (tokens[7].Equals(SpriteEffects.FlipVertically.ToString()))
            {
                flip = SpriteEffects.FlipVertically;
            }

            //Flags
            //flag1,flag2,flag3
            string[] flags = null;

            if (!tokens[6].Equals(""))
            {
                flags = tokens[6].Split(',');
            }

            //Bonus
            Bonus bonus = null;

            if (!tokens[4].Equals("nobonus"))
            {
                try
                {
                    bonus = new Bonus(tokens[4]);
                }
                catch (Exception e)
                {
                    Logger.Log(LogLevel.Error, "TGPA Exception : " + e.Message);
                }
            }
            //Pattern read
            if (tokens[5].Equals("nopattern"))
            {
                pattern = null;
            }
            else
            {
                //pattern = new MovePattern();

                string[] points = tokens[5].Split('+');

                foreach (String couple in points)
                {
                    //Not a pattern ID
                    if (couple.Contains(",") && couple.Contains("("))
                    {
                        string[] xy = couple.Replace("(", "").Replace(")", "").Split(',');
                        //pattern.AddPoint(new Point(Convert.ToInt32(xy[0]), Convert.ToInt32(xy[1])));
                    }
                    else
                    {
                        MovePattern.DefinedMovePattern patternID = (MovePattern.DefinedMovePattern)Enum.Parse(typeof(MovePattern.DefinedMovePattern), couple, true);
                        pattern = new MovePattern(patternID);
                    }
                }
            }

            //Enemy creation
            this.Enemy = BadGuy.String2BadGuy(tokens[1], location, bonus, pattern, flip, flags);

            if (this.Enemy.Location.X == -1)
            {
                location.X = -this.Enemy.DstRect.Width - 1;
            }

            if (this.Enemy.Location.Y == -1)
            {
                location.Y = -this.Enemy.DstRect.Height - 1;
            }

            this.Enemy.Location = location;

            return(true);
        }