Example #1
0
 /// <summary>
 /// Initialize the sprite.
 /// </summary>
 /// <param name="manager">The manager this sprite is a part of.</param>
 /// <param name="name">The name of the frame.</param>
 private void Initialize(SpriteManager manager, string name)
 {
     //Initialize some variables.
     _Manager = manager;
     _Name = name;
     _Position = Vector2.Zero;
     _TimePerFrame = 1;
     _Scale = 1;
     _Depth = 0;
     _Rotation = 0;
     _PositionOffset = Vector2.Zero;
     _OrbitOffset = 0;
     _RotationOffset = 0;
     _Tag = "";
     _Transparence = 1;
     _Visibility = Visibility.Visible;
     _Orientation = Orientation.Right;
     _Frames = new List<Frame>();
 }
Example #2
0
 /// <summary>
 /// Initialize the creature.
 /// </summary>
 private void Initialize()
 {
     //Initialize the class.
     _Gender = Gender.Male;
     _Types = new List<PokemonType>();
     _Moves = new List<Move>();
     _Sprite = new SpriteManager();
     _MaxEnergy = 100;
     _CurrentEnergy = _MaxEnergy;
     _Position = Vector2.Zero;
     _Velocity = Vector2.Zero;
     _TimeBetweenMoving = .01f;
     _ElapsedMovementTime = 0;
     _ElapsedEnergyTime = 0;
     _EnergyRecoverySpeed = .1f;
     _BattleState = BattleState.Idle;
     _FacingDirection = Direction.Down;
     _MovementSpeed = InsipidusEngine.SpeedType.Still;
 }
Example #3
0
 /// <summary>
 /// Constructor a sprite.
 /// </summary>
 /// <param name="manager">The manager this sprite is a part of.</param>
 /// <param name="name">The name of the sprite. Has nothing to do with the path of any sprite.</param>
 public Sprite(SpriteManager manager, string name)
 {
     Initialize(manager, name);
 }
Example #4
0
 /// <summary>
 /// Initialize the projectile.
 /// </summary>
 /// <param name="position">The starting position of the projectile.</param>
 /// <param name="destination">The projectile's destination.</param>
 protected virtual void Initialize(Vector2 position, Destination destination)
 {
     //Initialize some fields.
     _Sprite = new SpriteManager();
     _Position = position;
     _Destination = destination;
     _Velocity = new Vector2();
 }
        /// <summary>
        /// Clone this sprite manager and all its sprites.
        /// </summary>
        /// <returns>A clone of this sprite manager.</returns>
        public SpriteManager Clone()
        {
            //Create the clone.
            SpriteManager manager = new SpriteManager();

            //Clone the properties.
            manager.ContentManager = _ContentManager;

            //Clone the sprites.
            foreach (Sprite sprite in _Sprites)
            {
                //Create the cloned sprite.
                Sprite sClone = new Sprite(manager, sprite.Name);

                //Clone the properties.
                sClone.Position = sprite.Position;
                sClone.TimePerFrame = sprite.TimePerFrame;
                sClone.Scale = sprite.Scale;
                sClone.Depth = sprite.Depth;
                sClone.Rotation = sprite.Rotation;
                sClone.PositionOffset = sprite.PositionOffset;
                sClone.OrbitOffset = sprite.OrbitOffset;
                sClone.RotationOffset = sprite.RotationOffset;
                sClone.Tag = sprite.Tag;
                sClone.Transparence = sprite.Transparence;
                sClone.Visibility = sprite.Visibility;
                sClone.Orientation = sprite.Orientation;

                //Clone the frames.
                foreach (Frame frame in sprite.Frames)
                {
                    //Create the cloned frame.
                    Frame fClone = new Frame(frame.ColorPath, frame.Width, frame.Height);

                    //Clone the properties.
                    fClone.ColorPath = frame.ColorPath;
                    fClone.Width = frame.Width;
                    fClone.Height = frame.Height;
                    fClone.Origin = frame.Origin;
                    fClone.Texture = frame.Texture;

                    //Add the cloned frame to the cloned sprite.
                    sClone.AddFrame(fClone);
                }

                //Add the cloned sprite to the cloned manager.
                manager.Add(sClone);
            }

            //Make sure that all sprites have been properly activated.
            manager.ManageSprites();

            //Return the clone.
            return manager;
        }
