//Called when the game ends i.e the player loses all their lives public void GameOver() { HighscoresContainer highscoresContainer = FindObjectOfType <HighscoresContainer>(); BlockOfAliens blockOfAliens = FindObjectOfType <BlockOfAliens>(); FlyingSaucer flyingSaucer = FindObjectOfType <FlyingSaucer>(); int numHighscores = highscoresContainer.GetNumberOfHighScores(); int lowestScore = highscoresContainer.GetLowestScore(); //If there are less than 10 highscores or the player got a score greater than the lowest high score //Then the player has just got a highscore so... if (numHighscores < 10 || score > lowestScore) { //Stop the aliens and flying saucer from moving blockOfAliens.SetPaused(true); flyingSaucer.gameObject.SetActive(false); //Make the add score panel active and give the add score script the new score addScore.gameObject.SetActive(true); addScore.SetScore(score); } //Else the player didnt get a high score so... else { //Stop the aliens and flying saucer from moving blockOfAliens.SetPaused(true); flyingSaucer.gameObject.SetActive(false); //Display the game over panel gameOver.SetActive(true); } //Pause the game Time.timeScale = 0f; }
public override void Execute(float deltaTime) { Composite pFlyingSaucerRoot = GameStateManager.GetGame().GetStateCompositeManager().Find(Composite.CompositeName.FlyingSaucerRoot); // If there is not already a flying saucer on screen if (pFlyingSaucerRoot.GetFirstChild() == null) { // Identify random starting location (left or right) // 0 == Left, 1 == Right int randomStart = r.Next(0, 2); float xPos = 65 + (randomStart * 770.0f); float xDelta = (randomStart == 0) ? 10.0f : -10.0f; float yPos = 735.0f; FlyingSaucer pFlyingSaucer = new FlyingSaucer(GameObject.Name.FlyingSaucer, Sprite.Name.FlyingSaucer, xPos, yPos); GameStateManager.GetGame().GetStateGameObjectManager().Attach(pFlyingSaucer); GameStateManager.GetGame().GetStateCompositeManager().Find(Composite.CompositeName.FlyingSaucerRoot).Add(pFlyingSaucer); pFlyingSaucer.ActivateSprite(GameStateManager.GetGame().GetStateSpriteBatchManager().Find(SpriteBatch.Name.FlyingSaucer)); pFlyingSaucer.ActivateCollisionSprite(GameStateManager.GetGame().GetStateSpriteBatchManager().Find(SpriteBatch.Name.CollisionBox)); FlyingSaucerMovement pFlyingSaucerMovement = new FlyingSaucerMovement(GameObject.Name.FlyingSaucer, xDelta, 0.0f); TimerManager.Add(TimeEvent.Name.SpriteMovement, pFlyingSaucerMovement, 0.1f); TimerManager.Add(TimeEvent.Name.DropBomb, new DropFlyingSaucerBombCommand(), (float)r.NextDouble()); } }
public override void VisitFlyingSaucer(FlyingSaucer fs) { // Notify Observers CollisionPair pColPair = CollisionPairManager.GetActiveColPair(); Debug.Assert(pColPair != null); pColPair.SetCollision(fs, this); pColPair.NotifyListeners(); }
public override void VisitFlyingSaucer(FlyingSaucer fs) { // Debug.WriteLine("collide: {0} with {1}", a, this); // FlyingSaucer vs Wall CollisionPair pColPair = CollisionPairManager.GetActiveColPair(); Debug.Assert(pColPair != null); pColPair.SetCollision(fs, this); pColPair.NotifyListeners(); }
public override void Execute(float deltaTime) { Composite pFlyingSaucerRoot = GameStateManager.GetGame().GetStateCompositeManager().Find(Composite.CompositeName.FlyingSaucerRoot); // If Flying Saucer is on screen if (pFlyingSaucerRoot.GetFirstChild() != null) { Composite pBombRoot = GameStateManager.GetGame().GetStateCompositeManager().Find(Composite.CompositeName.BombRoot); // Identify random Column + starting location int randomColIndex = r.Next(0, pFlyingSaucerRoot.GetNumOfChildren()); FlyingSaucer pFlyingSaucer = (FlyingSaucer)pFlyingSaucerRoot.GetFirstChild(); Azul.Rect pFlyingSaucerColCollisionRect = pFlyingSaucer.GetCollisionObject().GetCollisionRect(); float xPos = (pFlyingSaucerColCollisionRect.x + (pFlyingSaucerColCollisionRect.width / 2.0f)); float yPos = (pFlyingSaucerColCollisionRect.y - (pFlyingSaucerColCollisionRect.height / 2.0f)); // Identify random Bomb Type and create bomb FallStrategy bombStrategy = null; int bombType = r.Next(0, 3); if (bombType == 0) { bombType = (int)Sprite.Name.BombStraight; bombStrategy = new FallStraight(); } else if (bombType == 1) { bombType = (int)Sprite.Name.BombZigZag; bombStrategy = new FallZigZag(); } else { bombType = (int)Sprite.Name.BombCross; bombStrategy = new FallDagger(); } // TODO refactor to use Object Pool FlyingSaucerBomb pBomb = new FlyingSaucerBomb(GameObject.Name.FlyingSaucerBomb, (Sprite.Name)bombType, bombStrategy, xPos, yPos); // Attach to BombRoot, SpriteBatches, and any related managers GameStateManager.GetGame().GetStateCompositeManager().Find(Composite.CompositeName.BombRoot).Add(pBomb); GameStateManager.GetGame().GetStateGameObjectManager().Attach(pBomb); pBomb.ActivateCollisionSprite(GameStateManager.GetGame().GetStateSpriteBatchManager().Find(SpriteBatch.Name.CollisionBox)); pBomb.ActivateSprite(GameStateManager.GetGame().GetStateSpriteBatchManager().Find(SpriteBatch.Name.Bomb)); } }
public void Create(Alien.Type type, float posX, float posY) { GameObject pGameObj = null; switch (type) { case Alien.Type.Crab: pGameObj = new CrabAlien(GameObject.Name.CrabAlien, Sprite.Name.CrabAlien, posX, posY); break; case Alien.Type.FlyingSaucer: pGameObj = new FlyingSaucer(GameObject.Name.FlyingSaucer, Sprite.Name.FlyingSaucer, posX, posY); break; case Alien.Type.JellyFish: pGameObj = new JellyfishAlien(GameObject.Name.JellyFishAlien, Sprite.Name.JellyfishAlien, posX, posY); break; case Alien.Type.Squid: pGameObj = new SquidAlien(GameObject.Name.SquidAlien, Sprite.Name.SquidAlien, posX, posY); break; default: // something is wrong Debug.Assert(false); break; } // Add to GameObjectManager Debug.Assert(pGameObj != null); GameStateManager.GetGame().GetStateGameObjectManager().Attach(pGameObj); // Add to Composite pComposite.Add(pGameObj); // Attach to SpriteBatch pGameObj.ActivateSprite(this.pAlienSpriteBatch); pGameObj.ActivateCollisionSprite(this.pCollisionBoxSpriteBatch); }
public override void LoadContent() { // Set to current state for initialization GameStateManager.GetGame().SetGameState(GameStateManager.GameState.Attract); //--------------------------------------------------------------------------------------------------------- // Initialize State-Scoped Managers //--------------------------------------------------------------------------------------------------------- this.pSpriteBatchManager = new SpriteBatchManager(3, 1); this.pGameObjectManager = new GameObjectManager(10, 5); this.pQueuedTimeEventManager = new QueuedTimeEventManager(20, 5); this.pDelayedObjectManager = new DelayedObjectManager(); //--------------------------------------------------------------------------------------------------------- // Create Colors //--------------------------------------------------------------------------------------------------------- //pGreenColor = new Azul.Color(0.1137f, 0.8196f, 0.2667f, 1.0f); //--------------------------------------------------------------------------------------------------------- // Create SpriteBatches //--------------------------------------------------------------------------------------------------------- SpriteBatch pTexts_SpriteBatch = this.pSpriteBatchManager.Add(SpriteBatch.Name.AttractTexts); SpriteBatch pAlien_SpriteBatch = this.pSpriteBatchManager.Add(SpriteBatch.Name.Attract_Aliens); //--------------------------------------------------------------------------------------------------------- // Aliens //--------------------------------------------------------------------------------------------------------- FlyingSaucer pFlyingSaucer = new FlyingSaucer(GameObject.Name.FlyingSaucer, Sprite.Name.FlyingSaucer, 300, 400); this.pGameObjectManager.Attach(pFlyingSaucer); pFlyingSaucer.ActivateSprite(pAlien_SpriteBatch); SquidAlien pSquidAlien = new SquidAlien(GameObject.Name.SquidAlien, Sprite.Name.SquidAlien, 300, 350); this.pGameObjectManager.Attach(pSquidAlien); pSquidAlien.ActivateSprite(pAlien_SpriteBatch); CrabAlien pCrabAlien = new CrabAlien(GameObject.Name.CrabAlien, Sprite.Name.CrabAlien, 300, 300); this.pGameObjectManager.Attach(pCrabAlien); pCrabAlien.ActivateSprite(pAlien_SpriteBatch); JellyfishAlien pJellyfishAlien = new JellyfishAlien(GameObject.Name.JellyFishAlien, Sprite.Name.JellyfishAlien, 300, 250); this.pGameObjectManager.Attach(pJellyfishAlien); pJellyfishAlien.ActivateSprite(pAlien_SpriteBatch); //--------------------------------------------------------------------------------------------------------- // Fonts //--------------------------------------------------------------------------------------------------------- FontManager.Add(Font.Name.Attract_Play, pTexts_SpriteBatch, "PLAY", Glyph.Name.Consolas36pt, 385, 650); FontManager.Add(Font.Name.Attract_Title, pTexts_SpriteBatch, "SPACE INVADERS", Glyph.Name.Consolas36pt, 290, 550); FontManager.Add(Font.Name.Attract_ScoreAdvanceTable, pTexts_SpriteBatch, "* SCORE ADVANCE TABLE *", Glyph.Name.Consolas36pt, 225, 450); FontManager.Add(Font.Name.Attract_FlyingSaucerPoints, pTexts_SpriteBatch, "= ? MYSTERY", Glyph.Name.Consolas36pt, 350, 400); FontManager.Add(Font.Name.Attract_SquidPoints, pTexts_SpriteBatch, "= 30 POINTS", Glyph.Name.Consolas36pt, 350, 350); FontManager.Add(Font.Name.Attract_CrabPoints, pTexts_SpriteBatch, "= 20 POINTS", Glyph.Name.Consolas36pt, 350, 300); FontManager.Add(Font.Name.Attract_JellyfishPoints, pTexts_SpriteBatch, "= 10 POINTS", Glyph.Name.Consolas36pt, 350, 250); FontManager.Add(Font.Name.Attract_Instruction_1P, pTexts_SpriteBatch, "PRESS 1 FOR 1-PLAYER MODE", Glyph.Name.Consolas36pt, 200, 150); FontManager.Add(Font.Name.Attract_Instruction_2P, pTexts_SpriteBatch, "PRESS 2 FOR 2-PLAYER MODE", Glyph.Name.Consolas36pt, 200, 115); }
public virtual void VisitFlyingSaucer(FlyingSaucer fs) { // no differed to subcass Debug.WriteLine("Visit by FlyingSaucer not implemented"); Debug.Assert(false); }