コード例 #1
0
        public void DrawMainMenu()
        {
            // Set "cursor" position on menu.
            Vector2 coinPos = Vector2.Zero;

            switch (gameController.CurrentMenu.SelectedOption)
            {
            case 0:
                coinPos = new Vector2(9, 7);
                break;

            case 1:
                coinPos = new Vector2(9, 20);
                break;

            case 2:
                coinPos = new Vector2(9, 35);
                break;
            }

            batch.Begin(samplerState: samplerState, transformMatrix: baseScaleMatrix);
            {
                batch.Draw(titleGraphic, Vector2.Zero, Color.White);
                batch.Draw(titleCursor, coinPos, Color.White);

                var totalScoreLength = 11 + ScoreRenderer.LengthOf(gameController.bestCoinScore / 100d);
                var diff             = bestScoreBackgroundOffset.X - totalScoreLength;

                // Draw "best score" section.
                if (gameController.bestCoinScore > 0)
                {
                    batch.Draw(bestScoreBackground, bestScoreBackgroundOffset.ToVector2() - new Vector2(totalScoreLength, 0), Color.White);
                    DrawScore(batch, bestScoreBackgroundOffset.ToVector2() + new Vector2(11, 2) - new Vector2(totalScoreLength, 0), gameController.bestCoinScore / 100d);
                }

                #region Main menu icons
                if (SoundController.Muted())
                {
                    batch.Draw(mutedIcon, mutedIconOffset.ToVector2(), Color.White);
                }

                if (SoundController.MusicMuted())
                {
                    batch.Draw(mutedMusicIcon, mutedMusicIconOffset.ToVector2(), Color.White);
                }

                if (gameController.skipTutorial)
                {
                    batch.Draw(noTutorialIcon, noTutorialIconOffset.ToVector2(), Color.White);
                }
                #endregion

                // Draw the border graphic over the bestScoreBackground.
                batch.Draw(titleBorderGraphic, Vector2.Zero, Color.White);
            }
            batch.End();
        }
