// parse a collection of sprite sheets from a specified sprite sheet data file
        public static SpriteSheetCollection parseFrom(String fileName, ContentManager content)
        {
            if(fileName == null || !File.Exists(fileName)) { return null; }

            StreamReader instream;
            SpriteSheet spriteSheet;
            SpriteSheetCollection spriteSheets = new SpriteSheetCollection();

            // open the sprite sheet data file and parse until either:
            // an invalid sprite sheet is encountered
            // or the end of the file is encountered
            try {
                instream = File.OpenText(fileName);

                do {
                    // parse the sprite sheet and store it
                    spriteSheet = SpriteSheet.parseFrom(instream, content);
                    spriteSheets.addSpriteSheet(spriteSheet);
                } while(spriteSheet != null);

                instream.Close();
            }
            catch(Exception) { return null; }

            return spriteSheets;
        }
示例#2
0
        protected override void LoadContent()
        {
            // initialize sprite batching and the sprite sheet collection
            spriteBatch  = new SpriteBatch(GraphicsDevice);
            spriteSheets = SpriteSheetCollection.parseFrom(settings.spriteSheetFileName, content);
            if (spriteSheets == null)
            {
                Exit();
            }

            // initialize the game management systems
            projectileSystem = new ProjectileSystem(spriteSheets, settings, content);
            spaceShipSystem  = new SpaceShipSystem(spriteSheets, projectileSystem, settings, content);
            asteroidSystem   = new AsteroidSystem(spriteSheets, spaceShipSystem, settings);
            explosionSystem  = new ExplosionSystem(spriteSheets, content);
            scoreSystem      = new ScoreSystem(spaceShipSystem, content, settings);
            collisionSystem  = new CollisionSystem(projectileSystem, spaceShipSystem, asteroidSystem, explosionSystem, scoreSystem);

            // initialize the menu
            menu = new Menu(this, spaceShipSystem, settings, content);

            // load and start the background music (if appropriate)
            backgroundMusic         = content.Load <Song>("myg0t");
            MediaPlayer.IsRepeating = true;
            if (settings.musicEnabled)
            {
                MediaPlayer.Play(backgroundMusic);
            }
        }
        // parse a collection of sprite sheets from a specified sprite sheet data file
        public static SpriteSheetCollection parseFrom(String fileName, ContentManager content)
        {
            if (fileName == null || !File.Exists(fileName))
            {
                return(null);
            }

            StreamReader          instream;
            SpriteSheet           spriteSheet;
            SpriteSheetCollection spriteSheets = new SpriteSheetCollection();

            // open the sprite sheet data file and parse until either:
            // an invalid sprite sheet is encountered
            // or the end of the file is encountered
            try {
                instream = File.OpenText(fileName);

                do
                {
                    // parse the sprite sheet and store it
                    spriteSheet = SpriteSheet.parseFrom(instream, content);
                    spriteSheets.addSpriteSheet(spriteSheet);
                } while(spriteSheet != null);

                instream.Close();
            }
            catch (Exception) { return(null); }

            return(spriteSheets);
        }
示例#4
0
        public ProjectileSystem(SpriteSheetCollection spriteSheets, GameSettings settings, ContentManager content)
        {
            m_projectiles = new List <Projectile>();

            // load the projectile sprites and create an animation from them
            if (spriteSheets != null)
            {
                m_projectileSprites = spriteSheets.getSpriteSheet("Projectiles");
            }

            if (m_projectileSprites != null)
            {
                m_projectileAnimations = new SpriteAnimation[4];

                for (int i = 0; i < 4; i++)
                {
                    m_projectileAnimations[i] = new SpriteAnimation(0.18f, SpriteAnimationType.Loop);
                    m_projectileAnimations[i].addSprite(m_projectileSprites.getSprite(i * 2));
                    m_projectileAnimations[i].addSprite(m_projectileSprites.getSprite(i * 2 + 1));
                }
            }

            // load the laser sound
            if (content != null)
            {
                m_laserSound = content.Load <SoundEffect>("Laser");
            }

            m_settings = settings;
        }
