void World::DrawPlayer2() { DrawPlayerPaddle(m_player2); }
inline void update(GameState *state) { localPersist vector2 ballMoveVector = {0,0}; clearBackgroundToColor(Vector3(0,0,0)); DrawCenterLine(); DrawPlayerPaddle(&state->playerPaddle); DrawComputerPaddle(&state->computerPaddle); //TODO:Handle Ball Math if(state->gameInprogress) { if(ballMoveVector == Vector2(0,0)) { ballMoveVector.x = -state->ball.moveSpeed; } if((state->ball.locationOnScreen.x <= 30 && state->ball.locationOnScreen.x >= 20) || (state->ball.locationOnScreen.x >= (screenWidth-30) && state->ball.locationOnScreen.x <= (screenWidth-20))) { r32 playerPaddleTop= \ state->playerPaddle.originLocationHeight + (state->playerPaddle.height/2.0f); r32 playerPaddleBottom= \ state->playerPaddle.originLocationHeight - (state->playerPaddle.height/2.0f); r32 computerPaddleTop= \ state->computerPaddle.originLocationHeight + (state->computerPaddle.height/2.0f); r32 computerPaddleBottom= \ state->computerPaddle.originLocationHeight - (state->computerPaddle.height/2.0f); if((state->ball.locationOnScreen.y <= playerPaddleTop && state->ball.locationOnScreen.y >= playerPaddleBottom) || (state->ball.locationOnScreen.y <= computerPaddleTop && state->ball.locationOnScreen.y >= computerPaddleBottom)) { ballMoveVector = -ballMoveVector; } } state->ball.locationOnScreen += ballMoveVector; // moveball if(state->ball.locationOnScreen.x <= 0) { state->gameScore.y += 1; ResetBallPostition(&state->ball); if(state->gameScore.y == 10) { //TODO: Game over section (player Loses) state->gameInprogress=false; ballMoveVector = Vector2(0,0); } } else if(state->ball.locationOnScreen.y >= screenWidth) { state->gameScore.x += 1; ResetBallPostition(&state->ball); if(state->gameScore.x == 10) { //TODO: Game over section (player wins) state->gameInprogress=false; ballMoveVector = Vector2(0,0); } } } DrawBall(&state->ball); }
void World::DrawPlayer1() { DrawPlayerPaddle(m_player1); }