Exemplo n.º 1
0
        //-----------------------------------------------------------

        //-----------------------------------------------------------
        //  Reset Game
        //  Resets the game to a blank state
        private void ResetGame()
        {
            _player            = null;
            _introductionActor = null;
            _actors            = null;
            _score             = 0;
            _level             = 1;
            _progressBar.UpdatePercentage(0, 100);
            _introductionTrigger = IntroductionTriggers.None;
            _introductionTimer   = 0.0f;
            _introductionIndex   = 0;
            _colorSwitchCount    = 0;

            _scoreLabel.UpdateText($"Score: {_score:D6}");
            _levelLabel.UpdateText($"Level: {_level}");
        }
Exemplo n.º 2
0
        //------------------------------------------------------------
        //  MessageBox_OnClick
        //  Called when the message box detects an on click event

        private void MessageBox_OnClick(MessageBox sender)
        {
            //  Increment index
            _introductionIndex++;

            //  Check if index exists
            if (_introductionIndex < _introductionLines.Count)
            {
                _messageBox.ChangeText(_introductionLines[_introductionIndex]);
            }


            //  Check for trigger switch

            switch (_introductionIndex)
            {
            case 3:
                _helperLabel.UpdateText("Click player circle and move mouse around");
                _introductionTrigger = IntroductionTriggers.ClickPlayer;
                break;

            case 4:
                _helperLabel.UpdateText("Consume to other circle by running into it");
                _introductionActor   = SpawnIntroductionEnemey();
                _introductionTrigger = IntroductionTriggers.ConsumeFood;
                break;

            case 8:
                _helperLabel.UpdateText("Use left and right click to change colors");
                _colorSwitchCount    = 0;
                _introductionTrigger = IntroductionTriggers.ColorSwitch;
                break;

            case 11:
                CreateWithoutIntroduction();
                break;

            default:
                _helperLabel.UpdateText("");
                break;
            }
        }
Exemplo n.º 3
0
        //-----------------------------------------------------------


        //-----------------------------------------------------------
        //  CreateIntroduction
        //  Creates the introduction sequence

        public void CreateIntroduction()
        {
            //  Create the player
            ResetGame();
            _player            = new Actor(0.2f, new Vector2(CacheManager.WorldSize.Width / 2.0f, CacheManager.WorldSize.Height / 2.0f));
            _player.IsPlayer   = true;
            _player.IsPositive = true;

            _actors = new List <Actor>();



            _introductionTrigger       = IntroductionTriggers.None;
            _introductionIndex         = -1;
            _introductionPlayerClicked = false;
            _introductionTimer         = 0.0f;

            _introductionLines = new List <string>();
            /*0*/
            _introductionLines.Add("This is you. This tiny, unimportant, small droplet in an world of other tiny, unimportant small droplets.");
            /*1*/
            _introductionLines.Add("No need to feel sad about that. Everyone starts out this way.");

            /*2: Trigger clicking the player*/
            _introductionLines.Add("For now let’s get you moving.  No need to sit an sulk about your existence.  Do me a favor and click yourself with the mouse, then move the mouse around the screen a bit.");

            /*3: Trigger consumeing*/
            _introductionLines.Add("Now that you're up and moving around, how about eating some food.  Look, I see something coming now that you can eat. Why don't you move over to it and try consuming it.");

            /*4*/
            _introductionLines.Add("Did you notice that?  The progress for your level increased.  You can see this at the bottom of the screen. The bar indicates how much further to go till the next level.");

            /*5*/
            _introductionLines.Add("The higher your level gets, however, the more life throws at you.  Life is always trying to bring you down.");

            /*6*/
            _introductionLines.Add("You can only consume those smaller, weaker, than you.  Don't let your ego get to big though, there will always be others bigger and better than you trying to take you down.");


            /*7: Trigger color switching */
            _introductionLines.Add("Did that hurt your feelings?  Well, how about this. Try left and right clicking with your mouse (not at the same time though).");


            /*8*/
            _introductionLines.Add("Don't you just feel special now? You have the ability to adapt to your surroundings.");

            /*9*/
            _introductionLines.Add("If you consume someone that is the same color as you, it will increase your size. However, consuming one of the opposite color will cause you to shrink.");

            /*10*/
            _introductionLines.Add("That's it. That's life. You have to make a way for yourself.  Stand on the shoulders of those smaller and weaker in order to challenge those bigger and better.  Good luck.");


            Size <int> boxSize     = new Size <int>((int)(CacheManager.VirtualSize.Width / 1.25f), (int)(CacheManager.VirtualSize.Height / 2.5f));
            Vector2    boxPosition = new Vector2
            {
                X = (CacheManager.VirtualSize.Width / 2.0f) - (boxSize.Width / 2.0f),
                Y = CacheManager.VirtualSize.Height - _progressBar.Size.Height - (boxSize.Height)
            };

            _messageBox = new MessageBox(
                id: "_messageBox",
                position: boxPosition,
                size: boxSize,
                texture: CacheManager.LoadTexture("ui/messagebox"),
                text: _introductionLines[0],
                padding: 5.0f,
                font: CacheManager.LoadFont("fonts/sneakattack-16"),
                container: null);


            _messageBox.OnClick += MessageBox_OnClick;

            _gameState = GameState.Introduction;
        }
