/// <summary>
        /// It draws a <see cref="Sprite"/> in a given position
        /// </summary>
        /// <param name="spriteBatch"></param>
        /// <param name="sprite"></param>
        /// <param name="spatialObject"></param>
        /// <param name="isDebugModeEnabled">It draws a visible boxing rectangle</param>
        public static void Draw(
            this SpriteBatch spriteBatch,
            Sprite sprite,
            DrawingInfos spatialObject,
            bool isDebugModeEnabled = false)
        {
            spriteBatch.Draw(
                sprite.Sheet,
                spatialObject.Position,
                sprite.SourceRectangle,
                spatialObject.OverlayColor,
                spatialObject.Rotation,
                spatialObject.Origin,
                spatialObject.Scale,
                spatialObject.IsFlipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None,
                spatialObject.LayerDepth);

            if (isDebugModeEnabled)
            {
                DrawRectangle(
                    spriteBatch,
                    spatialObject.HitBox(sprite.Width, sprite.Height),
                    _hitBoxColor);
            }
        }
Ejemplo n.º 2
0
        public ScorePage(
            AssetsLoader assets,
            ISettingsRepository settingsRepository,
            IScreenTransformationMatrixProvider matrixScaleProvider,
            ILocalizedStringsRepository localizedStringsRepository)
        {
            _font                = assets.Font;
            _background          = assets.OtherSprites["scoreBackground"];
            _matrixScaleProvider = matrixScaleProvider;

            _titleText          = localizedStringsRepository.Get(GameStringsLoader.ScorePageTitleString);
            _titleScalingObject = new ScalingObject(1f, 1.2f, 1.0f);
            _titleDrawingInfos  = new DrawingInfos()
            {
                Position = new Vector2(matrixScaleProvider.VirtualWidth / 2f, 100f),
                Origin   = _font.GetTextCenter(_titleText)
            };

            float textsScale = 0.4f;

            var bestFarts           = settingsRepository.GetOrSetInt(GameScores.BestFartsScoreKey, default);
            var bestNumberOfMeters  = settingsRepository.GetOrSetInt(GameScores.BestNumberOfMetersScoreKey, default);
            var bestVegetablesEaten = settingsRepository.GetOrSetInt(GameScores.BestVegetablesEatenScoreKey, default);

            _scoreInfos = new List <ScoreRecordText>()
            {
                new ScoreRecordText(
                    $"{localizedStringsRepository.Get(GameStringsLoader.BestNumberOfMetersScoreKey)}{bestNumberOfMeters}",
                    new DrawingInfos()
                {
                    Position     = new Vector2(_titleDrawingInfos.Position.X / 2, _titleDrawingInfos.Position.Y + 100f),
                    OverlayColor = Color.White.WithAlpha(0),
                    Scale        = textsScale
                }),

                new ScoreRecordText(
                    $"{localizedStringsRepository.Get(GameStringsLoader.BestVegetablesEatenScoreKey)}{bestVegetablesEaten}",
                    new DrawingInfos()
                {
                    Position     = new Vector2(_titleDrawingInfos.Position.X / 2, _titleDrawingInfos.Position.Y + 140f),
                    OverlayColor = Color.White.WithAlpha(0),
                    Scale        = textsScale
                }),

                new ScoreRecordText(
                    $"{localizedStringsRepository.Get(GameStringsLoader.BestFartsScoreKey)}{bestFarts}",
                    new DrawingInfos()
                {
                    Position     = new Vector2(_titleDrawingInfos.Position.X / 2, _titleDrawingInfos.Position.Y + 180f),
                    OverlayColor = Color.White.WithAlpha(0),
                    Scale        = textsScale
                }),
            };

            _nTexts        = _scoreInfos.Count;
            _currentTextId = 0;
            _fadeObject    = new FadeObject(TimeSpan.FromMilliseconds(500), Color.White);
            _fadeObject.FadeInCompleted += _textFadeObject_FadeInCompleted;
            _fadeObject.FadeIn();
        }
Ejemplo n.º 3
0
 public FloatingTextButton(
     string text,
     DrawingInfos drawingInfos,
     SpriteFont font,
     Action onClick,
     float minScale = 1.0f,
     float maxScale = 1.2f)
     : base(text, drawingInfos, font, minScale, maxScale)
 {
     _action   = onClick;
     _textSize = font.MeasureString(text);
 }
Ejemplo n.º 4
0
 public FloatingText(
     string text,
     DrawingInfos drawingInfos,
     SpriteFont font,
     float minScale = 1.0f,
     float maxScale = 1.2f)
 {
     _text          = text;
     _drawingInfos  = drawingInfos;
     _scalingObject = new ScalingObject(minScale, maxScale, 1.0f);
     _font          = font;
 }
