void render(){ display.Clear(); drawGhost(); drawBlock(CODE); drawMap(); drawBorders(); drawNextBlock(); sprintf(TEXT,"Score: %i",score); display.DrawString(TEXT, ((WIDTH))*BLOCKPIXSIZE, (0)*BLOCKPIXSIZE,0,0x00FF00); sprintf(TEXT,"Highscore: %i",hscore); display.DrawString(TEXT, ((WIDTH))*BLOCKPIXSIZE, (1)*BLOCKPIXSIZE,0,0x00FF00); sprintf(TEXT,"Next:"); display.DrawString(TEXT, ((WIDTH))*BLOCKPIXSIZE, (4)*BLOCKPIXSIZE,0,0x00FF00); display.Render(); }
void resetGame(){ //==========================START MSG Prints Highscore while(!keyboard.s){ display.Clear(); drawMap(); drawBorders(); sprintf(TEXT,"Press 's' to start"); display.DrawString(TEXT, 0, (HEIGHT/2)*BLOCKPIXSIZE,0,0x00FF00); display.Render(); keyboard.Poll(); SDL_Delay(50); } for(int i=0;i < WIDTH;i++){ for(int ii=0;ii < HEIGHT;ii++){ map[i][ii] = 0; } } score = 0; newBlock(); }
int main (int argc, char *argv[]) { srand ( time(NULL) ); sound.LoadSound("blockHit","hit.wav"); sound.LoadSound("horizontal","horizon2.wav"); sound.LoadSound("rotate","rotate.wav"); loadHighscore(&hscore); resetGame(); while (keyboard.Quit == false) { if(keyboard.r){ keyboard.Clear(); resetGame(); } if(keyboard.p){ SDL_Delay(100); keyboard.Poll(); keyboard.Clear(); while(!keyboard.p){ keyboard.Poll(); display.Clear(); drawBorders(); sprintf(TEXT,"Game is paused."); display.DrawString(TEXT, 0, (HEIGHT/2)*BLOCKPIXSIZE,0,0x00FF00); display.Render(); SDL_Delay(50); } } int speed = 0; speed = score/2400; if(speed > 40){speed = 40;} if(!(cycle% (60-speed)) || keyboard.Down){fallBlock(); HorizontalStrip(); if(keyboard.Down)keyboard.Clear(); } keyboard.Poll(); if(keyboard.Left && InvasiveCheckPass(blockx-1,blocky,blockt,blockr)){ --blockx; keyboard.Clear();} if(keyboard.Right && InvasiveCheckPass(blockx+1,blocky,blockt,blockr)){++blockx; keyboard.Clear();} if(keyboard.Up && InvasiveCheckPass(blockx,blocky,blockt,blockr+1)){ blockr = (++blockr > 3) ? 0 : blockr; updateBlockBoundaries(); sound.PlaySound("rotate",80,0); keyboard.Clear(); } if(keyboard.Space){ while(InvasiveCheckPass(blockx,blocky+1,blockt,blockr)){fallBlock(); HorizontalStrip();} gridLockBlock(); keyboard.Clear(); SDL_Delay(80); } blockx = (blockx< -minxcord) ? -minxcord : ((blockx > (WIDTH-1)-maxxcord) ? (WIDTH-1)-maxxcord : blockx); render(); char TXT[128]; if(speed > 30){sprintf(TXT,"EXTREME PENTRIX: %i",hscore);} else{sprintf(TXT,"Pentrix Highscore: %i",hscore);} display.Caption(TXT); SDL_Delay (4); cycle = (++cycle > 239) ? 1 : cycle; } return 0; }