Example #1
0
        private IMovementBehavior GetMovementBehavior(BirdData data, BirdMetaData metaData)
        {
            switch (metaData.MovementBehaviorType)
            {
                case "Straight":
                    return new StraightMovementBehavior
                    {
                        Position = data.Position,
                        Velocity = new Vector2(float.Parse(metaData.MovementBehaviorProperties["VelocityX"]), float.Parse(metaData.MovementBehaviorProperties["VelocityY"])),
                        Acceleration = new Vector2(float.Parse(metaData.MovementBehaviorProperties["AccelerationX"]), float.Parse(metaData.MovementBehaviorProperties["AccelerationY"])),
                    };

                case "Wavey":
                    return new WaveyMovementBehavior
                    {
                        Position = data.Position,
                        Velocity = new Vector2(float.Parse(metaData.MovementBehaviorProperties["VelocityX"]), float.Parse(metaData.MovementBehaviorProperties["VelocityY"])),
                        Acceleration = new Vector2(float.Parse(metaData.MovementBehaviorProperties["AccelerationX"]), float.Parse(metaData.MovementBehaviorProperties["AccelerationY"])),
                        Period = TimeSpan.FromSeconds(float.Parse(metaData.MovementBehaviorProperties["Period"])),
                        Radius = new Vector2(float.Parse(metaData.MovementBehaviorProperties["RadiusX"]), float.Parse(metaData.MovementBehaviorProperties["RadiusY"])),
                    };

                case "Gravity":
                    return new GravityMovementBehavior
                    {
                        Position = data.Position,
                        Velocity = new Vector2(float.Parse(metaData.MovementBehaviorProperties["VelocityX"]), float.Parse(metaData.MovementBehaviorProperties["VelocityY"])),
                        Acceleration = new Vector2(float.Parse(metaData.MovementBehaviorProperties["AccelerationX"]), float.Parse(metaData.MovementBehaviorProperties["AccelerationY"])),
                        TargetEntity = this.Bee,
                    };

                default: throw new ArgumentException();
            }
        }
Example #2
0
        private IShootingBehavior GetShootingBehavior(BirdData data, BirdMetaData metaData)
        {
            switch (metaData.ShootingBehaviorType)
            {
                case "Passive":
                    return new PassiveShooting();

                case "SingleBullet":
                    return new SingleBulletShooting
                    {
                        BulletDamage = int.Parse(metaData.ShootingBehaviorProperties["BulletDamage"]),
                        BulletDirection = new Vector2(float.Parse(metaData.ShootingBehaviorProperties["BulletDirectionX"]), float.Parse(metaData.ShootingBehaviorProperties["BulletDirectionY"])),
                        BulletSpeed = float.Parse(metaData.ShootingBehaviorProperties["BulletSpeed"]),
                        BulletTexture = this.ContentManager.Load<Texture2D>(metaData.ShootingBehaviorProperties["TexturePath"]),
                        FireRate = TimeSpan.FromSeconds(double.Parse(metaData.ShootingBehaviorProperties["FireRate"])),
                        FireBullet = this.BulletFired,
                    };

                case "DoubleBullet":
                    return new DoubleBulletShooting
                    {
                        BulletDamage = int.Parse(metaData.ShootingBehaviorProperties["BulletDamage"]),
                        BulletDirection = new Vector2(float.Parse(metaData.ShootingBehaviorProperties["BulletDirectionX"]), float.Parse(metaData.ShootingBehaviorProperties["BulletDirectionY"])),
                        BulletSpeed = float.Parse(metaData.ShootingBehaviorProperties["BulletSpeed"]),
                        BulletTexture = this.ContentManager.Load<Texture2D>(metaData.ShootingBehaviorProperties["TexturePath"]),
                        FireRate = TimeSpan.FromSeconds(double.Parse(metaData.ShootingBehaviorProperties["FireRate"])),
                        FireBullet = this.BulletFired,
                        Spread = float.Parse(metaData.ShootingBehaviorProperties["Spread"]),
                    };

                case "TripleBullet":
                    return new TripleBulletShooting
                    {
                        BulletDamage = int.Parse(metaData.ShootingBehaviorProperties["BulletDamage"]),
                        BulletDirection = new Vector2(float.Parse(metaData.ShootingBehaviorProperties["BulletDirectionX"]), float.Parse(metaData.ShootingBehaviorProperties["BulletDirectionY"])),
                        BulletSpeed = float.Parse(metaData.ShootingBehaviorProperties["BulletSpeed"]),
                        BulletTexture = this.ContentManager.Load<Texture2D>(metaData.ShootingBehaviorProperties["TexturePath"]),
                        FireRate = TimeSpan.FromSeconds(double.Parse(metaData.ShootingBehaviorProperties["FireRate"])),
                        FireBullet = this.BulletFired,
                        Spread = float.Parse(metaData.ShootingBehaviorProperties["Spread"]),
                    };

                case "Tracking":
                    return new TrackingShooting
                    {
                        BulletDamage = int.Parse(metaData.ShootingBehaviorProperties["BulletDamage"]),
                        BulletDirection = new Vector2(float.Parse(metaData.ShootingBehaviorProperties["BulletDirectionX"]), float.Parse(metaData.ShootingBehaviorProperties["BulletDirectionY"])),
                        BulletSpeed = float.Parse(metaData.ShootingBehaviorProperties["BulletSpeed"]),
                        BulletTexture = this.ContentManager.Load<Texture2D>(metaData.ShootingBehaviorProperties["TexturePath"]),
                        FireRate = TimeSpan.FromSeconds(double.Parse(metaData.ShootingBehaviorProperties["FireRate"])),
                        FireBullet = this.BulletFired,
                        TargetAtraction = float.Parse(metaData.ShootingBehaviorProperties["TargetAtraction"]),
                        TargetEntity = this.Bee,
                    };

                default: throw new ArgumentException();
            }
        }
Example #3
0
        /// <summary>
        /// Creates a new bird using the given bird data.
        /// </summary>
        /// <param name="birdData">The variable information associated with bird starting position and time.</param>
        /// <returns>The new bird entity.</returns>
        public BirdEntity CreateBird(BirdData birdData)
        {
            if (this.BirdMetaData == null)
            {
                this.Initialize();
            }

            var lMetaData = this.BirdMetaData[birdData.Type];

            return new BirdEntity
            {
                MovementBehavior = GetMovementBehavior(birdData, lMetaData),
                Renderer = this.CreateBirdRenderer(lMetaData),
                ShootingBehavior = this.GetShootingBehavior(birdData, lMetaData),
                MaximumHealth = lMetaData.Health,
                CurrentHealth = lMetaData.Health,
                ReleaseTime = birdData.ReleaseTime,
                Damage = lMetaData.TouchDamage,
            };
        }