Game-Design / Sprint2 / Sprint2_actual / Concrete ISprites / StaticMovingSprite.cs
StaticMovingSprite.cs
Raw
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Text;

namespace Sprint2_actual
{
    class StaticMovingSprite : ISprite
    {
        public Texture2D Texture { get; set; }
        public int SpriteWidth { get; set; }
        public int SpriteX { get; set; }
        public int SpriteY { get; set; }
        public Vector2 pos;
        private int StartingPosY { get; set; }
        private int spriteSpeed;

        public StaticMovingSprite(Texture2D texture, int spriteWidth, int spriteX, int spriteY, int startingPosX, int startingPosY)
        {
            Texture = texture;
            SpriteWidth = spriteWidth;
            SpriteX = spriteX;
            SpriteY = spriteY;
            pos = new Vector2(startingPosX, startingPosY);
            StartingPosY = startingPosY;
            spriteSpeed = 100;

        }
        public void update(GameTime gameTime)
        {
            pos.Y -= spriteSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            if (pos.Y <= 0 - (SpriteWidth))
                pos.Y = StartingPosY * 2 - (SpriteWidth);
        }

        public void draw()
        {
            Rectangle sourceRectangle = new Rectangle(SpriteX, SpriteY, SpriteWidth, SpriteWidth);
            Rectangle destinationRectangle = new Rectangle((int)pos.X, (int)pos.Y, SpriteWidth, SpriteWidth);

            GlobalVars.spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White);
        }
    }
}