Exemplo n.º 1
0
        public void LoadContent(ContentManager content, byte numberOfFrames, Vector2 screenBounds)
        {
            //load texture for the player and solid color texture(1x1 pixels) for health and shield display
            spriteSheet = content.Load <Texture2D>("player/player");
            solidColor  = content.Load <Texture2D>("solidColor");
            shieldTex   = content.Load <Texture2D>("player/playerShield");

            viewport = screenBounds;

            //set up collision mask, whos width and height is the size of each frame
            frameWidth    = (byte)(spriteSheet.Width / numberOfFrames); //spritesheets must be 1 frame tall
            collisionMask = ModifyTexture2D.Crop(spriteSheet, new Rectangle(0, 0, frameWidth, spriteSheet.Height));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a new enemy that falls vertically down the screen
        /// </summary>
        /// <param name="xStart">starting position of the new enemy</param>
        /// <param name="yStart">starting position of the new enemy</param>
        /// <param name="numberOfFrames">number of frames in the spritesheet</param>
        /// <param name="textureToLoad">asset name of the enemy's texture</param>
        /// <param name="difficultyFactor"></param>
        public Enemy(int xStart, int yStart, int numberOfFrames, string textureToLoad, float difficultyFactor)
        {
            location.X  = xStart;
            location.Y  = yStart;
            spriteSheet = content.Load <Texture2D>(textureToLoad);  //object may not exist when LoadContent is called from game class

            //set up collision mask, whos width and height is the size of each frame
            frameWidth    = (byte)(spriteSheet.Width / numberOfFrames); //spritesheets must be 1 frame tall
            collisionMask = ModifyTexture2D.Crop(spriteSheet, new Rectangle(0, 0, frameWidth, spriteSheet.Height));

            //set stats to default values
            health             = (10 * difficultyFactor); //modify health by difficulty
            offscreenAllowance = 2000;
            frameLength        = 85;

            //set rotation to default (zero) and origin to centre of enemy. spriteEffects assigned to default (none).
            rotation      = 0f;
            origin        = new Vector2(collisionMask.Width / 2.0f, collisionMask.Height / 2.0f);
            spriteEffects = SpriteEffects.None;

            numberOfParticles = 5;
        }