示例#1
0
        public void Initialize()
        {
            _player = new Player();
            _player.Initialize();
            _player.setPosition(new Vector2(100, 200));
            _levelBuilder.buildLevel();

            LoadContent();
            //_elapsedTimeStart = 0;
            //Console.WriteLine("In Level Three");
            //_musicInstance.Play();
        }
        public void Update(GameTime gametime, Player p)
        {
            for (int i = 0; i < _tileRows; i++)
            {
                for (int j = 0; j < _tileColumns; j++)
                {

                    //Top Collision (This was a pain...)
                    if ((p._playerDefaultRectangle.Intersects(_topTileBounds[i, j]) && p._isColliding == false))
                    {
                        p._playerDefaultPosition = new Vector2(p._playerDefaultPosition.X, _tileRectangles[i, j].Y - p._playerDefaultRectangle.Height);
                        p._canJump = true;
                        p.jumpHack(_topTileBounds[i, j].Y - p._playerDefaultRectangle.Height);
                        p._isColliding = true;
                        p._acceleration.Y = 0;
                        p._velocity.Y = 0;
                    }
                    if (p._playerDefaultPosition.Y > _tempY + 0.89)
                    {
                        //Console.WriteLine("Position: " + p._playerDefaultPosition);

                        p._isColliding = false;
                    }
                    else if ((Keyboard.GetState().IsKeyDown(Keys.Z)) || (p._gamePadState.IsButtonDown(Buttons.A)))
                    {
                        p._isColliding = false;
                    }

                    _tempY = p._playerDefaultPosition.Y;

                    //Bottom Collision
                    if (p._playerDefaultRectangle.Intersects(_bottomTileBounds[i, j]))
                    {
                        p._playerDefaultPosition = new Vector2(p._playerDefaultPosition.X, _topTileBounds[i, j].Y + _topTileBounds[i, j].Height+41);
                        p._acceleration.Y = 0;
                        p._velocity.Y = 0;
                    }

                    //Left Collision
                    if (p._playerDefaultRectangle.Intersects(_leftTileBounds[i, j]) && (!p._playerDefaultRectangle.Intersects(_topTileBounds[i, j])) && (!p._playerDefaultRectangle.Intersects(_bottomTileBounds[i, j])))
                    {
                        p._playerDefaultPosition = new Vector2(_leftTileBounds[i, j].X-p._playerDefaultRectangle.Width-1, p._playerDefaultPosition.Y);
                        p._acceleration.X = 0;
                        p._velocity.X = 0;
                    }
                    //Right Collision
                    if (p._playerDefaultRectangle.Intersects(_rightTileBounds[i, j]) && (!p._playerDefaultRectangle.Intersects(_topTileBounds[i, j])) && (!p._playerDefaultRectangle.Intersects(_bottomTileBounds[i, j])))
                    {
                        p._playerDefaultPosition = new Vector2(_rightTileBounds[i, j].X+5, p._playerDefaultPosition.Y);
                        p._acceleration.X = 0;
                        p._velocity.X = 0;
                    }

                    //Spikes
                    if (p._playerDefaultRectangle.Intersects(_spikeTops[i, j]))
                    {
                        if (!p._isDead)
                            _deathSFX.Play();

                        p._isDead = true;
                    }

                    //Springs
                    if (p._playerDefaultRectangle.Intersects(_springTops[i, j]))
                    {
                        p.manualJump();
                        _springSFX.Play();
                    }

                    //Finish
                    if (p._playerDefaultRectangle.Intersects(_finishRec[i, j]))
                    {
                        _finishSFX.Play();
                        setFinished();
                    }

                }
            }
        }