Ejemplo n.º 5
0
        private void UpdateScoreString()
        {
            _scoreText = $"{_scoreTextTitle}:{_score}";

            _scoreTextDrawingInfos = new DrawingInfos()
            {
                Position     = new Vector2(_matrixScaleProvider.VirtualWidth / 2f, _colorTextBackgroundRectangle.Y / 3),
                Origin       = _writingFont.GetTextCenter(_scoreText),
                Scale        = 0.8f,
                OverlayColor = _gameColors.ScoreColor
            };
        }
        /// <summary>
        /// Draws the current animation frame
        /// </summary>
        /// <param name="spriteBatch"></param>
        /// <param name="spatialInfos"></param>
        public void Draw(
            SpriteBatch spriteBatch,
            DrawingInfos spatialInfos)
        {
            if (CurrentAnimationName == null)
            {
                return;
            }

            spriteBatch.Draw(
                _animations[CurrentAnimationName].CurrentFrame,
                spatialInfos);
        }
 /// <summary>
 /// It draws a string in a given position
 /// </summary>
 /// <param name="spriteBatch"></param>
 /// <param name="font"></param>
 /// <param name="text"></param>
 /// <param name="spatialInfos"></param>
 public static void DrawString(
     this SpriteBatch spriteBatch,
     SpriteFont font,
     string text,
     DrawingInfos spatialInfos)
 {
     spriteBatch.DrawString(
         font,
         text,
         spatialInfos.Position,
         spatialInfos.OverlayColor,
         spatialInfos.Rotation,
         spatialInfos.Origin,
         spatialInfos.Scale,
         spatialInfos.IsFlipped ? SpriteEffects.FlipHorizontally : SpriteEffects.None,
         spatialInfos.LayerDepth);
 }
Ejemplo n.º 8
0
        public ScoreRecordText(
            string scoreText,
            DrawingInfos textDrawingInfos,
            string recordText = null)
        {
            ScoreText        = scoreText;
            TextDrawingInfos = textDrawingInfos;
            RecordText       = recordText;
            int positionToAdd = recordText == null ? 0 : 100;

            textDrawingInfos.Position = new Vector2(
                textDrawingInfos.Position.X + positionToAdd,
                textDrawingInfos.Position.Y);
            RecordTextDrawingInfos = new DrawingInfos()
            {
                Position     = textDrawingInfos.Position - new Vector2(150f, 0f),
                Scale        = textDrawingInfos.Scale,
                OverlayColor = _recordColor
            };

            _recordScalingObject = new ScalingObject(textDrawingInfos.Scale - 0.01f, textDrawingInfos.Scale + 0.01f);
        }
Ejemplo n.º 9
0
        public GameButton(
            AssetsLoader assetsLoader,
            int squaredButtonSize,
            ColorWithName color)
        {
            _buttonBottom     = assetsLoader.Sprites["button-bottom"];
            _buttonUpPressed  = assetsLoader.Sprites["button-up-pressed"];
            _buttonUpReleased = assetsLoader.Sprites["button-up-released"];

            _squaredButtonSize = squaredButtonSize;

            _upPartDrawingInfos = new DrawingInfos()
            {
                OverlayColor = color.ColorGraphic
            };

            _bottomPartDrawingInfos = new DrawingInfos()
            {
                OverlayColor = Color.White
            };

            ColorWithName = color;
            _currentState = ButtonState.Up;
        }
