public DemoGameImplementation(GameImages gameTextures, GameSounds gameSounds)
 {
     _gameTextures = gameTextures;
     _gameSounds   = gameSounds;
     _yellowFont   = new BasicFont(gameTextures.YellowFont);
     _world        = new WorldModel(gameTextures, gameSounds, _yellowFont, gameTextures.Ship.Dimensions.Width, gameTextures.Alien1.Dimensions.Width);
 }
Ejemplo n.º 2
0
 static void Main(string[] args)
 {
     try
     {
         SDLCoverLibrary.Init.WithSDLDo(
             () =>
         {
             var mainWindowSize = new Dimensions {
                 Width = 1280, Height = 800
             };
             var retroScreenSize = new Dimensions {
                 Width = 320, Height = 256
             };
             var mainWindow = new Window("Waters Alien Raiders Shoot'em Side Scroller Game", mainWindowSize);
             var gameImages = new GameImages(mainWindow.Renderer);
             var gameSounds = new GameSounds();
             mainWindow.RunUsing(new DemoGameImplementation(gameImages, gameSounds), retroScreenSize);
         }
             );
     }
     catch (Exception e)
     {
         Console.WriteLine("Unhandled exception during program: " + e.ToString());
         Console.Write(e.StackTrace);
     }
 }
Ejemplo n.º 3
0
 public WorldModel(GameImages gameTextures, GameSounds gameSounds, BasicFont yellowFont, int shipWidth, int alienWidth)
 {
     YellowFont            = yellowFont;
     Images                = gameTextures;
     Sounds                = gameSounds;
     Ship.Width            = shipWidth; // Quiz:  Why store this?
     AlienModel.AlienWidth = alienWidth;
 }
Ejemplo n.º 4
0
 public static void ConsiderRespawningShip(double gameTimeSeconds, ShipModel ship, GameSounds gameSounds)
 {
     if (ship.IsDestroyed)
     {
         double elapsedTime = gameTimeSeconds - ship.TimeOfDestruction;
         if (elapsedTime > ShipModel.RespawnDelay)
         {
             ship.IsDestroyed = false;
             gameSounds.ExtraLifeSound.Play();
         }
     }
 }
Ejemplo n.º 5
0
        public static void CheckIfShipShot(double gameTimeSeconds, ShipModel ship, AlienListModel aliensList, AlienBulletListModel alienBulletList, ExplosionListModel explosions, GameSounds gameSounds)
        {
            if (!ship.IsDestroyed)
            {
                bool shipDestroyed =
                    alienBulletList.AlienBullets.Exists(b => CollisionDetection.Hits(b.CentrePoint, ship.CentrePoint, CollisionDetectRange)) ||
                    aliensList.Aliens.Exists(a => CollisionDetection.Hits(a.CentrePoint, ship.CentrePoint, CollisionDetectRange));

                if (shipDestroyed)
                {
                    DestroyShip(gameTimeSeconds, ship, explosions, gameSounds);
                }
            }
        }
Ejemplo n.º 6
0
 public static void DestroyShip(double gameTimeSeconds, ShipModel ship, ExplosionListModel explosions, GameSounds gameSounds)
 {
     ship.IsDestroyed       = true;
     ship.TimeOfDestruction = gameTimeSeconds;
     AddExplosion(gameTimeSeconds, ship.CentrePoint, explosions, gameSounds);
 }
Ejemplo n.º 7
0
 public static void CheckIfAlienShot(double gameTimeSeconds, AlienListModel alienList, ShipBulletListModel shipBulletsList, ExplosionListModel explosionsList, ScoreModel Scoring, GameSounds gameSounds)
 {
     CheckIfAlienShotAndThen(
         gameTimeSeconds, alienList, shipBulletsList, alien =>
     {
         AddExplosion(gameTimeSeconds, alien.CentrePoint, explosionsList, gameSounds);
         Scoring.SetScore(Scoring.Score + 1);
     });
 }
Ejemplo n.º 8
0
 public static void AddExplosion(double gameTimeSeconds, Point explosionCentre, ExplosionListModel explosionList, GameSounds gameSounds)
 {
     explosionList.Explosions.Add(new ExplosionModel(explosionCentre, gameTimeSeconds));
     gameSounds.ExplosionSound.Play();
 }
Ejemplo n.º 9
0
 public static void ConsiderPlayerFiring(double gameTimeSeconds, Input input, ShipBulletListModel shipBulletList, ShipModel ship, GameSounds gameSounds)
 {
     if (!ship.IsDestroyed && input.Fire.JustDown)
     {
         var elapsedTime = gameTimeSeconds - ship.MostRecentPlayerFiringTime;
         if (elapsedTime > ShipModel.MinFiringIntervalForPlayer)
         {
             shipBulletList.ShipBullets.Add(new ShipBulletModel(ship.CentrePoint.ShuntedBy(ship.Width, 0)));
             ship.MostRecentPlayerFiringTime = gameTimeSeconds; // Quiz:  Why are we doing this?
             gameSounds.PlayerFiringSound.Play();
         }
     }
 }
Ejemplo n.º 10
0
 public static void CauseAlienToFire(AlienModel alien, AlienBulletListModel alienBulletList, GameSounds gameSounds)      // Quiz:   What future purpose have I catered for by separating this out?  If you can guess, how could that purpose be fulfilled?
 {
     alienBulletList.AlienBullets.Add(new AlienBulletModel(alien.CentrePoint.ShuntedBy(-AlienModel.AlienWidth, 0)));
     gameSounds.EnemyFiringSound.Play();
 }
Ejemplo n.º 11
0
 public static void ConsiderAddingAlien(double gameTimeSeconds, ShipModel ship, AlienListModel alienList, Random randomGenerator, AlienBulletListModel alienBulletList, GameSounds gameSounds)
 {
     if (!ship.IsDestroyed)  // Quiz:  Why not add aliens in the period while the ship is "destroyed"?
     {
         ConsiderAddingAlienAndThen(gameTimeSeconds, alienList, randomGenerator, alien =>
         {
             if (randomGenerator.Next(0, 100) > AlienModel.PercentChangeAlienFiresWhenCreated)    // Quiz:   Does my hard-coded constant really 100 matter here?  Is this bad practice?
             {
                 CauseAlienToFire(alien, alienBulletList, gameSounds);
             }
         });
     }
 }