void Player::checkCollision(int x, int y) {
//    printf("%d HAS THE BALL\n", hasTheBall);
//    printf("%d HAD THE BALL\n", hadTheBallBeforeJump);
//    printf("%d has COLLIDED\n", ball->hasCollidedWithThePole());

    if(isChangingPerspective && pPos.y <= 403 && !isJumping && !isDefending) {
        pPos.y = 403;
    }
    else if(isChangingPerspective && pPos.y >= 478 && !isJumping && !isDefending) {
        pPos.y = 478;
    }
    else if(isChangingPerspective && pPos.y <= 423 && !isJumping && isDefending) {
        pPos.y = 423;
    }
    else if(isChangingPerspective && pPos.y >= 498 && !isJumping && isDefending) {
        pPos.y = 498;
    }

    if(pPos.x < -(getTexture().getWidth() - getTextureRealWidth())/2) {
        pPos.x = -(getTexture().getWidth() - getTextureRealWidth())/2;
    }
    else if(x != 0 && y == 0) {
        if(pPos.x + getTextureRealWidth()*2 >= x && x > 0) {
            pPos.x = x - getTextureRealWidth()*2;
            pVelX = 0;
        }
        else if(x < 0 && pPos.x + getTextureRealWidth() <= -x) {
            x = -x;
            pPos.x = x - getTextureRealWidth();
            pVelX = 0;
        }
    }
    else if(y != 0 && x == 0) {
        if(pPos.y <= y) {
            pPos.y = y + 1;
            pVelY = 0;
            pVelX = 0;
        }
    }
    else if(y != 0 && x != 0) {
        if(pPos.x + getTextureRealWidth()*2 > x && x > 0) {
            pPos.x = x - getTextureRealWidth()*2;
            pVelX = 0;
        }
        else if(x < 0) {
            x = -x;
            if(pPos.x + getTextureRealWidth() <= x) {
                pPos.x = x - getTextureRealWidth();
                pVelX = 0;
            }
        }
        if(pPos.y <= y) {
            pPos.y = y + 1;
            pVelY = 0;
            pVelX = 0;
        }
    }
}
Example #2
0
	void* Canvas::pointPixel( int _x, int _y )
	{
		MYGUI_ASSERT( _x >= 0 && _x < getTextureRealWidth() && _y >= 0 && _y < getTextureRealHeight(),
			"Access to non-exists pixel! Check real dimensions of texture!" );

		MYGUI_ASSERT( isLocked(), "Must lock MyGUI::Canvas before point pixel!" );

		size_t _pixelDataSize = Ogre::PixelUtil::getNumElemBytes( mTexPtr->getFormat() );

		MYGUI_ASSERT( _pixelDataSize, "Unknown texture format!" );

		return mTexData + ( _y * getTextureRealWidth() + _x ) * _pixelDataSize;
	}
	void BerkeliumWidget::update()
	{
		void* data = lock();

		mBuffer.draw(data, getTextureRealWidth());

		unlock();
	}
void Player::checkBasketballPoleCollision(BasketballPole* pole) {
    if(!isChangingPerspective) {
        if(getX() + getTextureRealWidth() - 10 > pole->getRim().x + pole->getRim().w - 20) {
            behindRim = true;
        }
        else {
            behindRim = false;
        }
        if(getX() + getTextureRealWidth()*2 - 10 >= pole->getRim().x && getX() + getTextureRealWidth() - 10 <= pole->getRim().x + pole->getRim().w - 20) {
           belowRim = true;
        }
        else {
            belowRim = false;
        }
        if(getY() <= pole->getRim().y && !behindRim && !belowRim) {
            checkCollision(pole->getRim().x);
        }
        else if(behindRim) {
            if(pPos.x + getTextureRealWidth() - 30 <= pole->getRim().x + pole->getRim().w - 20 && pPos.y <= pole->getRim().y + pole->getRim().h + 30) {
                checkCollision(-pole->getBoard().x, pole->getBelowBoard().y);
            }
            else {
                checkCollision(pole->getBelowBoard().x - 70, pole->getBelowBoard().y);
            }

        }
        else if(belowRim) {
            if(getY() <= pole->getRim().y + pole->getRim().h + 30 && getX() + getTextureRealWidth()*2 - 10 <= pole->getBoard().x) {
                checkCollision(pole->getBoard().x, pole->getRim().y + pole->getRim().h);
            }
            else if(getY() <= pole->getBoard().y + pole->getBoard().h + 30 && getX() + getTextureRealWidth()*2 >= pole->getRim().x + pole->getRim().w - 20 && getX() + getTextureRealWidth() - 10 <= pole->getRim().x + pole->getRim().w - 20 && getX() + getTextureRealWidth()*2 - 10 >= pole->getBoard().x) {
                checkCollision(0, pole->getBoard().y + pole->getBoard().h + 30);
            }
            else {
                checkCollision(0, pole->getRim().y + pole->getRim().h);
            }
        }
        else {
            checkCollision();
        }
    }
    else {
        checkCollision(1180, 0);
    }
}
Example #5
0
	void Canvas::setPixel( int _x, int _y, const Ogre::ColourValue & value )
	{
		MYGUI_ASSERT( _x >= 0 && _x < getTextureRealWidth() && _y >= 0 && _y < getTextureRealHeight(),
			"Access to non-exists pixel! Check real dimensions of texture!" );

		MYGUI_ASSERT( isLocked(), "Must lock MyGUI::Canvas before set pixel!" );

		Ogre::PixelUtil::packColour( value, getTextureFormat(), pointPixel( _x, _y ) );
	}
