From f39e2ef53ae9a1fdbd683a858f17e7ef7ca7af5b Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Sun, 19 Oct 2008 22:58:54 +0000 Subject: [PATCH] - Added "Easy Mode" - gives more lives, longer time limit before hurryup, longer invulnerability at start --- defs.h | 10 +++ globals.h | 2 + rc.c | 188 +++++++++++++++++++++++++++++++++++++++++++----------- rc.h | 1 + shared.c | 13 +++- shared.h | 1 + 6 files changed, 174 insertions(+), 41 deletions(-) diff --git a/defs.h b/defs.h index e6f77ea..18716da 100644 --- a/defs.h +++ b/defs.h @@ -45,6 +45,7 @@ #define TEXTSIZE_CLOVER 20 #define TEXTSIZE_DEATH 20 #define TEXTSIZE_TITLE 20 +#define TEXTSIZE_TITLE2 16 #define TEXTSIZE_LEVEL2 22 #define TEXTSIZE_BIFF 26 #define TEXTSIZE_MULTI 26 @@ -473,6 +474,14 @@ #define F_SWIM2 17 +// Title screen states +#define TS_WAITKEY 0 +#define TS_SELECTMODE 1 + +// Game modes +#define GM_EASY 0 +#define GM_NORM 1 + // Level states #define LV_INIT 5 // just loaded, waiting for monsters to appear #define LV_INPROGRESS 0 // regular game play @@ -766,6 +775,7 @@ extern level_t *curlevel; extern tiletype_t fakeblock; extern int gtime; extern int timer; +extern int gamemode; extern SDL_Color red; extern SDL_Color black; extern SDL_Color blue; diff --git a/globals.h b/globals.h index 140db6d..a01f868 100644 --- a/globals.h +++ b/globals.h @@ -9,6 +9,8 @@ int numlevels; int maxlevid; +int gamemode; // easy or hard? + spriteinfo_t spriteinfo[MAXPTYPES]; char *datadir; diff --git a/rc.c b/rc.c index da4a438..6e1b36a 100644 --- a/rc.c +++ b/rc.c @@ -105,6 +105,7 @@ int pokerpoints; SDL_Color red = {255, 0, 0, 0}; +SDL_Color red2 = {150, 0, 0, 0}; SDL_Color orange = {255, 167, 88, 1}; SDL_Color black = {0, 0, 0, 0}; SDL_Color blue = {0, 0, 255, 0}; @@ -842,7 +843,7 @@ void nextlevel(void) { drawlevel(); // now the player gets invincibility - player->invuln = INVULNTIME; + makeinvuln(player); // phone is cancelled on boss levels if (player->powerup == PW_PHONE) { @@ -1048,7 +1049,7 @@ void die(sprite_t *s) { player->armour = B_FALSE; player->id = P_PLAYER; // become invulnerable temporarily - player->invuln = INVULNTIME; + makeinvuln(player); // bounce back player->recoiling = B_TRUE; jump(player, -player->dir); @@ -1064,7 +1065,7 @@ void die(sprite_t *s) { } player->powerup = B_FALSE; - nexthurryup = gtime + level->hurryuptime; + resethurryup(curlevel); if (curmusic == fastmusic) { playmusic(normalmusic); } @@ -2804,7 +2805,7 @@ if (s->id == P_PUFF) printf("PUFF WITH DOOMCOUNT!\n"); if (s->size <= 0.2) { s->dead = D_FINAL; /* reset hurryup timer */ - nexthurryup = gtime + level->hurryuptime; + resethurryup(curlevel); } else { SDL_Surface *ts, *cloudim; //printf("shrink\n"); @@ -5613,7 +5614,7 @@ void checksprites(void) { setdefaults(s); s->x = (curlevel->p1x * TILEW) + (TILEW/2); s->y = (curlevel->p1y * TILEH) + (TILEH/2); - s->invuln = INVULNTIME; + makeinvuln(player); } else { if (levelcomplete != LV_GAMEOVER) { // special type - when it expires, gameover timer will start @@ -7052,12 +7053,15 @@ void docannoneffect(void) { void dotitlescreen(void) { char temps[BUFLEN]; SDL_Surface *titlebg; - SDL_Surface *text, *texts; + SDL_Surface *text, *text2, *easy, *norm; SDL_Event event; int done; int timer = 0; int i; int texton = B_TRUE; + int titlemode; + int blinkspeed; + int thiskey; // load title screen @@ -7070,37 +7074,56 @@ void dotitlescreen(void) { // set up text text = TTF_RenderText_Solid(font[TEXTSIZE_TITLE], "Press any key to start", red); - texts = TTF_RenderText_Solid(font[TEXTSIZE_TITLE], "Press any key to start", black); + text2 = TTF_RenderText_Solid(font[TEXTSIZE_TITLE], "Select game mode:", red); + easy = TTF_RenderText_Solid(font[TEXTSIZE_TITLE], "Easy Mode", red2); + norm = TTF_RenderText_Solid(font[TEXTSIZE_TITLE], "Normal Mode", red2); + titlemode = TS_WAITKEY; + gamemode = GM_NORM; // default + + blinkspeed = 20; // wait for keypress done = B_FALSE; while (!done) { - SDL_PollEvent(&event); - switch (event.type) { - case SDL_JOYAXISMOTION: - joyx = SDL_JoystickGetAxis(joy,0); - joyy = SDL_JoystickGetAxis(joy,1); - for (i = 0; i < 20; i++) { - joybut[i] = SDL_JoystickGetButton(joy,i); - if (joybut[i]) printf("button %d down\n",i); - } + if (SDL_PollEvent(&event)) { + switch (event.type) { + case SDL_JOYAXISMOTION: + joyx = SDL_JoystickGetAxis(joy,0); + joyy = SDL_JoystickGetAxis(joy,1); + for (i = 0; i < 20; i++) { + joybut[i] = SDL_JoystickGetButton(joy,i); + if (joybut[i]) printf("button %d down\n",i); + } - //printf("joystick coords are: %d,%d button0=%d, button1=%d\n",joyx,joyy,joybut[0],joybut[1]); - - break; - case SDL_KEYDOWN: - keys = SDL_GetKeyState(NULL); - if (keys[SDLK_ESCAPE]) { - // quit - exit(0); - } else { - done = B_TRUE; - } - break; + //printf("joystick coords are: %d,%d button0=%d, button1=%d\n",joyx,joyy,joybut[0],joybut[1]); + + break; + case SDL_KEYUP: + //keys = SDL_GetKeyState(NULL); + thiskey = event.key.keysym.sym; + if (thiskey == SDLK_ESCAPE) { + // quit + exit(0); + } + if (titlemode == TS_WAITKEY) { + titlemode = TS_SELECTMODE; + blinkspeed = 5; + } else if (titlemode == TS_SELECTMODE) { + // pick current mode + if (thiskey == SDLK_UP) { + gamemode = GM_EASY; + } else if (thiskey == SDLK_DOWN) { + gamemode = GM_NORM; + } else if (thiskey == SDLK_z) { + done = B_TRUE; + } + } + break; + } } - if (++timer == 20) { + if (++timer >= blinkspeed) { // reset timer timer = 0; // blink text @@ -7116,14 +7139,85 @@ void dotitlescreen(void) { // draw screen SDL_BlitSurface(titlebg, NULL, screen, NULL); // draw text - if (texton) { + if (titlemode == TS_WAITKEY) { SDL_Rect area; - area.x = 320 - (texts->w/2)+2; - area.y = 240 - (texts->h/2)+2; - SDL_BlitSurface(texts, NULL, screen, &area); - area.x = 320 - (text->w/2); - area.y = 240 - (text->h/2); - SDL_BlitSurface(text, NULL, screen, &area); + if (texton) { + area.x = 320 - (text->w/2)+2; + area.y = 240 - (text->h/2)+2; + SDL_SetColors(text, &black, 1, 1); + SDL_BlitSurface(text, NULL, screen, &area); + + area.x -= 2; + area.y -= 2; + SDL_SetColors(text, &red, 1, 1); + SDL_BlitSurface(text, NULL, screen, &area); + } + } else if (titlemode == TS_SELECTMODE) { + SDL_Rect area; + SDL_Surface *desc; + // "select mode" + area.x = 320 - (text2->w/2)+2; + area.y = 240 - (text2->h*3)+2; + SDL_SetColors(text2, &black, 1, 1); + SDL_BlitSurface(text2, NULL, screen, &area); + + area.x -=2 ; area.y -= 2; + SDL_SetColors(text2, &red, 1, 1); + SDL_BlitSurface(text2, NULL, screen, &area); + + // "easy" + area.x = 320 - (easy->w/2)+2; + area.y = 240 - (easy->h)+2; + SDL_SetColors(easy, &black, 1, 1); + SDL_BlitSurface(easy, NULL, screen, &area); + + area.x -= 2; area.y -= 2; + if ((gamemode == GM_NORM) || (texton)) { // easy not blinking + // normal + SDL_SetColors(easy, &red2, 1, 1); + } else { + // white + SDL_SetColors(easy, &white, 1, 1); + } + SDL_BlitSurface(easy, NULL, screen, &area); + + // "normal" + area.x = 320 - (norm->w/2)+2; + area.y = 240 +2; + SDL_SetColors(norm, &black, 1, 1); + SDL_BlitSurface(norm, NULL, screen, &area); + + area.x -= 2; area.y -= 2; + if ((gamemode == GM_EASY) || (texton)) { // easy not blinking + // normal + SDL_SetColors(norm, &red2, 1, 1); + } else { + // white + SDL_SetColors(norm, &white, 1, 1); + } + SDL_BlitSurface(norm, NULL, screen, &area); + + // level description + if (gamemode == GM_EASY) { + int x,y; + int startx,starty; + + desc = TTF_RenderText_Solid(font[TEXTSIZE_TITLE2], "More lives, extended time limit", black); + startx = 320 - (desc->w/2); + starty = 240 + (desc->h)*3; + for (x = startx-1 ; x <= startx+1; x++) { + for (y = starty-1 ; y <= starty+1; y++) { + area.x = x; area.y = y; + SDL_BlitSurface(desc, NULL, screen, &area); + } + } + + area.x = startx; + area.y = starty; + SDL_SetColors(desc, &green, 1, 1); + SDL_BlitSurface(desc, NULL, screen, &area); + SDL_FreeSurface(desc); + } } @@ -7131,6 +7225,12 @@ void dotitlescreen(void) { } // clear screen to black //SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); + + // free temp surfaces + SDL_FreeSurface(text ); + SDL_FreeSurface(text2 ); + SDL_FreeSurface(easy ); + SDL_FreeSurface(norm ); } void startgame(void) { @@ -7186,9 +7286,13 @@ void startgame(void) { } // more initial variables - player->invuln = INVULNTIME; + makeinvuln(player); player->score = 0; - player->lives = 3; + if (gamemode == GM_EASY) { + player->lives = 6; + } else { + player->lives = 3; + } forcegoodcard = B_FALSE; nextforcegoodcard = B_FALSE; @@ -7212,3 +7316,11 @@ void uncatch(sprite_t *s) { s->caughtby = NULL; s->caughtstate = B_FALSE; } + +void makeinvuln(sprite_t *s) { + if ((s == player) && (gamemode == GM_EASY)) { + s->invuln = INVULNTIME*2; + } else { + s->invuln = INVULNTIME; + } +} diff --git a/rc.h b/rc.h index af8e05a..03aa449 100644 --- a/rc.h +++ b/rc.h @@ -82,3 +82,4 @@ void docannoneffect(void); void dotitlescreen(void); void startgame(void); void uncatch(sprite_t *s); +void makeinvuln(sprite_t *s); diff --git a/shared.c b/shared.c index 1d2024f..ffb06f2 100644 --- a/shared.c +++ b/shared.c @@ -403,8 +403,6 @@ int loadlevel(int wnum, int lnum, int wantmonsters) { tempanim[numanim] = y*LEVELW+x; numanim++; } - if (y*LEVELW+x == 800) printf("tileframe of 800 is %d\n",level->tileframe[y*LEVELW+x]); - x++; p = strtok(NULL, ","); @@ -523,6 +521,8 @@ int loadlevel(int wnum, int lnum, int wantmonsters) { int delay; if (level->initm[i].id == P_HELP) { + // TODO: want this??? unless in easy mode, these aren't shown + //if (gamemode != GM_EASY) continue; strncpy(name, level->initm[i].help, MIDBUFLEN); } else { sprintf(name, "Monster-%d",i); @@ -545,7 +545,7 @@ int loadlevel(int wnum, int lnum, int wantmonsters) { } gtime = 0; - nexthurryup = level->hurryuptime; + resethurryup(level); boss = NULL; mask = NULL; @@ -3228,3 +3228,10 @@ void drawplayer(sprite_t *s, SDL_Rect *where) { } #endif } + +void resethurryup(level_t *lev) { + nexthurryup = gtime + lev->hurryuptime; + if (gamemode == GM_EASY) { + nexthurryup += 15; + } +} diff --git a/shared.h b/shared.h index 4b847b5..353238c 100644 --- a/shared.h +++ b/shared.h @@ -61,6 +61,7 @@ int getcardsuit(int cardid); int getworld(int lev); int getlevel(int lev); void drawplayer(sprite_t *s, SDL_Rect *where); +void resethurryup(level_t *lev); // for doco void setfruitinfo(void); void setinfo(int id, char *name, char *desc, char *file);