Пример #1
0
        public Projectile(ComponentManager manager, Vector3 position, Vector3 initialVelocity, Health.DamageAmount damage, float size, string asset, string hitParticles, string hitNoise, Body target, bool animated = false, bool singleSprite = false) :
            base("Projectile", manager.RootComponent, Matrix.CreateTranslation(position), new Vector3(size, size, size), Vector3.One, 1.0f, 1.0f, 1.0f, 1.0f, new Vector3(0, -10, 0))
        {
            Target                = target;
            HitAnimation          = null;
            IsSleeping            = false;
            Velocity              = initialVelocity;
            Orientation           = OrientMode.LookAt;
            AddToCollisionManager = false;
            CollideMode           = Physics.CollisionMode.None;
            var spriteSheet = new SpriteSheet(asset);

            if (animated)
            {
                spriteSheet.FrameWidth  = Math.Min(spriteSheet.FrameWidth, spriteSheet.FrameHeight);
                spriteSheet.FrameHeight = spriteSheet.FrameWidth;
            }

            Sprite = new Sprite(manager, "Sprite", this, Matrix.CreateRotationY((float)Math.PI * 0.5f),
                                spriteSheet, false)
            {
                OrientationType = Sprite.OrientMode.Fixed
            };
            if (animated)
            {
                Sprite.SetSimpleAnimation();
                Sprite.CurrentAnimation.Play();
            }
            else
            {
                Sprite.SetSingleFrameAnimation();
            }

            if (singleSprite)
            {
                this.Sprite.OrientationType = Sprite.OrientMode.Spherical;
            }

            if (!singleSprite)
            {
                Sprite2 = new Sprite(manager, "Sprite2", Sprite,
                                     Matrix.CreateRotationX((float)Math.PI * 0.5f),
                                     spriteSheet, false)
                {
                    OrientationType = Sprite.OrientMode.Fixed
                };

                if (animated)
                {
                    Sprite2.SetSimpleAnimation();
                }
                else
                {
                    Sprite2.SetSingleFrameAnimation();
                }
            }
            Damage       = damage;
            HitParticles = new ParticleTrigger(hitParticles, manager, "Hit Particles", this,
                                               Matrix.Identity, new Vector3(size * 0.5f, size * 0.5f, size * 0.5f), Vector3.Zero)
            {
                TriggerOnDeath  = true,
                SoundToPlay     = hitNoise,
                BoxTriggerTimes = 2
            };
            DamageRadius = (float)Math.Pow(size * 4, 2);
        }