void Player::checkBallCollision() {
    if(pPos.x + getTextureRealWidth()*2 >= ball->getX()
       && pPos.x + getTextureRealWidth() <= ball->getX() + ball->getTexture().getWidth()
       && pPos.y <= ball->getY() && pPos.y + getTextureRealHeight() >= ball->getY() + ball->getTexture().getHeight()
       && !hasTheBall && !isChangingPerspective && !ball->isPossessed() && !ball->hasBeenStolen()) {
        if(isJumping && ball->getY() >= pPos.y && ball->getY() + ball->getTexture().getHeight() <= pPos.y + getTextureRealHeight() && ball->hasCollidedWithThePole()) {
            hasTheBall = true;
            ball->setPossession(true);
            hasThrownTheBall = false;
            ball->setIsThrown(false);
            ball->setVelocity(0, 0);
            ball->resetDimensions();
            //ball->setPosition(pPos.x + getTextureRealWidth()*2 - 30, pPos.y - 5);
        }
        else if(isJumping && facing == LEFT) {
            ball->checkCollision(pPos.x + textureRealWidth,0);
        }
        else if(!isJumping) {
            hasTheBall = true;
            hasThrownTheBall = false;
            ball->setPossession(true);
            ball->setIsThrown(false);
            ball->setVelocity(0, 0);
            if(isDefending) {
                isDefending = false;
            }
            ball->resetDimensions();
            //ball->setPosition(pPos.x + getTextureRealWidth()*2 - 30, pPos.y - 5);

        }
        ball->setHasScored(false);
        hasScored = false;
        if(hasStolenTheBall) {
            hasStolenTheBall = false;
        }
        ball->setIsStolen(false);
    }
    else if (hasTheBall && !ball->isThrown()) {
        ball->setPosition(pPos.x + getTextureRealWidth()*2 - 30, pPos.y - 5);
    }
}
Example #7
0
	Ogre::ColourValue Canvas::getPixel( int _x, int _y )
	{
		MYGUI_ASSERT( _x >= 0 && _x < getTextureRealWidth() && _y >= 0 && _y < getTextureRealHeight(),
			"Access to non-exists pixel! Check real dimensions of texture!" );

		MYGUI_ASSERT( isLocked(), "Must lock MyGUI::Canvas before set pixel!" );

		Ogre::ColourValue result;

		Ogre::PixelUtil::unpackColour( & result, getTextureFormat(), pointPixel( _x, _y ) );

		return result;
	}
Example #8
0
	void Canvas::correctUV()
	{
		if( mTexResizeMode == TRM_PT_VIEW_REQUESTED )
		{
			_setUVSet( FloatRect( 0, 0,
				(Ogre::Real) mReqTexSize.width  / (Ogre::Real) getTextureRealWidth(),
				(Ogre::Real) mReqTexSize.height / (Ogre::Real) getTextureRealHeight()
				) );
		}

		if( mTexResizeMode == TRM_PT_CONST_SIZE || mTexResizeMode == TRM_PT_VIEW_ALL )
		{
			_setUVSet( FloatRect( 0, 0, 1, 1 ) );
		}
	}
Example #9
0
 IntSize Canvas::getTextureRealSize() const
 {
     return IntSize( getTextureRealWidth(), getTextureRealHeight() );
 }
