void SpaceShip::render() { glPushMatrix(); glTranslatef(x + startX + shipWidth / 2, y + startY + shipHeight / 2, 0); glRotatef(rotateDeg, 0, 0, 1); glTranslatef(-x - startX - shipWidth / 2, -y - startY - shipHeight / 2, 0); glTranslatef(x, y, 0.0); draw(); glPopMatrix(); drawFuel(); drawTimer(); }
void HUD::drawHUD(int score, int multiplier, int timeRemaining) { ////// //Draw the score text ///// char scoreAsChar[10];//limiting this to 10 will probably cause mad //crashes when scores start getting smashed all round the gaff _itoa(score, scoreAsChar,10); //we want to pin the score to right-alignment, like in the game-over screen //calculate the score's width float scoreOffset = getStringWidth(scoreFont,0,0, scoreAsChar); printWithColour(scoreTextFont, scorePos.x, scorePos.y, scoreTextColour, scoreText); printWithColour(scoreFont, scorePos.x+205-scoreOffset, scorePos.y, scoreColour, scoreAsChar); drawMulti(multiplier); drawTimer(timeRemaining); }
// ----------------------- draws the display void HIDbase::paintLCD( ) { if( HIDstate != confirm_reset_state ) { // normal display, draw it one row at a time if( ! (statusLCD & (1 << ROW_BIT)) ) { // draw the fields in the first row statusLCD |= ( 1 << ROW_BIT ); // set up for drawing second row in next loop if( statusLCD & (1 << TIMER_BIT) ) { drawTimer(); // first line of display statusLCD &= ~(1 << TIMER_BIT); // clear status bit for field } if( statusLCD & (1 << LEVEL_1_BIT) ) { drawLevel_1(); // first line of display statusLCD &= ~(1 << LEVEL_1_BIT); // clear status bit for field } if( statusLCD & (1 << T2_BIT) ) { drawT2(); // first line of display statusLCD &= ~(1 << T2_BIT); // clear status bit for field } } else { // draw the fields in the second row statusLCD &= ~( 1 << ROW_BIT ); // set up for drawing first row in next loop if( statusLCD & (1 << ROR_BIT) ) { drawRoR(); // second line of display statusLCD &= ~(1 << ROR_BIT); // clear status bit for field } if( statusLCD & (1 << LEVEL_2_BIT) ) { drawLevel_2(); // second line of display statusLCD &= ~(1 << LEVEL_2_BIT); // clear status bit for field } if( statusLCD & (1 << T1_BIT) ) { drawT1(); // second line of display statusLCD &= ~(1 << T1_BIT); // clear status bit for field } } } else { if( statusLCD & (1 << CONFIRM_BIT) ) { drawConfirmReset(); // screen asking for user confirmation statusLCD = 0; // paint display only once } } }
void drawScoreBoard( BoardCtxt* board ) { if ( board->scoreBoardInvalid ) { XP_U16 ii; XP_U16 nPlayers = board->gi->nPlayers; DrawFocusState dfs = dfsFor( board, OBJ_SCORE ); ScoresArray scores; ModelCtxt* model = board->model; XP_S16 nTilesInPool = server_countTilesInPool( board->server ); if ( board->gameOver ) { model_figureFinalScores( model, &scores, NULL ); } else { for ( ii = 0; ii < nPlayers; ++ii ) { scores.arr[ii] = model_getPlayerScore( model, ii ); } } if ( draw_scoreBegin( board->draw, &board->scoreBdBounds, nPlayers, scores.arr, nTilesInPool, dfs ) ) { XP_S16 curTurn = server_getCurrentTurn( board->server ); XP_U16 selPlayer = board->selPlayer; XP_Rect scoreRect; XP_Rect playerRects[nPlayers]; XP_U16 remDim; XP_Bool isVertical = !board->scoreSplitHor; XP_Bool remFocussed = XP_FALSE; XP_Bool focusAll = XP_FALSE; DrawScoreInfo data[nPlayers]; #ifdef KEYBOARD_NAV XP_S16 cursorIndex = -1; if ( (board->focussed == OBJ_SCORE) && !board->hideFocus ) { focusAll = !board->focusHasDived; if ( !focusAll ) { cursorIndex = board->scoreCursorLoc; remFocussed = CURSOR_LOC_REM == cursorIndex; --cursorIndex; } } #endif XP_MEMSET( playerRects, 0, sizeof(playerRects) ); XP_MEMSET( data, 0, sizeof(data) ); scoreRect = board->scoreBdBounds; if ( !draw_drawRemText( board->draw, nTilesInPool, focusAll || remFocussed, &scoreRect ) ) { scoreRect.height = scoreRect.width = 0; } XP_ASSERT( rectContainsRect( &board->scoreBdBounds, &scoreRect ) ); remDim = isVertical? scoreRect.height : scoreRect.width; board->remDim = remDim; #ifdef KEYBOARD_NAV board->remRect = scoreRect; if ( 0 == remDim && board->scoreCursorLoc == CURSOR_LOC_REM ) { board->scoreCursorLoc = selPlayer + 1; } #endif scoreRect = board->scoreBdBounds; if ( isVertical ) { scoreRect.height -= remDim; scoreRect.top += remDim; } else { scoreRect.width -= remDim; scoreRect.left += remDim; } for ( ii = 0; ii < nPlayers; ++ii ) { DrawScoreInfo* dsi = &data[ii]; LocalPlayer* lp = &board->gi->players[ii]; dsi->lsc = board_ScoreCallback; dsi->lscClosure = model; #ifdef KEYBOARD_NAV if ( (ii == cursorIndex) || focusAll ) { dsi->flags |= CELL_ISCURSOR; } #endif dsi->playerNum = ii; dsi->totalScore = scores.arr[ii]; dsi->isTurn = (ii == curTurn); dsi->name = emptyStringIfNull(lp->name); dsi->selected = board->trayVisState != TRAY_HIDDEN && ii==selPlayer; dsi->isRobot = LP_IS_ROBOT(lp); dsi->isRemote = !lp->isLocal; dsi->nTilesLeft = (nTilesInPool > 0)? -1: model_getNumTilesTotal( model, ii ); } draw_score_drawPlayers( board->draw, &scoreRect, nPlayers, data, playerRects ); for ( ii = 0; ii < nPlayers; ++ii ) { XP_Rect* rp = &playerRects[ii]; board->pti[ii].scoreDims = isVertical ? rp->height : rp->width; #ifdef KEYBOARD_NAV XP_MEMCPY( &board->pti[ii].scoreRects, rp, sizeof(board->pti[ii].scoreRects) ); #endif } draw_objFinished( board->draw, OBJ_SCORE, &board->scoreBdBounds, dfs ); board->scoreBoardInvalid = XP_FALSE; } } drawTimer( board ); } /* drawScoreBoard */
void drawScoreBoard( BoardCtxt* board ) { if ( board->scoreBoardInvalid ) { short ii; XP_U16 nPlayers = board->gi->nPlayers; XP_ASSERT( nPlayers <= MAX_NUM_PLAYERS ); if ( nPlayers > 0 ) { ModelCtxt* model = board->model; XP_S16 curTurn = server_getCurrentTurn( board->server ); XP_U16 selPlayer = board->selPlayer; XP_S16 nTilesInPool = server_countTilesInPool( board->server ); XP_Rect scoreRect = board->scoreBdBounds; XP_S16* adjustDim; XP_S16* adjustPt; XP_U16 remWidth, remHeight, remDim; DrawScoreData* dp; DrawScoreData datum[MAX_NUM_PLAYERS]; ScoresArray scores; XP_Bool isVertical = !board->scoreSplitHor; XP_Bool remFocussed = XP_FALSE; XP_Bool focusAll = XP_FALSE; #ifdef KEYBOARD_NAV XP_S16 cursorIndex = -1; if ( (board->focussed == OBJ_SCORE) && !board->hideFocus ) { focusAll = !board->focusHasDived; if ( !focusAll ) { cursorIndex = board->scoreCursorLoc; remFocussed = CURSOR_LOC_REM == cursorIndex; --cursorIndex; } } #endif /* Get the scores from the model or by calculating them based on the end-of-game state. */ if ( board->gameOver ) { model_figureFinalScores( model, &scores, NULL ); } else { for ( ii = 0; ii < nPlayers; ++ii ) { scores.arr[ii] = model_getPlayerScore( model, ii ); } } if ( draw_scoreBegin( board->draw, &board->scoreBdBounds, nPlayers, scores.arr, nTilesInPool, dfsFor( board, OBJ_SCORE ) ) ) { XP_U16 totalDim = 0; /* not counting rem */ XP_U16 gotPct; /* Let platform decide whether the rem: string should be given any space once there are no tiles left. On Palm that space is clickable to drop a menu, so will probably leave it. */ if ( !draw_measureRemText( board->draw, &board->scoreBdBounds, nTilesInPool, &remWidth, &remHeight ) ) { remWidth = remHeight = 0; } XP_ASSERT( remWidth <= board->scoreBdBounds.width ); XP_ASSERT( remHeight <= board->scoreBdBounds.height ); remDim = isVertical? remHeight : remWidth; if ( isVertical ) { adjustPt = &scoreRect.top; adjustDim = &scoreRect.height; } else { adjustPt = &scoreRect.left; adjustDim = &scoreRect.width; } *adjustDim -= remDim; /* Give as much room as possible to the entry for the player whose turn it is so name can be drawn. Do that by formatting that player's score last, and passing each time the amount of space left. Platform code can then fill that space. */ /* figure spacing for each scoreboard entry */ XP_MEMSET( &datum, 0, sizeof(datum) ); totalDim = 0; for ( dp = datum, ii = 0; ii < nPlayers; ++ii, ++dp ) { LocalPlayer* lp = &board->gi->players[ii]; /* This is a hack! */ dp->dsi.lsc = board_ScoreCallback; dp->dsi.lscClosure = model; #ifdef KEYBOARD_NAV if ( (ii == cursorIndex) || focusAll ) { dp->dsi.flags |= CELL_ISCURSOR; } #endif dp->dsi.playerNum = ii; dp->dsi.totalScore = scores.arr[ii]; dp->dsi.isTurn = (ii == curTurn); dp->dsi.name = emptyStringIfNull(lp->name); dp->dsi.selected = board->trayVisState != TRAY_HIDDEN && ii==selPlayer; dp->dsi.isRobot = LP_IS_ROBOT(lp); dp->dsi.isRemote = !lp->isLocal; dp->dsi.nTilesLeft = (nTilesInPool > 0)? -1: model_getNumTilesTotal( model, ii ); draw_measureScoreText( board->draw, &scoreRect, &dp->dsi, &dp->width, &dp->height ); XP_ASSERT( dp->width <= scoreRect.width ); XP_ASSERT( dp->height <= scoreRect.height ); totalDim += isVertical ? dp->height : dp->width; } gotPct = (*adjustDim * 100) / totalDim; for ( dp = datum, ii = 0; ii < nPlayers; ++ii, ++dp ) { if ( isVertical ) { dp->height = (dp->height * gotPct) / 100; } else { dp->width = (dp->width * gotPct) / 100; } } scoreRect = board->scoreBdBounds; /* reset */ /* at this point, the scoreRect should be anchored at the scoreboard rect's upper left. */ if ( remDim > 0 ) { XP_Rect innerRect; *adjustDim = remDim; centerIn( &innerRect, &scoreRect, remWidth, remHeight ); draw_drawRemText( board->draw, &innerRect, &scoreRect, nTilesInPool, focusAll || remFocussed ); *adjustPt += remDim; #ifdef KEYBOARD_NAV board->remRect = scoreRect; /* Hack: don't let the cursor disappear if Rem: goes away */ } else if ( board->scoreCursorLoc == CURSOR_LOC_REM ) { board->scoreCursorLoc = selPlayer + 1; #endif } board->remDim = remDim; for ( dp = datum, ii = 0; ii < nPlayers; ++dp, ++ii ) { XP_Rect innerRect; XP_U16 dim = isVertical? dp->height:dp->width; *adjustDim = board->pti[ii].scoreDims = dim; centerIn( &innerRect, &scoreRect, dp->width, dp->height ); draw_score_drawPlayer( board->draw, &innerRect, &scoreRect, gotPct, &dp->dsi ); #ifdef KEYBOARD_NAV XP_MEMCPY( &board->pti[ii].scoreRects, &scoreRect, sizeof(scoreRect) ); #endif *adjustPt += *adjustDim; } draw_objFinished( board->draw, OBJ_SCORE, &board->scoreBdBounds, dfsFor( board, OBJ_SCORE ) ); board->scoreBoardInvalid = XP_FALSE; } } } drawTimer( board ); } /* drawScoreBoard */