Ejemplo n.º 10
0
        public OverlayPopup(
            string title,
            string text,
            SpriteFont font,
            IScreenTransformationMatrixProvider matrixScaleProvider,
            ILocalizedStringsRepository localizedStringsRepository,
            Action playAgainFunction,
            Action exitFunction)
        {
            _font = font;

            _backgroundRectangle = new Rectangle(0, 0, matrixScaleProvider.VirtualWidth, matrixScaleProvider.VirtualHeight);
            _backgroundColor     = Color.Gray.WithAlpha(0.7f);

            int popupRectangleWidth = 900;

            _popupRectangle = new Rectangle(
                (matrixScaleProvider.VirtualWidth - popupRectangleWidth) / 2, 260,
                popupRectangleWidth, popupRectangleWidth + 200);
            _popupBackgroundColor = Definitions.PrimaryBackgroundColor.WithAlpha(1f);

            _popupRectangleShadow = new Rectangle(
                _popupRectangle.X + 15,
                _popupRectangle.Y + 15,
                _popupRectangle.Width,
                _popupRectangle.Height);
            _popupShadowBackgroundColor = Color.Black.WithAlpha(1f);

            _titleDrawingInfos = new DrawingInfos()
            {
                Position = new Vector2(
                    matrixScaleProvider.VirtualWidth / 2,
                    _popupRectangle.Y + _popupRectangle.Height / 4),
                Origin       = _font.GetTextCenter(title),
                OverlayColor = Color.Black
            };

            _textDrawingInfos = new DrawingInfos()
            {
                Position     = _titleDrawingInfos.Position + new Vector2(0f, 200f),
                Origin       = _font.GetTextCenter(text),
                Scale        = 0.6f,
                OverlayColor = Color.White
            };

            TitleText = title;
            Text      = text;

            _playAgainButton = new FloatingTextButton(
                localizedStringsRepository.Get(GameStringsLoader.PlayAgainStringKey),
                new DrawingInfos()
            {
                Position     = _textDrawingInfos.Position + new Vector2(0f, 250f),
                Origin       = _font.GetTextCenter(localizedStringsRepository.Get(GameStringsLoader.PlayAgainStringKey)),
                OverlayColor = Definitions.PrimaryForegroundColor,
            },
                _font,
                playAgainFunction,
                0.7f, 0.8f);

            _exitButton = new FloatingTextButton(
                localizedStringsRepository.Get(GameStringsLoader.ExitStringKey),
                new DrawingInfos()
            {
                Position     = _textDrawingInfos.Position + new Vector2(0f, 450f),
                Origin       = _font.GetTextCenter(localizedStringsRepository.Get(GameStringsLoader.ExitStringKey)),
                OverlayColor = Definitions.PrimaryForegroundColor
            },
                _font,
                exitFunction,
                0.7f, 0.8f);
        }
Ejemplo n.º 11
0
        public MainMenuPage(
            AssetsLoader assetsLoader,
            GameOrchestrator gameOrchestrator,
            IScreenTransformationMatrixProvider matrixScaleProvider,
            ILocalizedStringsRepository localizedStringsRepository,
            RateMeDialog rateMeDialog,
            ISettingsRepository settingsRepository)
        {
            _backgroundRectangle = new Rectangle(0, 0, matrixScaleProvider.VirtualWidth, matrixScaleProvider.VirtualHeight);

            var titleFont = assetsLoader.TitleFont;

            _writingFont  = assetsLoader.WritingFont;
            _rateMeDialog = rateMeDialog ?? throw new ArgumentNullException(nameof(rateMeDialog));

            const string titleText = "RELLOW";

            _title = new FloatingText(
                titleText,
                new DrawingInfos()
            {
                Position     = new Vector2(matrixScaleProvider.VirtualWidth / 2f, 250f),
                Origin       = titleFont.GetTextCenter(titleText),
                OverlayColor = _foregroundColor
            },
                titleFont);

            var playText = localizedStringsRepository.Get(GameStringsLoader.PlayStringKey);

            _playButton = new FloatingTextButton(
                playText,
                new DrawingInfos()
            {
                Position     = new Vector2(matrixScaleProvider.VirtualWidth / 2f, 850f),
                Origin       = _writingFont.GetTextCenter(playText),
                OverlayColor = _foregroundColor
            },
                _writingFont,
                () =>
            {
                gameOrchestrator.SetGameState();
            });

            var aboutText = localizedStringsRepository.Get(GameStringsLoader.AboutStringKey);

            _aboutButton = new FloatingTextButton(
                aboutText,
                new DrawingInfos()
            {
                Position     = new Vector2(matrixScaleProvider.VirtualWidth / 2f, 1150f),
                Origin       = _writingFont.GetTextCenter(aboutText),
                OverlayColor = _foregroundColor
            },
                _writingFont,
                () =>
            {
                gameOrchestrator.SetAboutState();
            });

            var currentScore = settingsRepository.GetOrSetInt(Definitions.SCORE_KEY, 0);

            _scoreText         = $"{localizedStringsRepository.Get(GameStringsLoader.ScoreStringKey)}:{currentScore}";
            _scoreDrawingInfos = new DrawingInfos()
            {
                Position     = new Vector2(matrixScaleProvider.VirtualWidth / 2f, matrixScaleProvider.VirtualHeight - 250f - 200f),
                Origin       = _writingFont.GetTextCenter(_scoreText),
                OverlayColor = _scoreColor,
                Scale        = 0.5f
            };
        }