void WhitePlayer::handleEvents(SDL_Event* e) {
    if(e->type == SDL_KEYDOWN) {
        switch(e->key.keysym.sym) {
            case SDLK_RIGHT:
                if(facing == LEFT && hasLanded) {
                    frame = 0;
                    currFrameTime = 0;
                    movingRight = true;
                }
                isStanding = false;
                isRunning = true;
//                if(stancePositioned) {
//                    stancePositioned = false;
//                    pPos.y += 10;
//                }
                break;

            case SDLK_LEFT:
                if(facing == RIGHT && hasLanded) {
                    frame = 0;
                    currFrameTime = 0;
                    movingLeft = true;
                }
                isStanding = false;
                isRunning = true;
//                if(stancePositioned) {
//                    stancePositioned = false;
//                    pPos.y += 10;
//                }
                break;

            case SDLK_KP_0:
                if(!isDefending && !isJumping && !hasTheBall) {
                    frame = 0;
                    currFrameTime = 0;
                    isDefending = true;
                    if(pMovementSpeed != 3) {
                        pMovementSpeed = 3;
                    }
//                    if(stancePositioned) {
//                        stancePositioned = false;
//                        pPos.y += 10;
//                    }
                }
                break;
            case SDLK_RSHIFT:
                if(!isJumping) {
//                    if(stancePositioned) {
//                        stancePositioned = false;
//                        pPos.y += 10;
//                    }
                    if(hasTheBall) {
                        pShotPosition = pPos.x + getTextureRealWidth()*2;
                        ball->setVelocity(0, 0);
                        hadTheBallBeforeJump = true;
                    }
                    else {
                        hadTheBallBeforeJump = false;
                    }
                    frame = 0;
                    currFrameTime = 0;
                    pInitialY = pPos.y;
                    isJumping = true;
                    if(!isChangingPerspective) {
                        pVelY = pJumpPower;
                    }
                    else {
                        pVelY = 8*pJumpPower/9;
                    }
                    pMovementSpeed = 3;
                    hasLanded = false;
                    isDefending = false;
                    isRunning = false;
                    isStanding = false;
                }
                break;

            case SDLK_UP:
                if(!isJumping) {
//                    if(stancePositioned) {
//                        stancePositioned = false;
//                        pPos.y += 10;
//                    }
                    isChangingPerspective = true;
                    ball->changingPerspective(true);
                    isGoingAway = true;
                }
                break;

            case SDLK_DOWN:
//                if(stancePositioned) {
//                    stancePositioned = false;
//                    pPos.y += 10;
//                }
                if(!isJumping) {
                    if(pPos.y < 478) {
                        isChangingPerspective = true;
                        if(hasTheBall) {
                            ball->changingPerspective(true);
                        }
                        isComingCloser = true;
                    }
                }
                break;

            case SDLK_RCTRL:
                if(isDefending) {
                    isStealing = true;
                }
                break;
        }
    }
    else if(e->type == SDL_KEYUP && (e->key.keysym.sym == SDLK_LEFT || e->key.keysym.sym == SDLK_RIGHT) && hasLanded) {
        pVelX = 0.0;
        frame = 0;
        currFrameTime = 0;
        if(!hasTheBall) {
            pTexture = pNormalStance;
        }
        isRunning = false;
        isStanding = true;
        if(positioned) {
            pPos.y -= 20;
            positioned = false;
        }
        if(e->key.keysym.sym == SDLK_LEFT) {
            movingLeft = false;
        }
        else {
            movingRight = false;
        }
    }
    else if(e->type == SDL_KEYUP && e->key.keysym.sym == SDLK_KP_0 && hasLanded && !hasTheBall) {
        isDefending = false;
        frame = 0;
        currFrameTime = 0;
        pMovementSpeed = 10;
        if(positioned) {
            pPos.y -= 20;
            positioned = false;
        }
        if(!isRunning) {
            pTexture = pNormalStance;
        }
    }
    else if(e->type == SDL_KEYUP && e->key.keysym.sym == SDLK_RETURN && isJumping && hasTheBall && facing == RIGHT) {
        hasThrownTheBall = true;
        hasTheBall = false;
        ball->setIsThrown(true);
        lastPlayerToShoot = pName;
    }
    else if(e->type == SDL_KEYUP && (e->key.keysym.sym == SDLK_UP || e->key.keysym.sym == SDLK_DOWN) && hasLanded) {
        pVelY = 0.0;
        frame = 0;
//        currFrameTime = 0;
        if((pPos.y == 478 && !isDefending)) {
            isChangingPerspective = false;
            if(hasTheBall) {
                ball->changingPerspective(false);
            }
        }
        else if(pPos.y == 498 && isDefending) {
            isChangingPerspective = false;
        }
        if(!hasTheBall) {
            pTexture = pNormalStance;
        }
        if(e->key.keysym.sym == SDLK_UP) {
            isGoingAway = false;
        }
        else {
            isComingCloser = false;
        }
        isRunning = false;
        isStanding = true;
    }
}