Пример #1
0
        public static DrawableGameObject Create(GameWorld world, EnemyCreationParams param)
        {
            DrawableGameObject result = null;

            switch (param.Type)
            {
            case ENEMY_TP_SHOOTER:
                result = new ArcherEnemy(world, param.Position, Vector2.UnitX * param.Direction);
                break;

            case ENEMY_TP_CANNON:

                result = new CannonEnemy(
                    world,
                    param.Position,
                    new CannonEnemyParams
                {
                    Direction      = Vector2.UnitX * param.Direction,
                    DistanceOfShot = param.Force,
                    ThrowFrequency = TimeSpan.FromSeconds(param.Frequency)
                });
                break;

            case ENEMY_TP_ROTATE:
                result = new RotatingPost(world, param.Position, param.Speed.X);
                break;

            case ENEMY_TP_WANDERER:
            default:
                result = new WandererEnemy(world, param.Position, Vector2.UnitX * param.Direction);
                break;
            }

            return(result);
        }
        public static EnemyCreationParams Parse(Dictionary <String, String> properties)
        {
            EnemyCreationParams param = new EnemyCreationParams();

            String type;

            if (properties.TryGetValue("class", out type))
            {
                param.Type = type;
            }
            else
            {
                param.Type = EnemyFactory.ENEMY_TP_WANDERER;
            }

            String direction;

            if (properties.TryGetValue("direction", out direction))
            {
                param.Direction = int.Parse(direction);
            }
            else
            {
                param.Direction = (int)Vector2.UnitX.X;
            }

            String distance;

            if (properties.TryGetValue("distance", out distance))
            {
                param.Force = float.Parse(distance, CultureInfo.InvariantCulture);
            }



            String frequency;

            if (properties.TryGetValue("frequency", out frequency))
            {
                param.Frequency = double.Parse(frequency, CultureInfo.InvariantCulture);
            }

            String speed;

            if (properties.TryGetValue("speed", out speed))
            {
                var s = float.Parse(speed, CultureInfo.InvariantCulture);
                param.Speed = new Vector2(s, s);
            }
            else
            {
                param.Speed = Vector2.Zero;
            }


            return(param);
        }