void drawGame(Game *game){ drawImage(game->sprites[gBACKGROUND].image, 0, 0); int i,j; for(i=0; i < game->grid->dimensionX; i++) for(j=0; j < game->grid->dimensionY; j++){ drawImage(game->sprites[GRID_TILE].image, game->grid->tiles[i][j].x, game->grid->tiles[i][j].y); char str[1]; sprintf(str, "%i", game->grid->tiles[i][j].distFromExit); drawString(str, game->grid->tiles[i][j].x, game->grid->tiles[i][j].y, game->font, 0, 0, game->fontColor, game->fontBGColor); } drawTowers(game); Enemy *curEnemy = game->enemies; while(curEnemy != NULL){ drawImage(game->sprites[curEnemy->type].image, curEnemy->x, curEnemy->y); //draw health bar SDL_Rect rect = {curEnemy->x, curEnemy->y, game->sprites[curEnemy->type].image->w, 4}; SDL_FillRect(screen, &rect, 0xAAAAAA); rect.w = game->sprites[curEnemy->type].image->w * curEnemy->health / curEnemy->maxHealth; SDL_FillRect(screen, &rect, 0xFF0000); curEnemy = curEnemy->nextEnemy; } drawBullets(game); SDL_Rect rect = {game->grid->selectedTile->x+20, game->grid->selectedTile->y+20, 10, 10}; SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, game->rRatio, game->gRatio, game->bRatio)); char str[20]; sprintf(str, "Press M to go to menu. Score: %d", game->score); drawString(str, 0, 650, game->font, 1, 0, game->fontColor, game->fontBGColor); sprintf(str, "Red: %i", game->rStored); drawString(str, 0, 20, game->font, 0, 0, game->fontColor, game->fontBGColor); sprintf(str, "Green: %i", game->gStored); drawString(str, 0, 40, game->font, 0, 0, game->fontColor, game->fontBGColor); sprintf(str, "Blue: %i", game->bStored); drawString(str, 0, 60, game->font, 0, 0, game->fontColor, game->fontBGColor); sprintf(str, "R:G:B = %i, %i, %i", game->rRatio, game->gRatio, game->bRatio); drawString(str, 0, 0, game->font, 0, 0, game->fontColor, game->fontBGColor); sprintf(str, "Lives left: %i", game->lives); drawString(str, 0, 80, game->font, 0, 0, game->fontColor, game->fontBGColor); double total = (game->rRatio + game->gRatio + game->bRatio) / (double)game->towerPrices[game->selectedTowerType]; sprintf(str, "Cost for selected Tower: %d,%d,%d", (int)(game->rRatio/total), (int)(game->gRatio/total), (int)(game->bRatio/total)); drawString(str, 0, 0, game->font, 0, 0, game->fontColor, game->fontBGColor); SDL_Flip(screen); };
void Board::draw() { drawTowers(); drawWalls(); }
void selectUnitsInterface(Path* thePath, UnitListHeader * unitList, int * moneyAmount, TowerArray* theTowerList, int * theScore) { int currentOption = 1; int unitSelection = 0; Unit * toAdd; int levelCap = 1; while(levelCap < 6) { switch(getch()) { case KEY_UP: //move selection up one currentOption -= 1; if (currentOption < 1) { currentOption = 1; } //draw box around option (and remove old) attron(COLOR_PAIR(3)); removeChoiceBoxes(); addBoxChoiceOption(currentOption); attroff(COLOR_PAIR(3)); break; case KEY_DOWN: //move selection down one currentOption += 1; if (currentOption > 4) { currentOption = 4; } //draw box around option (and remove old) attron(COLOR_PAIR(3)); removeChoiceBoxes(); addBoxChoiceOption(currentOption); attroff(COLOR_PAIR(3)); break; case KEY_RIGHT: //if on unit selection, change if (currentOption == 1) { //switch unit selection if (unitSelection < 4) { unitSelection++; //mvaddstr(15,113," > "); updateUnitChoice(unitSelection); } } break; case KEY_LEFT: //if on unit selection, change if (currentOption == 1) { //switch unit selection if (unitSelection > 0) { unitSelection--; //mvaddstr(15,64," < "); updateUnitChoice(unitSelection); } } break; case '\n': //select whatever is being hovered on switch(currentOption) { case 4: return; case 3: if (unitList->size > 0) { //hide buttons mvaddstr(25,85," "); mvaddstr(28,80," "); mvaddstr(29,80," "); mvaddstr(30,80," "); mvaddstr(33,83," "); if (mainRunningLoop(theTowerList,thePath,unitList,theScore,moneyAmount) == 1) { *moneyAmount += 150; levelCap++; if (levelCap < 6) { //after done attron(COLOR_PAIR(0)); drawPurchaseArea(); basicSetupScreen(levelCap); updateMoney(*moneyAmount); attroff(COLOR_PAIR(0)); //change attron(COLOR_PAIR(3)); removeChoiceBoxes(); addBoxChoiceOption(3); attroff(COLOR_PAIR(3)); destroyTowerArray(theTowerList); //load level file switch(levelCap) { case 2: theTowerList = getTowerArray("assets/towersLevel2.txt"); break; case 3: theTowerList = getTowerArray("assets/towersLevel3.txt"); break; case 4: theTowerList = getTowerArray("assets/towersLevel4.txt"); break; case 5: theTowerList = getTowerArray("assets/towersLevel5.txt"); break; case 6: theTowerList = getTowerArray("assets/towersLevel5.txt"); break; } drawTowers(theTowerList); updateUnitChoice(unitSelection); } } } break; case 1: break; case 2: toAdd = malloc(sizeof(Unit)); //purchase units switch(unitSelection) { case 0: if (*moneyAmount >= unit1Cost) { *moneyAmount -= unit1Cost; NewUnit(toAdd,unit1,unitList); } break; case 1: if (*moneyAmount >= unit2Cost) { *moneyAmount -= unit2Cost; NewUnit(toAdd,unit2,unitList); } break; case 2: if (*moneyAmount >= unit3Cost) { *moneyAmount -= unit3Cost; NewUnit(toAdd,unit3,unitList); } break; case 3: if (*moneyAmount >= unit4Cost) { *moneyAmount -= unit4Cost; NewUnit(toAdd,unit4,unitList); } break; case 4: if (*moneyAmount >= unit5Cost) { *moneyAmount -= unit5Cost; NewUnit(toAdd,unit5,unitList); } break; } //display new amount of money updateMoney(*moneyAmount); drawUnitTypes(unitList); break; default: break; } break; default: //some other irrelevant key was pressed (ignore it) break; } } }
void drawGameScreen() { clear(); //draw exterior of game drawBox(10, 3, 44, 34, 0); //draw path walls drawBox(10, 7, 11, 3, 0); drawBox(18, 7, 4, 14, 0); drawBox(18, 18, 16, 3, 0); drawBox(31, 7, 4, 14, 0); drawBox(31, 7, 18, 3, 0); drawBox(46, 7, 4, 24, 0); drawBox(19, 28, 30, 3, 0); drawBox(19, 28, 4, 9, 0); //fix up the corners clearPath(); fixCorners(); //add beginning and ending chars mvaddch(8, 8, '>'); mvaddch(37, 21, ACS_DARROW); //draw and fill the purchase portion of the screen attron(COLOR_PAIR(0)); drawPurchaseArea(); basicSetupScreen(1); updateScore(0); attroff(COLOR_PAIR(0)); drawTowerExplain(); //load arrays for drawing TowerArray* theTowerList = getTowerArray("assets/towersLevel1.txt"); Path* thePath = getPathArray("assets/path.txt"); UnitListHeader * unitList = malloc(sizeof(UnitListHeader)); int moneyAmount = STARTINGMONEY; initializeList(unitList); drawUnitTypes(unitList); int theScore = 0; drawTowers(theTowerList); //go to entering unit purchases (gives control back to user) selectUnitsInterface(thePath,unitList,&moneyAmount,theTowerList,&theScore); //get lowest score of highscores ScoreHead scores; scores.size = 0; scores.first = NULL; ScoreNode * currScore = NULL; readScores(&scores); currScore = scores.first; int numScores = 1; int highestScore = 0; while ((currScore->next != NULL) && (numScores < 9)) { numScores += 1; currScore = currScore->next; } highestScore = -1; if (numScores > 8 && currScore != NULL) { highestScore = currScore->score; } char * enterName; if (theScore > highestScore) { enterName = drawScore(theScore,1); if (enterName != NULL) { addScore(&scores, enterName, theScore); writeScores(&scores); } } else { drawScore(theScore,0); } if (scores.size > 0) destroyScores(&scores); }