Example #1
0
 private bool type;  // collision type
 /// <summary>
 /// Constructor for the enemy and ship
 /// </summary>
 /// <param name="game">game</param>
 /// <param name="enemy">enemy</param>
 /// <param name="ship">ship</param>
 /// <param name="sound">sound</param>
 /// <param name="explosion">explosion</param>
 /// <param name="type">object is enemy or not</param>
 public CollisionManager(Game game,
                         Enemy enemy,
                         Ship ship,
                         Song backSound,
                         Song crashSound,
                         Crash explosion,
                         bool type) : base(game)
 {
     this.enemy      = enemy;
     this.ship       = ship;
     this.backSound  = backSound;
     this.crashSound = crashSound;
     this.explosion  = explosion;
     this.type       = type;
 }
Example #2
0
 /// <summary>
 /// Constructor for the gift and ship
 /// </summary>
 /// <param name="game">game</param>
 /// <param name="gift">gift</param>
 /// <param name="ship">ship</param>
 /// <param name="sound">sound</param>
 /// <param name="explosion">explosion</param>
 /// <param name="type">object is enemy or not</param>
 public CollisionManager(Game game,
                         Gift gift,
                         Ship ship,
                         Song backSound,
                         Song giftSound,
                         Crash explosion,
                         bool type) : base(game)
 {
     this.gift      = gift;
     this.ship      = ship;
     this.backSound = backSound;
     this.giftSound = giftSound;
     this.explosion = explosion;
     this.type      = type;
 }
