Exemple #1
0
        /// <summary>
        /// Initialize function creates all the required components for the bird.
        /// </summary>
        /// <param name="spriteSheet">The sprite sheet to use for the bird</param>
        public void Initialize(SpriteSheet spriteSheet)
        {
            // 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.
            Sprite = new CharacterSprite
                         (Graphics,
                         Manager,
                         "Bird Sprite",
                         Physics,
                         Matrix.CreateTranslation(0, 0.25f, 0)
                         );

            // 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);

            // Used to grab other components
            Hands = new Grabber("hands", Physics, Matrix.Identity, new Vector3(0.1f, 0.1f, 0.1f), Vector3.Zero);

            // Used to sense hostile creatures
            Sensors = new EnemySensor(Manager, "EnemySensor", Physics, Matrix.Identity, new Vector3(20, 5, 20), Vector3.Zero);

            // Controls the behavior of the creature
            AI = new BirdAI(this, "Bird AI", Sensors, PlanService);

            // The bird can peck at its enemies (0.1 damage)
            Attacks = new List <Attack> {
                new Attack("Peck", 0.1f, 2.0f, 1.0f, ContentPaths.Audio.pick, ContentPaths.Effects.flash)
            };


            // The bird can hold one item at a time in its inventory
            Inventory = new Inventory("Inventory", Physics)
            {
                Resources = new ResourceContainer
                {
                    MaxResources = 1
                }
            };

            // The shadow is rotated 90 degrees along X, and is 0.25 blocks beneath the creature
            Matrix shadowTransform = Matrix.CreateRotationX((float)Math.PI * 0.5f);

            shadowTransform.Translation = new Vector3(0.0f, -0.25f, 0.0f);
            shadowTransform            *= Matrix.CreateScale(0.75f);

            SpriteSheet shadowTexture = new SpriteSheet(ContentPaths.Effects.shadowcircle);

            Shadow = new Shadow(Manager, "Shadow", Physics, shadowTransform, shadowTexture);

            // We set up the shadow's animation so that it's just a static black circle
            // TODO: Make the shadow set this up automatically
            List <Point> shP = new List <Point>
            {
                new Point(0, 0)
            };
            Animation shadowAnimation = new Animation(Graphics, new SpriteSheet(ContentPaths.Effects.shadowcircle), "sh", 32, 32, shP, false, Color.Black, 1, 0.7f, 0.7f, false);

            Shadow.AddAnimation(shadowAnimation);
            shadowAnimation.Play();
            Shadow.SetCurrentAnimation("sh");

            // The bird will emit a shower of blood when it dies
            DeathParticleTrigger = new ParticleTrigger("blood_particle", Manager, "Death Gibs", Physics, Matrix.Identity, Vector3.One, Vector3.Zero)
            {
                TriggerOnDeath = true,
                TriggerAmount  = 1
            };

            // The bird is flammable, and can die when exposed to fire.
            Flames = new Flammable(Manager, "Flames", Physics, this);

            // Tag the physics component with some information
            // that can be used later
            Physics.Tags.Add("Bird");
            Physics.Tags.Add("Animal");

            NoiseMaker.Noises.Add("chirp", new List <string>()
            {
                ContentPaths.Audio.bird
            });

            Stats.FullName     = TextGenerator.GenerateRandom("$firstname") + " the bird";
            Stats.CurrentClass = new EmployeeClass()
            {
                Name   = "Bird",
                Levels = new List <EmployeeClass.Level>()
                {
                    new EmployeeClass.Level()
                    {
                        Index = 0, Name = "Bird"
                    }
                }
            };
        }
Exemple #2
0
        /// <summary>
        /// Initialize function creates all the required components for the bird.
        /// </summary>
        /// <param name="spriteSheet">The sprite sheet to use for the bird</param>
        public void Initialize(SpriteSheet spriteSheet)
        {
            // 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.
            Sprite = new CharacterSprite
                                  (Graphics,
                                  Manager,
                                  "Bird Sprite",
                                  Physics,
                                  Matrix.CreateTranslation(0, 0.25f, 0)
                                  );

            // 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);

            // Used to grab other components
            Hands = new Grabber("hands", Physics, Matrix.Identity, new Vector3(0.1f, 0.1f, 0.1f), Vector3.Zero);

            // Used to sense hostile creatures
            Sensors = new EnemySensor(Manager, "EnemySensor", Physics, Matrix.Identity, new Vector3(20, 5, 20), Vector3.Zero);

            // Controls the behavior of the creature
            AI = new BirdAI(this, "Bird AI", Sensors, PlanService);

            // The bird can peck at its enemies (0.1 damage)
            Attacks = new List<Attack>{new Attack("Peck", 0.1f, 2.0f, 1.0f, ContentPaths.Audio.pick, ContentPaths.Effects.flash)};

            // The bird can hold one item at a time in its inventory
            Inventory = new Inventory("Inventory", Physics)
            {
                Resources = new ResourceContainer
                {
                    MaxResources = 1
                }
            };

            // The shadow is rotated 90 degrees along X, and is 0.25 blocks beneath the creature
            Matrix shadowTransform = Matrix.CreateRotationX((float)Math.PI * 0.5f);
            shadowTransform.Translation = new Vector3(0.0f, -0.25f, 0.0f);
            shadowTransform *= Matrix.CreateScale(0.75f);

            SpriteSheet shadowTexture = new SpriteSheet(ContentPaths.Effects.shadowcircle);
            Shadow = new Shadow(Manager, "Shadow", Physics, shadowTransform, shadowTexture);

            // We set up the shadow's animation so that it's just a static black circle
            // TODO: Make the shadow set this up automatically
            List<Point> shP = new List<Point>
            {
                new Point(0, 0)
            };
            Animation shadowAnimation = new Animation(Graphics, new SpriteSheet(ContentPaths.Effects.shadowcircle), "sh", 32, 32, shP, false, Color.Black, 1, 0.7f, 0.7f, false);
            Shadow.AddAnimation(shadowAnimation);
            shadowAnimation.Play();
            Shadow.SetCurrentAnimation("sh");

            // The bird will emit a shower of blood when it dies
            DeathParticleTrigger = new ParticleTrigger("blood_particle", Manager, "Death Gibs", Physics, Matrix.Identity, Vector3.One, Vector3.Zero)
            {
                TriggerOnDeath = true,
                TriggerAmount = 1
            };

            // The bird is flammable, and can die when exposed to fire.
            Flames = new Flammable(Manager, "Flames", Physics, this);

            // Tag the physics component with some information
            // that can be used later
            Physics.Tags.Add("Bird");
            Physics.Tags.Add("Animal");

            NoiseMaker.Noises.Add("chirp", new List<string>(){ContentPaths.Audio.bird});

            Stats.FullName = TextGenerator.GenerateRandom("$firstname") + " the bird";
            Stats.CurrentClass = new EmployeeClass()
            {
                Name = "Bird",
                Levels = new List<EmployeeClass.Level>() { new EmployeeClass.Level() { Index = 0, Name = "Bird" } }
            };
        }