Example #6
0
        /// <summary>
        /// Load content.
        /// </summary>
        /// <param name="content">The content manager to use.</param>
        public void LoadContent(ContentManager content)
        {
            // Clear all sprites.
            _Sprites = new SpriteManager();

            // Front.
            Sprite front = _Sprites.Add(new Sprite(_Sprites, "Front"));
            front.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Front[1]");
            front.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Front[2]");
            front.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Front[3]");

            // Back.
            Sprite back = _Sprites.Add(new Sprite(_Sprites, "Back"));
            back.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Back[0]");
            back.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Back[1]");
            back.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Back[2]");
            back.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Back[3]");

            // Right.
            Sprite right = _Sprites.Add(new Sprite(_Sprites, "Right"));
            right.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Right[0]");
            right.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Right[1]");
            right.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Right[2]");

            // Left.
            Sprite left = _Sprites.Add(new Sprite(_Sprites, "Left"));
            left.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Left[0]");
            left.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Left[1]");
            left.AddFrame(@"Characters\ZombieGuy\ZombieGuy1_Left[2]");

            // Only make one sprite visible.
            back.Visibility = Visibility.Invisible;
            right.Visibility = Visibility.Invisible;
            left.Visibility = Visibility.Invisible;

            //Set the frame-rate.
            front.TimePerFrame = .1f;
            back.TimePerFrame = .1f;
            right.TimePerFrame = .1f;
            left.TimePerFrame = .1f;

            // Current sprite is facing up.
            _CurrentSprite = front;

            // Load all sprites' content.
            _Sprites.LoadContent(content);

            //Update the frames' origin.
            front.Frames.ForEach(item => item.Origin = new Vector2(item.Width / 2, item.Height / 2));
            back.Frames.ForEach(item => item.Origin = new Vector2(item.Width / 2, item.Height / 2));
            right.Frames.ForEach(item => item.Origin = new Vector2(item.Width / 2, item.Height / 2));
            left.Frames.ForEach(item => item.Origin = new Vector2(item.Width / 2, item.Height / 2));

            // Set the shape of the body.
            _Body.Shape.Width = 15;
            _Body.Shape.Height = 15;
            _Body.Shape.Depth = _Sprites[0][_Sprites[0].CurrentFrameIndex].Height / 3;

            // Update the sprites' position offset.
            front.PositionOffset = new Vector2(0, -front[front.CurrentFrameIndex].Origin.Y + (_Body.Shape.Height / 2));
            back.PositionOffset = new Vector2(0, -back[back.CurrentFrameIndex].Origin.Y + (_Body.Shape.Height / 2));
            right.PositionOffset = new Vector2(0, -right[right.CurrentFrameIndex].Origin.Y + (_Body.Shape.Height / 2));
            left.PositionOffset = new Vector2(0, -left[left.CurrentFrameIndex].Origin.Y + (_Body.Shape.Height / 2));
        }
Example #7
0
 /// <summary>
 /// Initialize the scene.
 /// </summary>
 /// <param name="scene">The scene this entity is part of.</param>
 protected virtual void Initialize(Scene scene)
 {
     // Initialize the variables.
     _Name = "";
     _Scene = scene;
     _Sprites = new SpriteManager();
     _Body = new Body(_Scene != null ? _Scene.PhysicsSimulator : null);
     _Body.Entity = this;
     _Body.AddBody();
 }
Example #8
0
        /// <summary>
        /// Load content and add a sprite.
        /// </summary>
        /// <param name="contentManager">The content manager to use.</param>
        /// <param name="spritePath">The path to the main sprite.</param>
        /// <param name="height">The height of the shape as seen on picture. This is used for collision data.
        /// -1 results in the use of the full height of the sprite and a depth of 1.</param>
        public virtual void LoadContent(ContentManager contentManager, String spritePath, float height)
        {
            //Clear all sprites.
            _Sprites = new SpriteManager();

            //Add the color texture.
            Sprite sprite = _Sprites.Add(new Sprite(_Sprites, "Entity"));
            sprite.AddFrame(spritePath);

            //Load all sprites' content.
            _Sprites.LoadContent(contentManager);

            //Update the frame's origin.
            sprite.Frames[0].Origin = new Vector2(sprite.Frames[0].Width / 2, sprite.Frames[0].Height / 2);

            //Check if the normal and depth maps exist.
            bool n = File.Exists(Path.Combine(contentManager.RootDirectory, spritePath + "(Normal)" + ".xnb"));
            bool d = File.Exists(Path.Combine(contentManager.RootDirectory, spritePath + "(Depth)" + ".xnb"));

            //Set the normal and depth maps.
            _Sprites[0].Frames[0].NormalPath = n ? spritePath + "(Normal)" : @"Entities\DepthDefault";
            _Sprites[0].Frames[0].DepthPath = d ? spritePath + "(Depth)" : @"Entities\DepthDefault";

            // Set the shape of the body.
            _Body.Shape.Width = sprite.CurrentFrame.Width;
            _Body.Shape.Height = (height == -1) ? sprite.CurrentFrame.Height : height;
            _Body.Shape.Depth = (height == -1) ? 1 : sprite.CurrentFrame.Height - height;

            //Update the sprite's position offset.
            _Sprites[0].PositionOffset = new Vector2(0, -sprite.CurrentFrame.Origin.Y + (_Body.Shape.Height / 2));
        }