Exemplo n.º 4
0
        //-----------------------------------------------------------

        //-----------------------------------------------------------
        //  CheckForCollisions
        //  Checks for colliions between the player and the actors

        private void CheckForCollisions(GameTime gameTime)
        {
            for (int i = 0; i < _actors.Count(); i++)
            {
                //  Check player collision first as priority
                if (_player.Intersects(_actors[i]))
                {
                    //  Check if player or actor is bigger
                    if (_player.circle.Radius >= _actors[i].circle.Radius)
                    {
                        //  Absorb
                        _actors[i].ShouldRespawn = true;
                        //  Check polarity
                        if (_player.IsPositive == _actors[i].IsPositive)
                        {
                            //  Play sound effect
                            if (GameSettingsRepository.GameSettings.SoundOn)
                            {
                                CacheManager.IncreaseFX.Play(GameSettingsRepository.GameSettings.SoundVolume, 0.0f, 0.0f);
                            }

                            //  Increase player size
                            _player.circle.Radius  += _actors[i].circle.Radius / 64.0f;
                            _player.AmountConsumed += _actors[i].circle.Radius;
                            _player.Velocity       -= 0.01f;

                            //  Increase Score
                            _score += (int)Math.Ceiling(_actors[i].circle.Radius);

                            //  Increase progress
                            _progressBar.UpdatePercentage(_player.AmountConsumed, _player.NextLevel);
                        }
                        else
                        {
                            //  Play sound effect
                            if (GameSettingsRepository.GameSettings.SoundOn)
                            {
                                CacheManager.DecreaseFx.Play(GameSettingsRepository.GameSettings.SoundVolume, 0.0f, 0.0f);
                            }

                            //  Decrease progress
                            _player.circle.Radius  -= _actors[i].circle.Radius / 64.0f;
                            _player.AmountConsumed += _actors[i].circle.Radius;
                            _player.Velocity       += 0.01f;
                            _score -= (int)Math.Ceiling(_actors[i].circle.Radius);

                            //  Increase progress
                            _progressBar.UpdatePercentage(_player.AmountConsumed, _player.NextLevel);
                        }
                    }
                    else
                    {
                        _gameState = GameState.GameOver;
                    }
                }

                //  Check actor to actor collisions
                for (int j = 0; j < _actors.Count(); j++)
                {
                    if (_actors[i].Intersects(_actors[j]))
                    {
                        if (_actors[i].circle.Radius > _actors[j].circle.Radius)
                        {
                            //  This means actor[i] eats actor[j]
                            _actors[j].ShouldRespawn = true;
                        }
                    }
                }
            }



            if (_introductionTrigger == IntroductionTriggers.ConsumeFood)
            {
                if (_player.Intersects(_introductionActor))
                {
                    //  Play sound effect
                    if (GameSettingsRepository.GameSettings.SoundOn)
                    {
                        CacheManager.IncreaseFX.Play(GameSettingsRepository.GameSettings.SoundVolume, 0.0f, 0.0f);
                    }


                    //  Increase player size
                    _player.circle.Radius  += _introductionActor.circle.Radius / 64.0f;
                    _player.AmountConsumed += _introductionActor.circle.Radius;
                    _player.Velocity       -= 0.01f;

                    //  Increase Score
                    _score += (int)Math.Ceiling(_introductionActor.circle.Radius);

                    //  Increase progress
                    _progressBar.UpdatePercentage(_player.AmountConsumed, _player.NextLevel);

                    _helperLabel.UpdateText("");
                    _introductionTrigger = IntroductionTriggers.None;
                }
            }

            _score = MathHelper.Clamp(_score, 0, int.MaxValue);
            _scoreLabel.UpdateText($"Score: {_score:D6}");
        }