Ejemplo n.º 12
0
        public GameOverPage(
            IScreenTransformationMatrixProvider matrixScaleProvider,
            AssetsLoader assets,
            ISettingsRepository settingsRepository,
            int thisGameNumberOfVegetablesEaten,
            int thisGameNumberOfMeters,
            int thisGameNumberOfFarts,
            ILocalizedStringsRepository localizedStringsRepository)
        {
            _font                = assets.Font;
            _background          = assets.OtherSprites["gameoverBackground"];
            _matrixScaleProvider = matrixScaleProvider;

            _gameOverTextDrawingInfos = new DrawingInfos()
            {
                Position = new Vector2()
                {
                    X = matrixScaleProvider.VirtualWidth / 2f, Y = 100f
                },
                Origin = _font.GetTextCenter(_gameOverText)
            };
            _gameOverScalingObject = new ScalingObject(1f, 1.2f, 1.0f);

            var bestFarts           = settingsRepository.GetOrSetInt(GameScores.BestFartsScoreKey, default(int));
            var bestNumberOfMeters  = settingsRepository.GetOrSetInt(GameScores.BestNumberOfMetersScoreKey, default(int));
            var bestVegetablesEaten = settingsRepository.GetOrSetInt(GameScores.BestVegetablesEatenScoreKey, default(int));

            var bestNumberOfVegetablesEatenRecord = false;

            if (thisGameNumberOfVegetablesEaten > bestVegetablesEaten)
            {
                settingsRepository.SetInt(GameScores.BestVegetablesEatenScoreKey, thisGameNumberOfVegetablesEaten);
                bestNumberOfVegetablesEatenRecord = true;
            }

            var bestAliveTimeRecord = false;

            if (thisGameNumberOfMeters > bestNumberOfMeters)
            {
                settingsRepository.SetInt(GameScores.BestNumberOfMetersScoreKey, thisGameNumberOfMeters);
                bestAliveTimeRecord = true;
            }

            var bestNumberOfFartsRecord = false;

            if (thisGameNumberOfFarts > bestFarts)
            {
                settingsRepository.SetInt(GameScores.BestFartsScoreKey, thisGameNumberOfFarts);
                bestNumberOfFartsRecord = true;
            }

            const float textsScale = 0.4f;

            _scoreInfos = new List <ScoreRecordText>()
            {
                new ScoreRecordText(
                    $"{localizedStringsRepository.Get(GameStringsLoader.NumberOfMetersString)}{thisGameNumberOfMeters}",
                    new DrawingInfos()
                {
                    Position     = new Vector2(_gameOverTextDrawingInfos.Position.X / 2, _gameOverTextDrawingInfos.Position.Y + 200f),
                    OverlayColor = Color.White.WithAlpha(0),
                    Scale        = textsScale
                },
                    !bestAliveTimeRecord ? "       " : "Record!"),

                new ScoreRecordText(
                    $"{localizedStringsRepository.Get(GameStringsLoader.NumbersOfFartsString)}{thisGameNumberOfFarts}",
                    new DrawingInfos()
                {
                    Position     = new Vector2(_gameOverTextDrawingInfos.Position.X / 2, _gameOverTextDrawingInfos.Position.Y + 125f),
                    OverlayColor = Color.White.WithAlpha(0),
                    Scale        = textsScale
                },
                    !bestNumberOfFartsRecord ? "       " : "Record!"),

                new ScoreRecordText(
                    $"{localizedStringsRepository.Get(GameStringsLoader.NumberOfVegetablesEaten)}{thisGameNumberOfVegetablesEaten}",
                    new DrawingInfos()
                {
                    Position     = new Vector2(_gameOverTextDrawingInfos.Position.X / 2, _gameOverTextDrawingInfos.Position.Y + 162f),
                    OverlayColor = Color.White.WithAlpha(0),
                    Scale        = textsScale
                },
                    !bestNumberOfVegetablesEatenRecord ? "       " : "Record!"),
            };

            _nTexts        = _scoreInfos.Count;
            _currentTextId = 0;
            _fadeObject    = new FadeObject(TimeSpan.FromMilliseconds(200), Color.White);
            _fadeObject.FadeInCompleted += _textFadeObject_FadeInCompleted;
            _fadeObject.FadeIn();
        }
