Ejemplo n.º 1
0
        private void ProjectileCollision()
        {
            GameObject TiledObject;
            int        directionY;


            this.x = _position.x + _velocity.x;

            TiledObject = Level.Return().CheckCollision(this);

            if (TiledObject != null)
            {
                _velocity.x *= -1;
                _velocity.x *= _bouncinessX;
            }

            x = _position.x - _velocity.x;

            //Y-Collision


            this.y      = _position.y + _velocity.y;
            TiledObject = Level.Return().CheckCollision(this);

            if (TiledObject != null)
            {
                directionY = _velocity.y > 0 ? 1 : -1;

                if (directionY == 1)
                {
                    _velocity.y *= -1;
                    _velocity.y *= _bouncinessY;
                }

                if (directionY == -1)
                {
                    _velocity.y = 0;
                }
            }

            y = _position.y - _velocity.y;

            _position.Add(_velocity);
        }
Ejemplo n.º 2
0
        //
        // Below here everything is about collision detection.
        //

        public void Step()
        {
            int        direction;
            GameObject TiledObject;

            //X-COLLISION
            _player.position.x += _player._velocity.x;
            this.x              = _player.position.x;

            TiledObject = Level.Return().CheckCollision(this);

            if (TiledObject != null)
            {
                direction = _player._velocity.x > 0 ? -1 : 1;

                if (direction == -1)
                {
                    _player._position.x = TiledObject.x - width / 2;
                    _player._velocity.x = 0.0000000000001f;                     //PRO-CODE ONLY PLZ DON'T COPY THIS. ITS MINE AND MINE ONLY.
                    _hitRight           = true;
                }

                if (direction == 1)
                {
                    _player._position.x = TiledObject.x + 64 + width / 2;
                    _player._velocity.x = 0;
                }
            }
            else
            {
                _hitRight = false;
            }

            x = _player._position.x - _player.velocity.x;


            //Y-COLLISION
            _player._velocity.Add(_player._gravity);
            _player.position.y += _player._velocity.y;
            this.y              = _player.position.y;

            TiledObject = Level.Return().CheckCollision(this);

            if (TiledObject != null)
            {
                direction = _player._velocity.y < 0 ? -1 : 1;

                if (direction == 1)
                {
                    _player.position.y  = TiledObject.y;
                    _player._landed     = true;
                    _player._landedBird = true;
                }

                if (direction == -1)
                {
                    _player.position.y = TiledObject.y + height + 64;
                }

                _player._velocity.y = 0;
                _player._gravity.y  = 0;
            }
            else
            {
                _player._landedBird = false;
            }
            y = _player.position.y - _player.velocity.y;
        }