Beispiel #1
0
 public override bool CheckCollision(BoundingRectangle other)
 {
     if (_bounds.CollidesWith(other))
     {
         return(true);
     }
     return(false);
 }
 public override bool CheckCollision(BoundingRectangle other)
 {
     if (_bounds.CollidesWith(other))
     {
         this.BuyItem();
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #3
0
        /// <summary>
        /// Updates game
        /// </summary>
        /// <param name="gameTime"></param>
        public void Update(GameTime gameTime)
        {
            CurrentTime += (float)gameTime.ElapsedGameTime.TotalSeconds;
            if (CurrentBackground == 1)
            {
                Rain.Update(gameTime);
            }
            Land.Update(gameTime);
            if (Player.UpdateNow)
            {
                Player.UpdateNow = false;

                gameMap.Blocks = new List <Block>();
                ChangeBackground();
                gameMap.PopulateTileMap();
                Player.ForceMove(gameMap.RhoStartingPosition);
            }
            // TODO: Add your update logic here
            move.X = 0;
            inputManager.Update(gameTime);
            gameMap.Update(gameTime);
            if (Player.Teleporting)
            {
                move.Y = 0.00001f;
            }
            else
            {
                move.X = inputManager.Direction.X * MOVESPEED;

                if (inputManager.TryJump && move.Y == 0)
                {
                    move.Y = -JUMPHEIGHT;
                }
                else
                {
                    move.Y = MathHelper.Min(move.Y + GRAVITY, TERMINALVELOCITY);
                }

                projectedLocation.X = MathHelper.Clamp((Player.Position.X + move.X), 0, Screen.SIZE * Screen.GS);
                projectedLocation.Y = Player.Position.Y + move.Y;
                if (move.X == 0)
                {
                    projectedLocation.X     += 2.5f;
                    projectedLocation.Width  = 24 * Rho.SIZESCALE;
                    projectedLocationX.Width = 24 * Rho.SIZESCALE;
                    projectedLocationX.Width = 24 * Rho.SIZESCALE;
                }
                else
                {
                    projectedLocation.Width  = 29 * Rho.SIZESCALE;
                    projectedLocationX.Width = 29 * Rho.SIZESCALE;
                    projectedLocationY.Width = 29 * Rho.SIZESCALE;
                }
                projectedLocationX.X = projectedLocation.X;
                projectedLocationX.Y = Player.Position.Y;
                projectedLocationY.X = Player.Position.X;
                projectedLocationY.Y = projectedLocation.Y;
                for (int i = 0; i < gameMap.Blocks.Count; i++)
                {
                    if (projectedLocation.CollidesWith(gameMap.Blocks[i].Bounds))
                    {
                        if (projectedLocationY.CollidesWith(gameMap.Blocks[i].Bounds))
                        {
                            if (Player.Bounds.Top > gameMap.Blocks[i].Bounds.Bottom)
                            {
                                move.Y = 0.1f;
                                Player.ForceMove(Player.Position.X, gameMap.Blocks[i].Bounds.Bottom + 0.1f);
                            }
                            else if (Player.Bounds.Bottom < gameMap.Blocks[i].Bounds.Top)
                            {
                                move.Y = 0;
                                if (saveFallSpeed != 0)
                                {
                                    Land.SpawnParticles(100 * (Player.Position.Y - apex) / Screen.SIZE);
                                }
                                Player.ForceMove(Player.Position.X, gameMap.Blocks[i].Bounds.Top - Player.Bounds.Height - 0.1f);
                            }
                        }
                        if (projectedLocationX.CollidesWith(gameMap.Blocks[i].Bounds))
                        {
                            move.X = 0;
                            if (Player.Bounds.Left > gameMap.Blocks[i].Bounds.Right)
                            {
                                Player.ForceMove(gameMap.Blocks[i].Bounds.Right + 0.1f, Player.Position.Y);
                            }
                            else if (Player.Bounds.Right < gameMap.Blocks[i].Bounds.Left)
                            {
                                Player.ForceMove(gameMap.Blocks[i].Bounds.Left - Player.Bounds.Width - 0.1f, Player.Position.Y);
                            }
                        }
                    }
                }
            }
            if (saveFallSpeed <= 0 && move.Y > 0 || move.Y == 0)
            {
                apex = Player.Position.Y;
            }
            saveFallSpeed = move.Y;
            Player.Update(gameTime, move);
            for (int i = 0; i < gameMap.Coins.Count; i++)
            {
                if (!gameMap.Coins[i].IsCollected && Player.Bounds.CollidesWith(gameMap.Coins[i].Bounds))
                {
                    gameMap.Coins[i].IsCollected = true;
                    CoinsCollected++;
                    coinPickup.Play(volume: 0.25f, pitch: -0.4f, pan: 0.0f);
                }
            }

            if (inputManager.MouseClicked())
            {
                Player.TryTeleport(inputManager.MouseCoordinates, gameMap.TileMap);
            }
            if (CoinsCollected >= gameMap.CoinCount && gameMap.CoinCount >= 1)
            {
                CoinsCollected = 0;
                RoomsCleared++;
                NewRoom();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Updates the game.  Called every frame of the game loop.
        /// </summary>
        /// <param name="gameTime">The time in the game</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // TODO: Add your update logic here
            MouseState currentMouse  = Mouse.GetState();
            Vector2    mousePosition = new Vector2(currentMouse.X, currentMouse.Y);

            Velocity = mousePosition - Position;
            Position = mousePosition;

            if (_enemyPosition1.Y < 500 && _enemyPosition1.Y > 100 && _enemy1Land)
            {
                _enemyPosition1.Y = 0;
                _enemy1Bounds.Y   = 0;
                _enemy1Land       = false;
            }
            else if (_enemyPosition1.Y >= 480)
            {
                _enemy1Land = true;
            }
            else
            {
                _enemyPosition1.Y += 8;
                _enemy1Bounds.Y    = _enemyPosition1.Y + 8;
            }


            if (_enemyPosition2.Y < 500 && _enemyPosition2.Y > 100 && _enemy2Land)
            {
                _enemyPosition2.Y = 0;
                _enemy2Bounds.Y   = 0;
                _enemy2Land       = false;
            }
            else if (_enemyPosition2.Y >= 480)
            {
                _enemy2Land = true;
            }
            else
            {
                _enemyPosition2.Y += 4;
                _enemy2Bounds.Y    = _enemyPosition2.Y + 8;
            }

            if (_enemyPosition3.Y < 500 && _enemyPosition3.Y > 100 && _enemy3Land)
            {
                _enemyPosition3.Y = 0;

                _enemy3Bounds.Y = 0;
                _enemy3Land     = false;
            }
            else if (_enemyPosition3.Y >= 480)
            {
                _enemy3Land = true;
            }
            else
            {
                _enemyPosition3.Y += 2;
                _enemy3Bounds.Y    = _enemyPosition3.Y + 8;
            }

            if (_enemyPosition4.Y < 500 && _enemyPosition4.Y > 100 && _enemy4Land)
            {
                _enemyPosition4.Y = 0;
                _enemy4Bounds.Y   = 0;
                _enemy4Land       = false;
            }
            else if (_enemyPosition4.Y >= 480)
            {
                _enemy4Land = true;
            }
            else
            {
                _enemyPosition4.Y += 6;
                _enemy4Bounds.Y    = _enemyPosition4.Y + 8;
            }


            var keyboardState = Keyboard.GetState();

            // The game pauses either if the user presses the pause button, or if
            // they unplug the active gamepad. This requires us to keep track of
            // whether a gamepad was ever plugged in, because we don't want to pause
            // on PC if they are playing with a keyboard and have no gamepad at all!

            if (_gameState == 1)
            {
                // Otherwise move the player position.
                var movement = Vector2.Zero;

                if (keyboardState.IsKeyDown(Keys.Left))
                {
                    if (animationTimer > .3)
                    {
                        animationFrame++;
                        if (animationFrame > 7)
                        {
                            animationFrame = 0;
                        }
                        animationTimer -= .3;
                    }
                    movement.X--;

                    flipped = true;
                }

                if (keyboardState.IsKeyDown(Keys.Right))
                {
                    if (animationTimer > .3)
                    {
                        animationFrame++;
                        if (animationFrame > 7)
                        {
                            animationFrame = 0;
                        }
                        animationTimer -= .3;
                    }

                    movement.X++;

                    flipped = false;
                }

                /*if (keyboardState.IsKeyDown(Keys.Up))
                 * {
                 *  if (animationTimer > .3)
                 *  {
                 *      animationFrame++;
                 *      if (animationFrame > 7) animationFrame = 0;
                 *      animationTimer -= .3;
                 *  }
                 *  movement.Y--;
                 * }*/

                if (keyboardState.IsKeyDown(Keys.Down))
                {
                    if (animationTimer > .3)
                    {
                        animationFrame++;
                        if (animationFrame > 7)
                        {
                            animationFrame = 0;
                        }
                        animationTimer -= .3;
                    }
                    movement.Y++;
                }
                float   t            = (float)gameTime.ElapsedGameTime.TotalSeconds;
                Vector2 acceleration = new Vector2(0, 2);

                /*if (keyboardState.IsKeyDown(Keys.Space))
                 * {
                 *  acceleration = new Vector2(0, -7);
                 *  //jump.Play(.25f,0,0);
                 * }*/
                _playerPosition += acceleration;
                if (_playerPosition.Y < 50)
                {
                    _playerPosition.Y = 50;
                }
                if (_playerPosition.Y > GraphicsDevice.Viewport.Height)
                {
                    _playerPosition.Y = GraphicsDevice.Viewport.Height;
                }
                if (_playerPosition.X < 64)
                {
                    _playerPosition.X = 64;
                }
                if (_playerPosition.X > 3810)
                {
                    _playerPosition.X = 3810;
                }
                _playerbounds.X = _playerPosition.X;
                _playerbounds.Y = _playerPosition.Y - 64;

                if (_playerPosition.X > 3000 && _playerPosition.X < 3200)
                {
                    _fireworks.PlaceFirework(new Vector2(600, GraphicsDevice.Viewport.Height - 64));
                }
                if (_playerPosition.X > 3200 && _playerPosition.X < 3400)
                {
                    _fireworks.PlaceFirework(new Vector2(700, GraphicsDevice.Viewport.Height - 64));
                }
                if (_playerPosition.X > 3400)
                {
                    _fireworks.PlaceFirework(new Vector2(800, GraphicsDevice.Viewport.Height - 64));
                }
                if (_playerbounds.CollidesWith(_bedBounds))
                {
                    MediaPlayer.Stop();
                    _hitBed.Play();
                    _gameState = 0;
                    if (Keyboard.GetState().IsKeyDown(Keys.Enter))
                    {
                        Exit();
                    }
                    //ExitScreen();
                }
                if (_playerbounds.CollidesWith(_enemy2Bounds) || _playerbounds.CollidesWith(_enemy1Bounds) || _playerbounds.CollidesWith(_enemy3Bounds) || _playerbounds.CollidesWith(_enemy4Bounds))
                {
                    _hitBurger.Play();


                    var waitTime  = new TimeSpan(0, 0, 5);
                    var waitUntil = DateTime.Now + waitTime;
                    _explosions.PlaceExplosion(new Vector2(400, _playerPosition.Y - 40));
                    _playerPosition.X = _playerPosition.X - 50;
                }


                if (movement.Length() > 1)
                {
                    movement.Normalize();
                }

                _playerPosition += movement * 4f;
            }
            if (!_isPlaying)
            {
                MediaPlayer.Play(_backgroundMusic);
                MediaPlayer.IsRepeating = true;
                _isPlaying = true;
            }
            base.Update(gameTime);
        }
Beispiel #5
0
 /// <summary>
 /// Detects if BoundingCircle is colliding with BoundingRectangle
 /// </summary>
 /// <param name="other"></param>
 /// <returns></returns>
 public bool CollidesWith(BoundingRectangle other)
 {
     return(other.CollidesWith(this));
 }
Beispiel #6
0
 public override bool CheckCollision(BoundingRectangle other)
 {
     return(_bounds.CollidesWith(other));
 }