Ejemplo n.º 13
0
        public MainMenuPage(
            AssetsLoader assets,
            RateMeDialog rateMeDialog,
            SoundManager soundManager,
            IScreenTransformationMatrixProvider matrixScaleProvider,
            ILocalizedStringsRepository localizedStringsRepository)
        {
            _font = assets.Font;
            _matrixScaleProvider = matrixScaleProvider;
            _rateMeDialog        = rateMeDialog ?? throw new ArgumentNullException(nameof(rateMeDialog));
            _soundManager        = soundManager ?? throw new ArgumentNullException(nameof(soundManager));

            _background      = assets.OtherSprites["menuBackground"];
            _playText        = localizedStringsRepository.Get(GameStringsLoader.PlayButtonString);
            _scoreText       = localizedStringsRepository.Get(GameStringsLoader.ScoreButtonString);
            _fartText        = localizedStringsRepository.Get(GameStringsLoader.FartButtonString);
            _titleImage      = assets.OtherSprites["gameTitle"];
            _achievementText = "about";

            _titleScalingObject = new ScalingObject(1f, 1.2f, 1.0f);
            _titleDrawingInfos  = new DrawingInfos()
            {
                Position = new Vector2(matrixScaleProvider.VirtualWidth / 2f, 100f),
                Origin   = _titleImage.SpriteCenter
            };

            _playScalingObject = new ScalingObject(0.5f, 0.7f, 1f);
            _playDrawingInfos  = new DrawingInfos()
            {
                Position = new Vector2(140f, 250f),
                Origin   = _font.GetTextCenter(_playText)
            };
            _playTextSize = _font.MeasureString(_playText);

            _fartScalingObject = new ScalingObject(0.5f, 0.7f, 1f);
            _fartDrawingInfos  = new DrawingInfos()
            {
                Position     = new Vector2(140f, 320f),
                Origin       = _font.GetTextCenter(_fartText),
                OverlayColor = new Color(155, 88, 48)
            };
            _fartTextSize = _font.MeasureString(_fartText);

            _scoreTextSize      = _font.MeasureString(_scoreText);
            _scoreScalingObject = new ScalingObject(0.5f, 0.7f, 1f);
            _scoreDrawingInfos  = new DrawingInfos()
            {
                Position = new Vector2(matrixScaleProvider.VirtualWidth - 150f, 250f),
                Origin   = _font.GetTextCenter(_scoreText)
            };

            _aboutTextSize      = _font.MeasureString(_achievementText);
            _aboutScalingObject = new ScalingObject(0.5f, 0.7f, 1f);
            _aboutDrawingInfos  = new DrawingInfos()
            {
                Position = new Vector2(matrixScaleProvider.VirtualWidth - 150f, 320f),
                Origin   = _font.GetTextCenter(_achievementText)
            };

            _soundManager.PlayMenuBackground();
        }
Ejemplo n.º 14
0
        private void NewRound()
        {
            if (IsTimeToShuffleColors())
            {
                _gameColors.ShuffleUIColors();
            }

            if (_numberOfVictories > 0)
            {
                var differential = (_numberOfVictories * 10) + (int)((_choiceTime - _currentWordTimer).TotalMilliseconds / 10);
                _score += differential;

                var popupText              = $"+{differential}";
                var startingPopupPosition  = _scoreTextDrawingInfos.Position + new Vector2(0f, 230f);
                var scoreDifferentialPopup = new PopupText()
                {
                    Text         = popupText,
                    DrawingInfos = new DrawingInfos()
                    {
                        Position = startingPopupPosition,
                        Scale    = 1.0f,
                        Origin   = _writingFont.GetTextCenter(popupText),
                    },
                    PopupObject = new PopupObject(
                        _popupScoreDuration,
                        startingPopupPosition,
                        _gameColors.ScoreColor,
                        110)
                };
                scoreDifferentialPopup.PopupObject.Popup();

                _scoreDifferentialPopups.Add(scoreDifferentialPopup);
            }

            ++_numberOfVictories;

            _currentWordTimer = _choiceTime;
            _gameButtonsManager.NewRound();

            _currentWordDrawingInfos = new DrawingInfos()
            {
                Position = new Vector2(
                    _matrixScaleProvider.VirtualWidth / 2f,
                    14f + _colorTextBackgroundRectangle.Y + _colorTextBackgroundRectangle.Height / 2f),
                Origin       = _writingFont.GetTextCenter(_gameButtonsManager.CurrentWord),
                OverlayColor = _gameButtonsManager.CurrentWordForegroundColor
            };

            if (_gameButtonsManager.CanAddButtons &&
                IsTimeToIncreaseDifficulty())
            {
                _choiceTime -= TimeSpan.FromMilliseconds(200);
                _gameButtonsManager.AddButton();
            }

            _timeProgressBar.MaxValue = (int)_choiceTime.TotalMilliseconds;
            _timeProgressBar.Color    = _gameColors.TimerBarColor;

            UpdateScoreString();
            _timeProgressBar.Reset();
            UpdateTimerProgressBar();
            _currentGameState = GameStates.PlayingWaitingForInput;
        }