Ejemplo n.º 1
0
        public override void CreateCosmeticChildren(ComponentManager manager)
        {
            AddChild(new Shadow(manager));

            var spriteSheet = new SpriteSheet(ContentPaths.Entities.DwarfObjects.beartrap);

            Sprite = AddChild(new AnimatedSprite(Manager, "Sprite", Matrix.Identity, false)) as AnimatedSprite;

            Sprite.AddAnimation(AnimationLibrary.CreateAnimation(spriteSheet, new List <Point> {
                Point.Zero
            }, IdleAnimation));

            var sprung = AnimationLibrary.CreateAnimation
                             (spriteSheet, new List <Point>
            {
                new Point(0, 1),
                new Point(1, 1),
                new Point(2, 1),
                new Point(3, 1)
            }, TriggerAnimation);

            sprung.FrameHZ = 6.6f;

            Sprite.AddAnimation(sprung);

            Sprite.SetFlag(Flag.ShouldSerialize, false);
            base.CreateCosmeticChildren(manager);
        }
Ejemplo n.º 2
0
        void CreateSpriteSheet(ComponentManager manager)
        {
            var spriteSheet = new SpriteSheet(SpriteAsset);

            // When true, causes the bird to face the direction its moving in
            Physics.Orientation = Physics.OrientMode.RotateY;

            // The dimensions of each frame in the sprite sheet (in pixels), as given by the readme
            const int frameWidth  = 24;
            const int frameHeight = 16;

            // Create the sprite component for the bird.
            var sprite = Physics.AddChild(new CharacterSprite
                                              (manager.World.GraphicsDevice,
                                              manager,
                                              "Bird Sprite",
                                              Matrix.CreateTranslation(0, 0.25f, 0)
                                              )) as CharacterSprite;

            // Flying animation (rows 4 5 6 and 7)
            sprite.AddAnimation(CharacterMode.Flying,
                                OrientedAnimation.Orientation.Forward,
                                spriteSheet,
                                // animation will play at 15 FPS
                                15.0f,
                                frameWidth, frameHeight,
                                // animation begins at row 4
                                4,
                                // It consists of columns 0, 1 and 2 looped forever
                                0, 1, 2);
            sprite.AddAnimation(CharacterMode.Flying,
                                OrientedAnimation.Orientation.Left,
                                spriteSheet,
                                15.0f,
                                frameWidth, frameHeight,
                                5,
                                0, 1, 2);
            sprite.AddAnimation(CharacterMode.Flying,
                                OrientedAnimation.Orientation.Right,
                                spriteSheet,
                                15.0f,
                                frameWidth, frameHeight,
                                6,
                                0, 1, 2);
            sprite.AddAnimation(CharacterMode.Flying,
                                OrientedAnimation.Orientation.Backward,
                                spriteSheet,
                                15.0f,
                                frameWidth, frameHeight,
                                7,
                                0, 1, 2);

            // Hopping animation (rows 0 1 2 and 3)
            sprite.AddAnimation(CharacterMode.Walking, OrientedAnimation.Orientation.Forward, spriteSheet, 5.0f, frameWidth, frameHeight, 0, 0, 1);
            sprite.AddAnimation(CharacterMode.Walking, OrientedAnimation.Orientation.Left, spriteSheet, 5.0f, frameWidth, frameHeight, 1, 0, 1);
            sprite.AddAnimation(CharacterMode.Walking, OrientedAnimation.Orientation.Right, spriteSheet, 5.0f, frameWidth, frameHeight, 2, 0, 1);
            sprite.AddAnimation(CharacterMode.Walking, OrientedAnimation.Orientation.Backward, spriteSheet, 5.0f, frameWidth, frameHeight, 3, 0, 1);

            // Idle animation (rows 0 1 2 and 3)
            sprite.AddAnimation(CharacterMode.Idle, OrientedAnimation.Orientation.Forward, spriteSheet, 5.0f, frameWidth, frameHeight, 0, 0);
            sprite.AddAnimation(CharacterMode.Idle, OrientedAnimation.Orientation.Left, spriteSheet, 5.0f, frameWidth, frameHeight, 1, 0);
            sprite.AddAnimation(CharacterMode.Idle, OrientedAnimation.Orientation.Right, spriteSheet, 5.0f, frameWidth, frameHeight, 2, 0);
            sprite.AddAnimation(CharacterMode.Idle, OrientedAnimation.Orientation.Backward, spriteSheet, 5.0f, frameWidth, frameHeight, 3, 0);

            Sprite.SetFlag(Flag.ShouldSerialize, false);
        }