示例#5
0
        public ProjectileSystem(SpriteSheetCollection spriteSheets, GameSettings settings, ContentManager content)
        {
            m_projectiles = new List<Projectile>();

            // load the projectile sprites and create an animation from them
            if(spriteSheets != null) {
                m_projectileSprites = spriteSheets.getSpriteSheet("Projectiles");
            }

            if(m_projectileSprites != null) {
                m_projectileAnimations = new SpriteAnimation[4];

                for(int i=0;i<4;i++) {
                    m_projectileAnimations[i] = new SpriteAnimation(0.18f, SpriteAnimationType.Loop);
                    m_projectileAnimations[i].addSprite(m_projectileSprites.getSprite(i * 2));
                    m_projectileAnimations[i].addSprite(m_projectileSprites.getSprite(i * 2 + 1));
                }
            }

            // load the laser sound
            if(content != null) {
                m_laserSound = content.Load<SoundEffect>("Laser");
            }

            m_settings = settings;
        }
示例#6
0
 public ExplosionSystem(SpriteSheetCollection spriteSheets, ContentManager content)
 {
     m_explosions = new List<Explosion>();
     if(spriteSheets != null) {
         m_explosionSprites = spriteSheets.getSpriteSheet("Explosion");
     }
     m_explosionSound = content.Load<SoundEffect>("Explosion");
 }
示例#7
0
 public ExplosionSystem(SpriteSheetCollection spriteSheets, ContentManager content)
 {
     m_explosions = new List <Explosion>();
     if (spriteSheets != null)
     {
         m_explosionSprites = spriteSheets.getSpriteSheet("Explosion");
     }
     m_explosionSound = content.Load <SoundEffect>("Explosion");
 }
示例#8
0
        public AsteroidSystem(SpriteSheetCollection spriteSheets, SpaceShipSystem spaceShipSystem, GameSettings settings)
        {
            m_asteroids = new List<Asteroid>();
            if(spriteSheets != null) {
                m_asteroidSprites = spriteSheets.getSpriteSheet("Asteroids");
            }
            m_spaceShipSystem = spaceShipSystem;
            m_settings = settings;

            m_maxSmallAsteroids = 12;
            m_maxBigAsteroids = 10;
        }
示例#9
0
        public AsteroidSystem(SpriteSheetCollection spriteSheets, SpaceShipSystem spaceShipSystem, GameSettings settings)
        {
            m_asteroids = new List <Asteroid>();
            if (spriteSheets != null)
            {
                m_asteroidSprites = spriteSheets.getSpriteSheet("Asteroids");
            }
            m_spaceShipSystem = spaceShipSystem;
            m_settings        = settings;

            m_maxSmallAsteroids = 12;
            m_maxBigAsteroids   = 10;
        }
示例#10
0
        public SpaceShipSystem(int numberOfSpaceShips, SpriteSheetCollection spriteSheets, ProjectileSystem projectileSystem, GameSettings settings, ContentManager content)
        {
            this.numberOfSpaceShips = numberOfSpaceShips;
            if(spriteSheets != null) {
                m_spaceShipSprites = spriteSheets.getSpriteSheet("SpaceShip");
            }
            m_projectileSystem = projectileSystem;
            m_settings = settings;

            // initialize all space ships
            if(m_settings == null || content == null || m_spaceShipSprites == null) { return; }
            m_spaceShips = new SpaceShip[m_maxSpaceShips];
            m_spaceShips[0] = new SpaceShip(PlayerIndex.One, new Vector2(settings.screenWidth * 0.2f, settings.screenHeight * 0.2f), 135, m_spaceShipSprites, projectileSystem, settings, content);
            m_spaceShips[1] = new SpaceShip(PlayerIndex.Two, new Vector2(settings.screenWidth * 0.8f, settings.screenHeight * 0.8f), -45, m_spaceShipSprites, projectileSystem, settings, content);
            m_spaceShips[2] = new SpaceShip(PlayerIndex.Three, new Vector2(settings.screenWidth * 0.2f, settings.screenHeight * 0.8f), 45, m_spaceShipSprites, projectileSystem, settings, content);
            m_spaceShips[3] = new SpaceShip(PlayerIndex.Four, new Vector2(settings.screenWidth * 0.8f, settings.screenHeight * 0.2f), -135, m_spaceShipSprites, projectileSystem, settings, content);
        }