Example #3
0
        /// <summary>
        /// Constructor of the ActionScene
        /// </summary>
        /// <param name="game">game</param>
        /// <param name="spriteBatch">spriteBatch</param>
        /// <param name="sound">sound</param>
        public ActionScene(Game game,
                           SpriteBatch spriteBatch) : base(game)
        {
            this.spriteBatch = spriteBatch;
            //this.sound = sound;

            energyCount        = Shared.ENERGY;
            Shared.isNextLevel = false;

            shipTex = game.Content.Load <Texture2D>("Images/ship");
            Texture2D giftTex  = game.Content.Load <Texture2D>("Images/gift");
            Texture2D enemyTex = game.Content.Load <Texture2D>("Images/enemy");
            Texture2D expTex   = game.Content.Load <Texture2D>("Images/explosion");
            Texture2D crashTex = game.Content.Load <Texture2D>("Images/boom");
            Texture2D bgTex    = game.Content.Load <Texture2D>("images/Back");

            bgmSound        = game.Content.Load <Song>("Sounds/game");
            crashSound      = game.Content.Load <Song>("Sounds/boom");
            takeEnergySound = game.Content.Load <Song>("Sounds/item");
            levelUp         = game.Content.Load <Song>("Sounds/levelup");
            gameOver        = game.Content.Load <Song>("Sounds/gameOver");
            gameFailSound   = game.Content.Load <Song>("Sounds/intro");

            ship = new Ship(game, spriteBatch, shipTex, ENERGY_SCORE, isCrash, isTakeEnergy);
            MediaPlayer.Play(bgmSound);
            // Set game level
            Shared.GameLevelInitialize();

            #region Game Object Generation
            int maxSpawnX = 800;
            int maxSpawnY = 600;

            Random r = new Random(120);
            //ramdomly enemy generate
            for (int i = 0; i < Shared.ENEMY; i++)
            {
                int speedX = r.Next(1, Shared.MAX_SPEED);
                int speedY = r.Next(1, Shared.MAX_SPEED);
                int signX  = r.Next(0, 2);
                int signY  = r.Next(0, 2);

                if (signX == 1)
                {
                    speedX = -speedX;
                }
                if (signY == 1)
                {
                    speedY = -speedY;
                }

                int xp = r.Next(0, maxSpawnX);
                int yp = r.Next(0, maxSpawnY);

                enemySpeed = new Vector2((float)speedX, (float)speedY);
                enemyPos   = new Vector2(xp, yp);
                enemy      = new Enemy(game, spriteBatch, enemyTex, enemyPos, enemySpeed);
                this.Components.Add(enemy);

                crash = new Crash(game, spriteBatch, expTex, Vector2.Zero);
                this.Components.Add(crash);

                CollisionManager cm = new CollisionManager(game, enemy, ship,
                                                           bgmSound, crashSound, crash, ENEMY_COLLISION);
                this.Components.Add(cm);
            }

            //ramdomly gift generate
            for (int i = 0; i < Shared.ENERGY; i++)
            {
                int speedX = r.Next(1, Shared.MAX_SPEED);
                int speedY = r.Next(1, Shared.MAX_SPEED);
                int signX  = r.Next(0, 2);
                int signY  = r.Next(0, 2);

                if (signX == 1)
                {
                    speedX = -speedX;
                }
                if (signY == 1)
                {
                    speedY = -speedY;
                }

                int xp = r.Next(0, maxSpawnX);
                int yp = r.Next(0, maxSpawnY);

                giftSpeed = new Vector2((float)speedX, (float)speedY);
                giftPos   = new Vector2(xp, yp);
                gift      = new Gift(game, spriteBatch, giftTex, giftPos, giftSpeed, Shared.stage);
                this.Components.Add(gift);

                crash = new Crash(game, spriteBatch, crashTex, giftPos);
                this.Components.Add(crash);

                CollisionManager cm = new CollisionManager(game, gift, ship, bgmSound,
                                                           takeEnergySound, crash, !ENEMY_COLLISION);
                this.Components.Add(cm);
            }

            #endregion

            #region Game Message Initialization
            SpriteFont infoFont    = game.Content.Load <SpriteFont>("fonts/infoFont");
            SpriteFont messageFont = game.Content.Load <SpriteFont>("fonts/MessageFont");

            //timer
            timerPos = new Vector2((Shared.stage.X - infoFont.MeasureString("Time remain: 30.0").X) / 2, 10);
            timer    = new GamePlayTime(game, spriteBatch, infoFont, GAME_DURATION, timerPos);
            this.Components.Add(timer);

            // level message
            levelMessage          = new GameMessage(game, spriteBatch, infoFont, Color.Yellow);
            levelMessage.Message  = string.Format("Level {0}", Shared.currentLevel);
            levelMessage.Position = new Vector2(Shared.stage.X - infoFont.MeasureString(levelMessage.Message).X - 40, 30);
            this.Components.Add(levelMessage);

            // score message
            scoreMessage          = new GameMessage(game, spriteBatch, infoFont, Color.Yellow);
            scoreMessage.Message  = string.Format("Energy Score: {0:D3}", 0);
            scoreMessage.Position = new Vector2(50 + infoFont.LineSpacing, 25);
            this.Components.Add(scoreMessage);

            // high score message
            highScoreMessage         = new GameMessage(game, spriteBatch, infoFont, Color.Yellow);
            highScoreMessage.Message = string.Format("High Score: {0:D3}", 0);
            //highScoreMessage.Position = new Vector2(50 + infoFont.LineSpacing, 15);
            highScoreMessage.Position = new Vector2(Shared.stage.X - infoFont.MeasureString(highScoreMessage.Message).X - 40, 10);
            this.Components.Add(highScoreMessage);

            // level complete message
            levelCompleteMessage         = new GameMessage(game, spriteBatch, messageFont, Color.LightGoldenrodYellow);
            levelCompleteMessage.Message = "LEVEL COMPLETE\nSPACE TO NEXT LEVEL";
            messageSize = messageFont.MeasureString(levelCompleteMessage.Message);
            levelCompleteMessage.Position = new Vector2((Shared.stage.X - messageSize.X) / 2, (Shared.stage.Y - messageSize.Y) / 2);
            this.Components.Add(levelCompleteMessage);
            levelCompleteMessage.Enabled = false;
            levelCompleteMessage.Visible = false;

            // game complete message
            gameCompleteMessage         = new GameMessage(game, spriteBatch, messageFont, Color.LightGoldenrodYellow);
            gameCompleteMessage.Message = "CONGRATURATION!!\n\nGAME COMPLETE\nSPACE TO RECORD SCORE, ESC TO MENU";
            messageSize = messageFont.MeasureString(gameCompleteMessage.Message);
            gameCompleteMessage.Position = new Vector2((Shared.stage.X - messageSize.X) / 2, (Shared.stage.Y - messageSize.Y) / 2);
            this.Components.Add(gameCompleteMessage);
            gameCompleteMessage.Enabled = false;
            gameCompleteMessage.Visible = false;

            // game over message
            gameOverMessage          = new GameMessage(game, spriteBatch, messageFont, Color.OrangeRed);
            gameOverMessage.Message  = "GAME OVER\nSPACE TO RE-PLAY, ESC TO MENU";
            messageSize              = messageFont.MeasureString(gameOverMessage.Message);
            gameOverMessage.Position = new Vector2((Shared.stage.X - messageSize.X) / 2, (Shared.stage.Y - messageSize.Y) / 2);
            this.Components.Add(gameOverMessage);
            gameOverMessage.Enabled = false;
            gameOverMessage.Visible = false;

            #endregion
        }