Beispiel #1
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();
            }
        }