diff --git a/defs.h b/defs.h index 65129bd..e7d7711 100644 --- a/defs.h +++ b/defs.h @@ -196,6 +196,8 @@ #define MAXHISCORES 10 #define MAXHISCORENAME 10 +#define HISCORE_DISPLAYTIME 10 // how many secs to display hiscores for + // Fixed text buffer sizes #define BUFLEN 512 #define MIDBUFLEN 64 @@ -486,6 +488,9 @@ #define TS_INSERTCOIN 0 #define TS_WAIT1UP 1 #define TS_SELECTMODE 2 +#define TS_HISCORES 3 + +#define TTIME 10 // time between state switches in title screen // Game modes #define GM_EASY 0 diff --git a/rc.c b/rc.c index 15d267b..fdab38f 100644 --- a/rc.c +++ b/rc.c @@ -131,6 +131,7 @@ int pokerpoints; SDL_Color red = {255, 0, 0, 0}; SDL_Color red2 = {150, 0, 0, 0}; +SDL_Color red3 = {90, 0, 0, 0}; SDL_Color orange = {255, 167, 88, 1}; SDL_Color black = {0, 0, 0, 0}; SDL_Color blue = {0, 0, 255, 0}; @@ -7286,6 +7287,7 @@ void dotitlescreen(void) { int timer = 0; //int i; int texton = B_TRUE; + int htstart = 0, htime = 0,hticks; // load title screen @@ -7348,17 +7350,20 @@ void dotitlescreen(void) { } } - // draw screen - SDL_BlitSurface(titlebg, NULL, screen, NULL); - // draw text + - drawcredits(); + // draw screen + if (titlemode != TS_HISCORES) { + SDL_BlitSurface(titlebg, NULL, screen, NULL); + } else { + SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); + } // mode-specific text - if (titlemode == TS_INSERTCOIN) { + if ((titlemode == TS_INSERTCOIN) || (titlemode == TS_HISCORES)) { if (texton) { area.x = 320 - (cointext->w/2)+2; - area.y = 240 - (cointext->h/2)+2; + area.y = 10; SDL_SetColors(cointext, &black, 1, 1); SDL_BlitSurface(cointext, NULL, screen, &area); @@ -7367,7 +7372,8 @@ void dotitlescreen(void) { SDL_SetColors(cointext, &white, 1, 1); SDL_BlitSurface(cointext, NULL, screen, &area); } - } else if (titlemode == TS_WAIT1UP) { + } + if (titlemode == TS_WAIT1UP) { //if (texton) { area.x = 320 - (text->w/2)+2; area.y = 240 - (text->h/2)+2; @@ -7444,10 +7450,37 @@ void dotitlescreen(void) { SDL_BlitSurface(desc, NULL, screen, &area); SDL_FreeSurface(desc); } + } else if (titlemode == TS_HISCORES) { + drawhiscores(); + } + + // draw text + drawcredits(); + + SDL_UpdateRect(screen, 0,0,640,480); + + hticks = SDL_GetTicks(); + if (htstart == 0) { + htstart = hticks; + } else { + /* once per second */ + if (hticks - htstart >= 1000) { + htime++; + htstart = hticks; + } + + if (htime == TTIME) { + if (titlemode == TS_INSERTCOIN) { + titlemode = TS_HISCORES; + } else if (titlemode == TS_HISCORES) { + titlemode = TS_INSERTCOIN; + } + htime = 0; + } + } - SDL_UpdateRect(screen, 0,0,640,480); } // clear screen to black //SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); @@ -7559,11 +7592,7 @@ void uncatch(sprite_t *s) { } void makeinvuln(sprite_t *s) { - if ((s == player) && (gamemode == GM_EASY)) { - s->invuln = INVULNTIME*2; - } else { - s->invuln = INVULNTIME; - } + s->invuln = INVULNTIME; } @@ -7601,7 +7630,7 @@ void handletitleinput(int key) { // quit exit(0); } - if (titlemode == TS_INSERTCOIN) { + if ((titlemode == TS_INSERTCOIN) || (titlemode == TS_HISCORES)) { if ((key == SDLK_5) || (key == SDLK_6) || (key == SDLK_RETURN)) { credits++; playfx(FX_COIN); @@ -7878,7 +7907,7 @@ void checkhiscores(void){ // print name drawoutlinetext(screen, x, y, TEXTSIZE_HISCORE, "Name", &cyan, &blue); - y += 40; + y += (TEXTSIZE_HISCORE*2); x = sx; // player's score... @@ -8034,11 +8063,9 @@ void checkhiscores(void){ void showhiscores(void){ int finished = B_FALSE; - int i; - char srank[BUFLEN],sscore[BUFLEN],slevel[BUFLEN],sname[BUFLEN]; //char line[BUFLEN]; - char commascore[BUFLEN]; - int x,y,sx,sy; + int htstart = 0, htime = 0,hticks; + // contact server and read list /* @@ -8062,63 +8089,8 @@ void showhiscores(void){ while (!finished) { SDL_Event event; - //draw hiscore list - sx = 110; - sy = 100; - x = sx; - y = sy; - // headings - drawoutlinecentretext(screen, 50, TEXTSIZE_HISCORE, "High Scores", &cyan, &blue); - - // print rank - drawoutlinetext(screen, x, y, TEXTSIZE_HISCORE, "Rank", &cyan, &blue); - x += 70; - // print score - drawoutlinetext(screen, x, y, TEXTSIZE_HISCORE, "Score", &cyan, &blue); - x += 150; - // print level - drawoutlinetext(screen, x, y, TEXTSIZE_HISCORE, "Level", &cyan, &blue); - x += 90; - // print name - drawoutlinetext(screen, x, y, TEXTSIZE_HISCORE, "Name", &cyan, &blue); - - y += 40; - x = sx; - - for (i = 0; i < numhiscores; i++) { - SDL_Color *fg, *bg; - // generate hiscore lines - sprintf(srank, "%-2d.",i+1); - addcommas(commascore, hiscore[i].score); - sprintf(sscore, "%-14s",commascore); - sprintf(slevel, "%1d-%-2d",getworld(hiscore[i].level),getlevel(hiscore[i].level)); - sprintf(sname, "%-32s",hiscore[i].name); - - if ((gothiscore != -1) && (i == gothiscore)) { - fg = &white; - bg = &grey2; - } else { - fg = &red; - bg = &red2; - } - - // print rank - drawoutlinetext(screen, x, y, TEXTSIZE_HISCORE, srank, fg, bg); - x += 70; - // print score - drawoutlinetext(screen, x, y, TEXTSIZE_HISCORE, sscore, fg, bg); - x += 150; - // print level - drawoutlinetext(screen, x, y, TEXTSIZE_HISCORE, slevel, fg, bg); - x += 90; - // print name - drawoutlinetext(screen, x, y, TEXTSIZE_HISCORE, sname, fg, bg); - - // go to next line - x = sx; - y += (TEXTSIZE_HISCORE+2); - } + drawhiscores(); // wait for a key... if (SDL_PollEvent(&event)) { @@ -8144,6 +8116,25 @@ void showhiscores(void){ } SDL_UpdateRect(screen, 0,0,640,480); + + + hticks = SDL_GetTicks(); + if (htstart == 0) { + htstart = hticks; + } else { + /* once per second */ + if (hticks - htstart >= 1000) { + htime++; + htstart = hticks; + } + + if (htime >= HISCORE_DISPLAYTIME) { + finished = B_TRUE; + } + + } + + } // stop music ready for title screen again (it will only be playing if @@ -8194,3 +8185,69 @@ int socket_readline(int sock, char* out) { return i + 1; } + +void drawhiscores(void) { + char srank[BUFLEN],sscore[BUFLEN],slevel[BUFLEN],sname[BUFLEN]; + char commascore[BUFLEN]; + int x,y,sx,sy; + int i; + + //draw hiscore list + sx = 110; + sy = 100; + x = sx; + y = sy; + + // headings + drawoutlinecentretext(screen, 50, TEXTSIZE_HISCORE, "High Scores", &cyan, &blue); + + // print rank + drawoutlinetext(screen, x, y, TEXTSIZE_HISCORE, "Rank", &cyan, &blue); + x += 70; + // print score + drawoutlinetext(screen, x, y, TEXTSIZE_HISCORE, "Score", &cyan, &blue); + x += 150; + // print level + drawoutlinetext(screen, x, y, TEXTSIZE_HISCORE, "Level", &cyan, &blue); + x += 90; + // print name + drawoutlinetext(screen, x, y, TEXTSIZE_HISCORE, "Name", &cyan, &blue); + + y += (TEXTSIZE_HISCORE*2); + x = sx; + + for (i = 0; i < numhiscores; i++) { + SDL_Color *fg, *bg; + // generate hiscore lines + sprintf(srank, "%-2d.",i+1); + addcommas(commascore, hiscore[i].score); + sprintf(sscore, "%-14s",commascore); + sprintf(slevel, "%1d-%-2d",getworld(hiscore[i].level),getlevel(hiscore[i].level)); + sprintf(sname, "%-32s",hiscore[i].name); + + if ((gothiscore != -1) && (i == gothiscore)) { + fg = &white; + bg = &grey2; + } else { + fg = &red; + bg = &red3; + } + + // print rank + drawoutlinetext(screen, x, y, TEXTSIZE_HISCORE, srank, fg, bg); + x += 70; + // print score + drawoutlinetext(screen, x, y, TEXTSIZE_HISCORE, sscore, fg, bg); + x += 150; + // print level + drawoutlinetext(screen, x, y, TEXTSIZE_HISCORE, slevel, fg, bg); + x += 90; + // print name + drawoutlinetext(screen, x, y, TEXTSIZE_HISCORE, sname, fg, bg); + + // go to next line + x = sx; + y += (TEXTSIZE_HISCORE+2); + } + +} diff --git a/rc.h b/rc.h index d20bc70..95130da 100644 --- a/rc.h +++ b/rc.h @@ -94,4 +94,5 @@ int socket_readline(int sock, char *out); void showhiscores(void); void checkhiscores(void); int gethiscores(void); +void drawhiscores(void); int submithiscore(int score,int level, char *name);