Exemplo n.º 5
0
        //-----------------------------------------------------------

        //-----------------------------------------------------------
        //  Update
        //  Updates the screen
        public override void Update(GameTime gameTime)
        {
            KeyboardState keyboardState = Keyboard.GetState();
            MouseState    mouseState    = Mouse.GetState();

            base.Update(gameTime);

            if (_gameState == GameState.Playing)
            {
                if (keyboardState.IsKeyDown(Keys.Escape) && _prevKeyboardState.IsKeyUp(Keys.Escape))
                {
                    //  Pause the game
                    _gameState = GameState.Paused;
                }
                else
                {
                    _player.Update(gameTime);

                    UpdateActors(gameTime);

                    CheckForCollisions(gameTime);
                }
            }
            else if (_gameState == GameState.Paused)
            {
                if (keyboardState.IsKeyDown(Keys.Escape) && _prevKeyboardState.IsKeyUp(Keys.Escape))
                {
                    //  Unpause Game
                    _gameState = GameState.Playing;
                }
                else
                {
                    _pauseMenu.Update(gameTime);
                }
            }
            else if (_gameState == GameState.GameOver)
            {
                _gameOverMenu.Update(gameTime);
            }
            else if (_gameState == GameState.Waiting)
            {
                CheckForMouseClick(mouseState);
            }
            else if (_gameState == GameState.Introduction)
            {
                switch (_introductionTrigger)
                {
                case IntroductionTriggers.ClickPlayer:
                    if (_introductionPlayerClicked)
                    {
                        _introductionTimer += (float)gameTime.ElapsedGameTime.TotalSeconds;
                        _helperLabel.UpdateText($"Click player circle and move mouse around ({(5.0f - _introductionTimer):00.0})");
                        if (_introductionTimer >= 5.0f)
                        {
                            _introductionTrigger = IntroductionTriggers.None;
                        }
                        _player.Update(gameTime);
                    }
                    else
                    {
                        CheckForMouseClick(mouseState);
                    }
                    break;

                case IntroductionTriggers.ConsumeFood:
                    _player.Update(gameTime);
                    CheckForCollisions(gameTime);
                    _introductionActor.Update(gameTime);
                    break;

                case IntroductionTriggers.ColorSwitch:
                    if (_colorSwitchCount >= 2)
                    {
                        _introductionTrigger = IntroductionTriggers.None;
                    }
                    if (_player.DidScolorSwitch)
                    {
                        _colorSwitchCount++;
                    }
                    _player.Update(gameTime);
                    break;

                case IntroductionTriggers.Start:
                    _gameState = GameState.Waiting;
                    break;

                default:
                    _helperLabel.UpdateText("");
                    _messageBox.Update(gameTime);
                    break;
                }
            }


            _prevKeyboardState = keyboardState;
            _prevMouseState    = mouseState;
        }