示例#11
0
        public SpaceShipSystem(int numberOfSpaceShips, SpriteSheetCollection spriteSheets, ProjectileSystem projectileSystem, GameSettings settings, ContentManager content)
        {
            this.numberOfSpaceShips = numberOfSpaceShips;
            if (spriteSheets != null)
            {
                m_spaceShipSprites = spriteSheets.getSpriteSheet("SpaceShip");
            }
            m_projectileSystem = projectileSystem;
            m_settings         = settings;

            // initialize all space ships
            if (m_settings == null || content == null || m_spaceShipSprites == null)
            {
                return;
            }
            m_spaceShips    = new SpaceShip[m_maxSpaceShips];
            m_spaceShips[0] = new SpaceShip(PlayerIndex.One, new Vector2(settings.screenWidth * 0.2f, settings.screenHeight * 0.2f), 135, m_spaceShipSprites, projectileSystem, settings, content);
            m_spaceShips[1] = new SpaceShip(PlayerIndex.Two, new Vector2(settings.screenWidth * 0.8f, settings.screenHeight * 0.8f), -45, m_spaceShipSprites, projectileSystem, settings, content);
            m_spaceShips[2] = new SpaceShip(PlayerIndex.Three, new Vector2(settings.screenWidth * 0.2f, settings.screenHeight * 0.8f), 45, m_spaceShipSprites, projectileSystem, settings, content);
            m_spaceShips[3] = new SpaceShip(PlayerIndex.Four, new Vector2(settings.screenWidth * 0.8f, settings.screenHeight * 0.2f), -135, m_spaceShipSprites, projectileSystem, settings, content);
        }
示例#12
0
        protected override void LoadContent()
        {
            // initialize sprite batching and the sprite sheet collection
            spriteBatch = new SpriteBatch(GraphicsDevice);
            spriteSheets = SpriteSheetCollection.parseFrom(settings.spriteSheetFileName, content);
            if(spriteSheets == null) { Exit(); }

            // initialize the game management systems
            projectileSystem = new ProjectileSystem(spriteSheets, settings, content);
            spaceShipSystem = new SpaceShipSystem(spriteSheets, projectileSystem, settings, content);
            asteroidSystem = new AsteroidSystem(spriteSheets, spaceShipSystem, settings);
            explosionSystem = new ExplosionSystem(spriteSheets, content);
            scoreSystem = new ScoreSystem(spaceShipSystem, content, settings);
            collisionSystem = new CollisionSystem(projectileSystem, spaceShipSystem, asteroidSystem, explosionSystem, scoreSystem);

            // initialize the menu
            menu = new Menu(this, spaceShipSystem, settings, content);

            // load and start the background music (if appropriate)
            backgroundMusic = content.Load<Song>("myg0t");
            MediaPlayer.IsRepeating = true;
            if(settings.musicEnabled) {
                MediaPlayer.Play(backgroundMusic);
            }
        }
示例#13
0
 public SpaceShipSystem(SpriteSheetCollection spriteSheets, ProjectileSystem projectileSystem, GameSettings settings, ContentManager content)
     : this(0, spriteSheets, projectileSystem, settings, content)
 {
 }
示例#14
0
 public SpaceShipSystem(SpriteSheetCollection spriteSheets, ProjectileSystem projectileSystem, GameSettings settings, ContentManager content) :
     this(0, spriteSheets, projectileSystem, settings, content)
 {
 }