예제 #1
0
void applyGravity(GPngGame *gPngGame, unsigned char gravityCounter) {
    unsigned char baseWeight, currentWeight;
    
    baseWeight = 16;

    //ball
    currentWeight = baseWeight << gPngGame->ball->weight;
    if(!(gravityCounter % currentWeight)) {
	setBallXVel(gPngGame->ball->xVel + gPngGame->xGravity, gPngGame->ball);
	setBallYVel(gPngGame->ball->yVel + gPngGame->yGravity, gPngGame->ball);
    }
    
    //paddle one
    currentWeight = baseWeight << gPngGame->paddleOne->weight;
    if(!(gravityCounter % currentWeight)) {
	setPaddleXVel(gPngGame->paddleOne->xVel + gPngGame->xGravity, gPngGame->paddleOne);
	setPaddleYVel(gPngGame->paddleOne->yVel + gPngGame->yGravity, gPngGame->paddleOne);
    }

    //paddle two
    currentWeight = baseWeight << gPngGame->paddleTwo->weight;
    if(!(gravityCounter % currentWeight)) {
	setPaddleXVel(gPngGame->paddleTwo->xVel + gPngGame->xGravity, gPngGame->paddleTwo);
	setPaddleYVel(gPngGame->paddleTwo->yVel + gPngGame->yGravity, gPngGame->paddleTwo);
    }
}
예제 #2
0
void updateBall(Ball *ball, GPINT friction)
{
#ifdef USE_FRICTION
    //apply friction
    setBallXVel(FPMUL(ball->xVel, friction), ball);
    setBallYVel(FPMUL(ball->yVel, friction), ball);
#else
    friction = friction;
#endif

    // update positions
    ball->x += ball->xVel;
    ball->y += ball->yVel;
}
예제 #3
0
void initGameObjects(StartState startState)
{
    initDefaultBall(&ball);
    initDefaultCourt(&court);
    initDefaultPaddleOne(&paddleOne);
    initDefaultPaddleTwo(&paddleTwo);

    gPngGame.isPlayerOneHuman = 0;
    gPngGame.isPlayerTwoHuman = 0;


    switch(startState) {
    case straightLeft:
	paddleTwo.x = FPMAKE(280,0);
	paddleTwo.y = FPMAKE(FPINT(gPngGame.court->y), 0);
	
	setBallXVel(-1*FPMAKE(0, 8), &ball);
	
	break;

    case straightLeftPaddleTopCollision:
	paddleTwo.x = FPMAKE(280,0);
	paddleTwo.y = FPMAKE(FPINT(gPngGame.court->y), 0);

	paddleOne.x = FPMAKE(35,0);
	paddleOne.y = FPMAKE(110,0);
	paddleOne.xVel = FPMAKE(0,0);
	paddleOne.yVel = FPMAKE(-1,0);
	ball.x = FPMAKE(45,0);
	ball.y = FPMAKE(100-DEFAULT_BALL_HEIGHT-8,0);
	ball.xVel = FPMAKE(-1,0);
	ball.yVel = FPMAKE(0,0);


	setBallXVel(-1*FPMAKE(0, 8), &ball);
	break;
    case straightLeftPaddleBottomCollision:
	paddleTwo.x = FPMAKE(280,0);
	paddleTwo.y = FPMAKE(FPINT(gPngGame.court->y), 0);

	paddleOne.x = FPMAKE(35,0);
	paddleOne.y = FPMAKE(90,0);
	paddleOne.xVel = FPMAKE(0,0);
	paddleOne.yVel = FPMAKE(1,0);
	ball.x = FPMAKE(45,0);
	ball.y = FPMAKE(100+DEFAULT_PADDLE_HEIGHT+8,0);
	ball.xVel = FPMAKE(-1,0);
	ball.yVel = FPMAKE(0,0);

	setBallXVel(-1*FPMAKE(0, 8), &ball);
	
	break;
    case straightLeftPaddleNonTopCollision:
	paddleOne.x = FPMAKE(24,0);
	paddleOne.y = FPMAKE(100,0);
	paddleOne.yVel = 0;
	paddleOne.xVel = MAX_PADDLE_SPEED_X;
	
	ball.x = FPMAKE(34+DEFAULT_PADDLE_WIDTH,0);
	ball.y = FPMAKE(100-DEFAULT_BALL_HEIGHT+1, 0);
	ball.xVel = MIN_BALL_SPEED_X;
	ball.yVel = 0;
	break;
    case straightRightNonTopCollision:
	paddleOne.x = FPMAKE(344-paddleTwo.width,0);
	paddleTwo.y = FPMAKE(100,0);
	paddleTwo.yVel = 0;
	paddleTwo.xVel = MIN_PADDLE_SPEED_X;
	
	ball.x = FPMAKE(334-ball.width,0);
	ball.y = FPMAKE(100-DEFAULT_BALL_HEIGHT+1, 0);
	ball.xVel = MAX_BALL_SPEED_X;
	ball.yVel = 0;
	break;
    case straightRightPaddleTopCollision:
	paddleTwo.x = FPMAKE(280,0);
	paddleTwo.y = FPMAKE(110, 0);
	paddleTwo.xVel = FPMAKE(0,0);
	paddleTwo.yVel = FPMAKE(-1,0);

	paddleOne.x = FPMAKE(35,0);
	paddleOne.y = FPMAKE(110,0);

	ball.x = FPMAKE(270,0);
	ball.y = FPMAKE(100-DEFAULT_BALL_HEIGHT-8,0);
	ball.xVel = FPMAKE(1,0);
	ball.yVel = FPMAKE(0,0);


	setBallXVel(FPMAKE(0, 8), &ball);
	
	break;

    case straightRightPaddleBottomCollision:
	paddleTwo.x = FPMAKE(280,0);
	paddleTwo.y = FPMAKE(90,0);
	paddleTwo.xVel = FPMAKE(0,0);
	paddleTwo.yVel = FPMAKE(1,0);
	
	paddleOne.x = FPMAKE(35,0);
	paddleOne.y = FPMAKE(90,0);

	ball.x = FPMAKE(270,0);
	ball.y = FPMAKE(100+DEFAULT_PADDLE_HEIGHT+8,0);
	ball.xVel = FPMAKE(1,0);
	ball.yVel = FPMAKE(0,0);

	setBallXVel(FPMAKE(0, 8), &ball);
	
	break;

    case straightRightPaddleRearCollision:
	paddleOne.x = FPMAKE(DEFAULT_LEFT_ACCAREA_X + DEFAULT_LEFT_ACCAREA_WIDTH - DEFAULT_PADDLE_WIDTH, 0);
	paddleOne.y = FPMAKE(100,0);
	ball.x = FPMAKE(FPINT(paddleOne.x) - DEFAULT_BALL_WIDTH - 5, 0);
	ball.y = FPMAKE(100,0);
	setBallXVel(-1*FPMAKE(0, 6), &ball);
	setPaddleXVel(FPMAKE(-1,0), &paddleOne);

     	break;
    case straightLeftPaddleRearCollision:
	paddleTwo.x = FPMAKE(DEFAULT_RIGHT_ACCAREA_X, 0);
	paddleTwo.y = FPMAKE(100,0);
	ball.x = FPMAKE(FPINT(paddleTwo.x) + DEFAULT_BALL_WIDTH + 5, 0);
	ball.y = FPMAKE(100,0);
	setBallXVel(FPMAKE(0, 6), &ball);
	setPaddleXVel(FPMAKE(1,0), &paddleTwo);
	break;

    case noStartState:
	gPngGame.isPlayerOneHuman = 1;
	gPngGame.isPlayerTwoHuman = 0;
	break;
    default:
	printf("default - please provide a value");
	break;
    }

    assembleDefaultPongGame();
 }