コード例 #2
0
        public void DrawGame()
        {
            var baseMatrixWithLaserShake = Matrix.CreateTranslation(
                new Vector3(gameController.laserPlayer.laserShake.CurrentShake, 0))
                                           * baseMatrix;

            var mousePos = InputController.CurrentMousePosition;

            graphicsDevice.Clear(Color.Black);

            for (int i = coinBackgroundLayers.Count - 1; i >= 0; i--)
            {
                var coinBackground = coinBackgroundLayers[i];

                var drawColour = new Color(
                    coinBackground.currentAlpha,
                    coinBackground.currentAlpha,
                    coinBackground.currentAlpha, 1f);

                // Create matrix for coin backgrounds.
                Matrix coinBackgroundMatrix =
                    Matrix.CreateTranslation(-ChangeGame.WINDOW_WIDTH / 2, -ChangeGame.PLAYABLE_AREA_HEIGHT, 0)
                    * baseMatrix
                    * Matrix.CreateScale(coinBackground.currentScale)
                    * Matrix.CreateTranslation(
                        ChangeGame.PLAYABLE_AREA_WIDTH * ChangeGame.SCALE / 2,
                        ChangeGame.PLAYABLE_AREA_HEIGHT * ChangeGame.SCALE - coinBackground.currentTranslate,
                        0);

                // Draw buffer coin background.
                batch.Begin(
                    sortMode: SpriteSortMode.BackToFront,
                    samplerState: samplerState,
                    transformMatrix: coinBackgroundMatrix);
                {
                    batch.Draw(coinBackground.graphic, new Vector2(0, 0), drawColour);
                    batch.Draw(VaultWalls, new Vector2(-vaultWallWidth, 0), drawColour);
                    batch.Draw(VaultWalls, new Vector2(ChangeGame.PLAYABLE_AREA_WIDTH, 0), drawColour);
                    batch.Draw(VaultFloor, new Vector2(-vaultWallWidth, -vaultFloorHeight), drawColour);
                    batch.Draw(VaultFloor, new Vector2(-vaultWallWidth, ChangeGame.PLAYABLE_AREA_HEIGHT), drawColour);
                }
                batch.End();
            }

            // Draw current coin background.
            batch.Begin(samplerState: samplerState, transformMatrix: baseMatrix);
            {
                batch.Draw(currentCoinBackground, new Vector2(0, 0), Color.White);
            }
            batch.End();

            // Draw falling coins.
            batch.Begin(samplerState: samplerState, transformMatrix: baseMatrix);
            {
                foreach (var coin in gameController.FallingCoins)
                {
                    batch.Draw(coinGraphic, coin.CollisionRect.Location.ToVector2(), Color.White);
                }
            }
            batch.End();

            // Draw paddle background.
            batch.Begin(samplerState: samplerState, transformMatrix: baseScaleMatrix);
            {
                batch.Draw(paddleBackground, new Vector2(0, ChangeGame.WINDOW_HEIGHT - ChangeGame.PADDLE_AREA_HEIGHT), Color.White);
            }
            batch.End();

            // Draw enemies.
            batch.Begin(samplerState: samplerState, transformMatrix: baseMatrix);
            {
                foreach (var c in gameController.corpses)
                {
                    var oldEnemySize = new Vector2(10, 10);
                    var enemyDiff    = new Vector2(piggyBankGraphic.Width, piggyBankGraphic.Height) - oldEnemySize;

                    bool isBackwardsVacuum = c.EnemyReference is VacuumEnemy && c.EnemyReference.Direction < 0;

                    var fireOffset = new Vector2(-1, -5);
                    if (isBackwardsVacuum)
                    {
                        fireOffset += new Vector2(5, 0);
                    }

                    var effect    = c.speed.X < 0 ? SpriteEffects.None : SpriteEffects.FlipHorizontally;
                    var effectInv = c.speed.X > 0 ? SpriteEffects.None : SpriteEffects.FlipHorizontally;

                    batch.Draw(enemyFireGraphics[c.animationFrame % enemyFireGraphics.Length],
                               (c.Position + fireOffset).ToPoint().ToVector2(),
                               null,
                               Color.White,
                               0, Vector2.Zero, 1, effect, 0);

                    DrawEnemy(batch, c.EnemyReference, c.Position.ToPoint().ToVector2());
                }
                for (int i = 0; i < gameController.enemies.Count; i++)
                {
                    DrawEnemy(batch, gameController.enemies[i], gameController.enemies[i].CollisionRect.Location.ToVector2());
                }
            }
            batch.End();

            // Draw back of paddle.
            if (gameController.CurrentStage.HasFlag(Stage.StageFlags.PaddlePlayerEnabled))
            {
                batch.Begin(samplerState: samplerState, transformMatrix: baseMatrix);
                {
                    batch.Draw(paddleGraphicBack, gameController.paddlePlayer.CollisionRect.Location.ToVector2(), Color.White);
                }
                batch.End();
            }

            // Draw money.
            batch.Begin(samplerState: samplerState, transformMatrix: baseMatrix);
            {
                foreach (var c in gameController.notesOnFire)
                {
                    var fireOffset = new Vector2(-1, -(NoteOnFire.HEIGHT - Note.HEIGHT));

                    var effect = c.IsFlipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None;

                    var noteFireGraphicsSet = noteFireGraphics[c.Type];
                    batch.Draw(noteFireGraphicsSet[c.animationFrame % noteFireGraphicsSet.Length],
                               (c.Position + fireOffset).ToPoint().ToVector2(),
                               null,
                               Color.White,
                               0, Vector2.Zero, 1, effect, 0);
                }
                foreach (var note in gameController.notes)
                {
                    if (!note.InsideVacuum)
                    {
                        batch.Draw(noteGraphics[note.Type], note.CollisionRect.Location.ToVector2(), Color.White);
                    }
                }
            }
            batch.End();

            // Draw front of paddle.
            if (gameController.CurrentStage.HasFlag(Stage.StageFlags.PaddlePlayerEnabled))
            {
                batch.Begin(samplerState: samplerState, transformMatrix: baseMatrix);
                {
                    batch.Draw(paddleGraphicFront, gameController.paddlePlayer.CollisionRect.Location.ToVector2(), Color.White);
                }
                batch.End();
            }

            var scoreLength    = ScoreRenderer.LengthOf(gameController.currentCoinScore / 100d);
            var totalArea      = ChangeGame.PLAYABLE_AREA_WIDTH - scoreLength;
            var totalAreaRatio = (ChangeGame.PLAYABLE_AREA_WIDTH - scoreLength) / (float)ChangeGame.PLAYABLE_AREA_WIDTH;

            #region Draw hud
            // Calculate values for drawing the hud.
            var laserPercentage = (int)(gameController.laserPlayer.laserCharge * totalArea) / (float)totalArea * totalAreaRatio;

            var healthPercentage = (gameController.CurrentStage.MaxNotesMissed - gameController.notesMissed) / (float)gameController.CurrentStage.MaxNotesMissed;
            healthPercentage = (int)(healthPercentage * totalArea) / (float)totalArea * totalAreaRatio;

            var totalDuration   = gameController.CurrentStage.RequiredTimePassed.TotalSeconds;
            var currentDuration = gameController.CurrentStage.timePassed.TotalSeconds;

            float progressPercentage;

            if (gameController.CurrentStage.HasFlag(Stage.StageFlags.CompleteOnTimePassed))
            {
                progressPercentage = (float)(currentDuration / totalDuration);
            }
            else if (gameController.CurrentStage.HasFlag(Stage.StageFlags.CompleteOnCollectCoins))
            {
                progressPercentage = gameController.CurrentStage.coinsCollected / (float)gameController.CurrentStage.RequiredCoins;
            }
            else
            {
                progressPercentage = 1f;
            }

            progressPercentage = (int)(progressPercentage * totalArea) / (float)totalArea * totalAreaRatio;

            // Draw the hud.
            batch.Begin(samplerState: samplerState, transformMatrix: baseScaleMatrix);
            {
                batch.Draw(hudBackground, Vector2.Zero, Color.White);

                batch.Draw(hudLaserCharge,
                           new Vector2(scoreLength, 3),
                           null,
                           Color.White,
                           0, Vector2.Zero,
                           new Vector2(laserPercentage, 1),
                           SpriteEffects.None, 0);

                batch.Draw(hudPlayerHealth,
                           new Vector2(scoreLength, 1),
                           null,
                           Color.White,
                           0, Vector2.Zero,
                           new Vector2(healthPercentage, 1),
                           SpriteEffects.None, 0);

                batch.Draw(hudTimeRemaining,
                           new Vector2(scoreLength, 0),
                           null,
                           Color.White,
                           0, Vector2.Zero,
                           new Vector2(progressPercentage, 1),
                           SpriteEffects.None, 0);

                batch.Draw(scoreBackground, Vector2.Zero, Color.White);
                DrawScore(batch, Vector2.Zero, gameController.currentCoinScore / 100d);
            }
            batch.End();
            #endregion

            // Draw laser player (over HUD).
            if (gameController.CurrentStage.HasFlag(Stage.StageFlags.LaserPlayerEnabled))
            {
                batch.Begin(samplerState: samplerState, transformMatrix: baseMatrixWithLaserShake);
                {
                    batch.Draw(playerGraphic, (gameController.laserPlayer.CollisionRect.Location + laserPlayerOffset).ToVector2(), Color.White);
                }
                batch.End();
            }

            // Draw lasers.
            if (gameController.laserPlayer.FiringLaser)
            {
                Color[] laserData = Enumerable.Repeat(Color.Transparent,
                                                      ChangeGame.PLAYABLE_AREA_WIDTH * ChangeGame.PLAYABLE_AREA_HEIGHT).ToArray();

                // Add both lasers to colour data.
                LineGraphic.CreateLineBoundsCheck(laserData,
                                                  gameController.laserPlayer.LeftEyePos.X, gameController.laserPlayer.LeftEyePos.Y,
                                                  mousePos.X, mousePos.Y, Color.Red);
                LineGraphic.CreateLineBoundsCheck(laserData,
                                                  gameController.laserPlayer.RightEyePos.X, gameController.laserPlayer.RightEyePos.Y,
                                                  mousePos.X, mousePos.Y, Color.Red);

                playerLasersLayer.SetData(laserData);

                batch.Begin(samplerState: samplerState, transformMatrix: baseMatrixWithLaserShake, blendState: BlendState.NonPremultiplied);
                {
                    var   laserAlpha     = Math.Min(gameController.laserPlayer.laserCharge * 8, 1f);
                    Color laserFadeColor = new Color(1f, 1f, 1f, laserAlpha);

                    batch.Draw(playerLasersLayer, Vector2.Zero, laserFadeColor);
                }
                batch.End();
            }

            // If there is a Stage Complete menu, draw it.
            if (gameController.CurrentMenu != null && gameController.CurrentMenu is StageCompleteMenu)
            {
                batch.Begin(samplerState: samplerState, transformMatrix: baseScaleMatrix);
                {
                    batch.Draw(stageOverBackground, gameController.CurrentMenu.MenuOffset.ToPoint().ToVector2() + stageCompleteOffset.ToVector2(), Color.White);
                }
                batch.End();
            }

            // Clean up temporary enemy Texture2Ds.
            foreach (var t in temporaryVacuumTextureStore)
            {
                t.Dispose();
            }
            temporaryVacuumTextureStore.Clear();
        }