Ejemplo n.º 3
0
        public Projectile(ComponentManager manager, Vector3 position, Vector3 initialVelocity, Health.DamageAmount damage, float size, string asset, string hitParticles, string hitNoise, GameComponent target, bool animated = false, bool singleSprite = false) :
            base(manager, "Projectile", Matrix.CreateTranslation(position), new Vector3(size, size, size), Vector3.One, 1.0f, 1.0f, 1.0f, 1.0f, new Vector3(0, -10, 0), OrientMode.Fixed)
        {
            this.AllowPhysicsSleep = false;
            Target       = target;
            HitAnimation = null;
            IsSleeping   = false;
            Velocity     = initialVelocity;
            Orientation  = OrientMode.LookAt;
            CollideMode  = Physics.CollisionMode.None;
            var spriteSheet = new SpriteSheet(asset);

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

            // Todo: Needs the cosmetic children treatement.
            if (animated)
            {
                Sprite = AddChild(new AnimatedSprite(Manager, "Sprite", Matrix.CreateRotationY((float)Math.PI * 0.5f))
                {
                    OrientationType = AnimatedSprite.OrientMode.Fixed
                }) as AnimatedSprite;

                var anim = Library.CreateSimpleAnimation(asset);
                anim.Loops = true;
                (Sprite as AnimatedSprite).AddAnimation(anim);

                if (singleSprite)
                {
                    (Sprite as AnimatedSprite).OrientationType = AnimatedSprite.OrientMode.Spherical;
                }
            }
            else
            {
                Sprite = AddChild(new SimpleSprite(Manager, "Sprite", Matrix.CreateRotationY((float)Math.PI * 0.5f), spriteSheet, new Point(0, 0))
                {
                    OrientationType = SimpleSprite.OrientMode.Fixed
                }) as SimpleSprite;
                (Sprite as SimpleSprite).AutoSetWorldSize();
                if (singleSprite)
                {
                    (Sprite as SimpleSprite).OrientationType = SimpleSprite.OrientMode.Spherical;
                }
            }

            Sprite.SetFlag(Flag.ShouldSerialize, false);

            if (!singleSprite)
            {
                if (animated)
                {
                    Sprite2 = Sprite.AddChild(new AnimatedSprite(Manager, "Sprite2",
                                                                 Matrix.CreateRotationY((float)Math.PI * 0.5f) * Matrix.CreateRotationZ((float)Math.PI * 0.5f))
                    {
                        OrientationType = AnimatedSprite.OrientMode.Fixed
                    }) as AnimatedSprite;

                    var anim = Library.CreateSimpleAnimation(asset);
                    anim.Loops = true;
                    (Sprite2 as AnimatedSprite).AddAnimation(anim);
                }
                else
                {
                    Sprite2 = AddChild(new SimpleSprite(Manager, "Sprite", Matrix.CreateRotationY((float)Math.PI * 0.5f) * Matrix.CreateRotationZ((float)Math.PI * 0.5f), spriteSheet, new Point(0, 0))
                    {
                        OrientationType = SimpleSprite.OrientMode.Fixed
                    }) as SimpleSprite;
                    (Sprite2 as SimpleSprite).AutoSetWorldSize();
                }
                Sprite2.SetFlag(Flag.ShouldSerialize, false);
            }

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