From cdf82e72e6f9b8ca4cb289347cb6a6d7883bae26 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Sat, 18 Oct 2008 03:18:24 +0000 Subject: [PATCH] - Game now drops to title screen after game over - Fixed freeze bug if you got luckiness without having any cards - Luckiness is now done via the 4-leaf clover object, and visually displayed by flashing the score --- data/sprites/clover.png | Bin 0 -> 1083 bytes data/world1/level107.dat | 8 +- defs.h | 10 +- rc.c | 871 +++++++++++++++++++++------------------ rc.h | 1 + shared.c | 13 +- 6 files changed, 503 insertions(+), 400 deletions(-) create mode 100644 data/sprites/clover.png diff --git a/data/sprites/clover.png b/data/sprites/clover.png new file mode 100644 index 0000000000000000000000000000000000000000..5c3e8e3560f04f6cbae415c1363e3f0b9f7a7a37 GIT binary patch literal 1083 zcmV-B1jPG^P)tv65BLQEv*Gzhy`6(wJmPkhzs55x+`6| za4jN&f}k6*7IagnAP5x;Vyq|xwbj;sH+@NLlK1lFy?HZp=YF_J!LvG>^ZV@%!~gR9 zD~GqMo!P6Q62lk_efHIdmzH0D=ZU9zQoJpM@IF`P*RKU<&V6w)f4E@}%S&$_I9RCF zGkgehaU2DTlFRk}^og>0Ytc)+U6BNgg2|#EvpdPDvmbxo1poqoXHFcIwy|dzAiCn#Wn3?U_(EX3gC^z6j9SAT7FY2SfK(Rg(8T^*#yD3l{{ zTvL$>5UCn;i4STCdod0|7P1fkA+9wLL~hJ0eSCKB?3aA<2pzZe^tGrin=;@6))a~< zC{}~d!WkIm1rHI*5K@M)FbI_d#day?z&XOQoNlAf+adD)`F-B>bdBzyfjXHXijToDo2jzBTD$ePU0T1v)>>EGN#5H8{0M^ zc8?zn9^bt`ncZBniwwXEkL+zcyYr}hIUYq*HK-DVk`mCm7c?sc_JT9Cp1x`OfDAU{@$Yikj|_b>JKhxwbBC zo61^;{c$XFPIjf!HI=hW7lqRsyuWyE@X5w%c837$=&Y66rfQ%POc`zkCnh*&T=bHn zR`POw&$zmI&kS^4q1X`pYZuBN)|RvT0J;QV7l7fcTT$9#UF4x4C#hTuvMU$+_kOz6 zelWK$7=CJgPyFe7H-5SMdv-fZbsInmpu+$h0Wbw%2EYV>CV&Kh0w4fz0Q{r(4<9o& z%1^)b^LGFq0Jsg{9|52OPy)yS3;;x1KVh~21b}D#QU`$*L_D?DwE?sNY|@r31Q2Z5 z{1&v>f))VE3m4ZfKQ>=)-d!?(roHkGfEIw2{{Rkr*Tg002ovPDHLkV1guw B= 0) { - for (i = 0; i < numlevels; i++) { - if (levelentry[i].id == skipto) { - curlevelnum = i; - } - } - } /* fakeblock.id = T_LAND; @@ -242,409 +233,401 @@ int main (int argc, char **argv) { exit(1); } - shufflecards(); - - - // title screen - dotitlescreen(); - - - // load initial level - playmusic(normalmusic); - - if (loadlevel(curworld,curlevelnum, B_TRUE)) { - return 1; - } - - //levelcomplete = LV_FINAL; - curlevelnum-- ; // since nexlevel() will increment it - nextlevel(); - //drawlevel(); - flip(); - - timer = 0; - - player->invuln = INVULNTIME; - player->score = 0; - player->lives = 3; - forcegoodcard = B_FALSE; - nextforcegoodcard = B_FALSE; - - - /* generate images for "PAUSED" text */ pausedtext = TTF_RenderText_Solid(font[TEXTSIZE_PAUSED], "PAUSED", yellow); pausedshadow = TTF_RenderText_Solid(font[TEXTSIZE_PAUSED], "PAUSED", black); paused = B_FALSE; - // main loop - while (1) { - removeall(); - // check for sprite death and update moevment counters - checksprites(); - - /********************************************** - * check for end of level - */ - if (levelcomplete == LV_CLEAR) { - addoutlinetext(320,240,TEXTSIZE_LEVEL,"Level Complete!",&green,&black,LEVELWINDELAY, TT_NORM); - levelcomplete = LV_WAIT; - playfx(FX_WINLEVEL); - // turn off clock and water powerups - if (player->powerup == PW_CLOCK) { - Mix_ResumeMusic(); - player->powerup = B_FALSE; - } else if ((curlevel->iced == WATER_INPROGRESS) || (curlevel->iced == WATER_COMPLETE)) { - curlevel->iced = B_FALSE; - undoflood(); - } - } else if (levelcomplete == LV_WAIT) { - int mcount = 0; - sprite_t *s2; - - /* when all monsters have become fruits */ - for (s2 = sprite->next ; s2 ; s2 = s2->next) { - if (ismonster(s2->id)) { - if (s2->id != P_BLACKCLOUD) { - mcount++; - break; - } - } - } - if (mcount == 0) { - levelcompletetime = gtime; - levelcomplete = LV_FINAL; - } - } - - /********************************************** - * check for keypress or other input (joystick etc) - */ - handleinput(); + // outside loop + while (1) { + // title screen + if (!skipto) { + dotitlescreen(); + } + + // shuffle cards + shufflecards(); + + startgame(); + + // main loop + while (!gameover) { + removeall(); + + // check for sprite death and update moevment counters + checksprites(); - if (!paused) { /********************************************** - * Special effects #1 - ones which change the level by - * modifiying tiles, etc. + * check for end of level */ - if (player->powerup != PW_CLOCK) { - // for each animated tile on the level... - for (animtile = curlevel->animtiles; animtile && *animtile != -1; animtile++) { - int offset,numframes; - tiletype_t *tt; + if (levelcomplete == LV_CLEAR) { + addoutlinetext(320,240,TEXTSIZE_LEVEL,"Level Complete!",&green,&black,LEVELWINDELAY, TT_NORM); + levelcomplete = LV_WAIT; + playfx(FX_WINLEVEL); + // turn off clock and water powerups + if (player->powerup == PW_CLOCK) { + Mix_ResumeMusic(); + player->powerup = B_FALSE; + } else if ((curlevel->iced == WATER_INPROGRESS) || (curlevel->iced == WATER_COMPLETE)) { + curlevel->iced = B_FALSE; + undoflood(); + } + } else if (levelcomplete == LV_WAIT) { + int mcount = 0; + sprite_t *s2; - offset = *animtile; - - tt = gettile(curlevel->map[offset]); - - numframes = tt->numframes; - - // is it time to change frames? - if ((timer % tt->animspeed) == 0) { - // change its frame - curlevel->tileframe[offset]++; - if (curlevel->tileframe[offset] >= numframes) { - curlevel->tileframe[offset] = 0; + /* when all monsters have become fruits */ + for (s2 = sprite->next ; s2 ; s2 = s2->next) { + if (ismonster(s2->id)) { + if (s2->id != P_BLACKCLOUD) { + mcount++; + break; } - // redraw it - drawtile(temps, offset%LEVELW,offset/LEVELW); + } + } + if (mcount == 0) { + levelcompletetime = gtime; + levelcomplete = LV_FINAL; + } + } + + + /********************************************** + * check for keypress or other input (joystick etc) + */ + handleinput(); + + if (!paused) { + /********************************************** + * Special effects #1 - ones which change the level by + * modifiying tiles, etc. + */ + if (player->powerup != PW_CLOCK) { + // for each animated tile on the level... + for (animtile = curlevel->animtiles; animtile && *animtile != -1; animtile++) { + int offset,numframes; + tiletype_t *tt; + + offset = *animtile; + + tt = gettile(curlevel->map[offset]); + + numframes = tt->numframes; + + // is it time to change frames? + if ((timer % tt->animspeed) == 0) { + // change its frame + curlevel->tileframe[offset]++; + if (curlevel->tileframe[offset] >= numframes) { + curlevel->tileframe[offset] = 0; + } + // redraw it + drawtile(temps, offset%LEVELW,offset/LEVELW); + } + } - } - - // ice effect - if (curlevel->iced == ICE_INPROGRESS) { - doice(); - } - - // water effect - if (timer % FLOODSPEED == 0) { - if (curlevel->iced == WATER_INPROGRESS) { - doflood(); + // ice effect + if (curlevel->iced == ICE_INPROGRESS) { + doice(); } + + // water effect + if (timer % FLOODSPEED == 0) { + if (curlevel->iced == WATER_INPROGRESS) { + doflood(); + } + } + } + + /********************************************** + * Move sprites + */ + if (levelcomplete == LV_DOPOKER) { + // only fivecards sprite can move + sprite_t *this; + for (this = sprite; this ; this = this->next) { + if (this->id == P_FIVECARDS) { + movesprite(this); + } + } + } else { // all other states... + if (levelcomplete != LV_HELPFREEZE) { + // move sprites + moveallsprites(); + } + } + + /********************************************** + * Move onscreen text + */ + if (levelcomplete != LV_HELPFREEZE) { + movetext(); + } + + + /********************************************** + * Gravity + */ + if (levelcomplete == LV_INIT) { + // only player + dogravity(player); + checkwrap(player); + dotileeffects(player); + } else { + sprite_t *s; + switch (levelcomplete) { + case LV_INPROGRESS: + case LV_CLEAR: + case LV_WAIT: + case LV_FINAL: + case LV_CLOUD: + /* gravity */ + for (s = sprite ; s ; s = s->next) { + dogravity(s); + checkwrap(s); + } + + /* tile effects */ + for (s = sprite ; s ; s = s->next) { + dotileeffects(s); + } + break; + case LV_GAMEOVER: // no collision detection or player movement + /* gravity */ + for (s = sprite->next ; s ; s = s->next) { + dogravity(s); + checkwrap(s); + } + break; + case LV_DOPOKER: // do nothing + case LV_HELPFREEZE: // do nothing + break; + } + } + + /********************************************** + * Special effects #2 - ones which need to happen + * after sprite movement + */ + if (player->hasbell) { + /* check for bell sound */ + + /* play a bell sound if the powerup will be a permenant one */ + if (ispermenant(level->poweruptype)) { + // play sound once + if (!playedbell) { + playfx(FX_BELL); + playedbell = BELL_DONESOUND; + } + if (playedbell != BELL_DONEFLASH) { + if (timer >= BELLTIME) { + playedbell = BELL_DONEFLASH; + } else if (timer % 10 == 0) { + SDL_Rect area; + area.x = 0; + area.y = 0; + area.w = 640; + area.h = 480; + SDL_FillRect(screen, &area, SDL_MapRGB(screen->format,white.r,white.g,white.b)); + flip(); + } + } + } + } + + /********************************************** + * Collision detection + */ + if ((levelcomplete != LV_DOPOKER) && (levelcomplete != LV_HELPFREEZE)) { + checkcollideall(); } } + + /********************************************** - * Move sprites + * Drawing routines */ + + // player netting + if ((levelcomplete != LV_DOPOKER) && (levelcomplete != LV_HELPFREEZE)) { + drawnetting(player); + } + + // cannon firing + if ((levelcomplete != LV_DOPOKER) && (levelcomplete != LV_HELPFREEZE) && (player->powerup == PW_CANNONFIRE)) { // cannon firing + docannoneffect(); + } + + + // draw sprites + if ((levelcomplete != LV_DOPOKER) && (levelcomplete != LV_HELPFREEZE)) { + drawallsprites(); + } + + + + // poker effect + // this must come last as it clears the screen and blanks out other sprites if (levelcomplete == LV_DOPOKER) { - // only fivecards sprite can move + SDL_Rect area; sprite_t *this; + + area.x = 0; + area.y = 0; + area.w = 640; + area.h = 480; + // clear screen + SDL_FillRect(screen, &area, SDL_MapRGB(screen->format,black.r,black.g,black.b)); + + // only fivecards sprite is drawn for (this = sprite; this ; this = this->next) { if (this->id == P_FIVECARDS) { - movesprite(this); + drawsprite(this); } } - } else { // all other states... - if (levelcomplete != LV_HELPFREEZE) { - // move sprites - moveallsprites(); - } + } else if (levelcomplete == LV_HELPFREEZE) { + SDL_Rect area; + + area.x = 0; + area.y = 0; + area.w = 640; + area.h = 480; + // clear screen + SDL_FillRect(screen, &area, SDL_MapRGB(screen->format,black.r,black.g,black.b)); + } + + // draw text + drawtext(); + + // draw score + drawscore(); + + // draw boss health + if (boss) { + drawbosshealth(); + } + + + // draw 'PAUSED' text + if (paused) { + SDL_Rect area; + // show that we are paused + area.x = (640/2) - (pausedshadow->w/2) - 2; + area.y = (480/2) - (pausedshadow->h/2) + 2; + area.w = 0; + area.h = 0; + SDL_BlitSurface(pausedshadow, NULL, screen, &area); + area.x = (640/2) - (pausedtext->w/2); + area.y = (480/2) - (pausedtext->h/2); + area.w = 0; + area.h = 0; + SDL_BlitSurface(pausedtext, NULL, screen, &area); } /********************************************** - * Move onscreen text + * Special effects #3 - ones which need to happen + * after graphics drawing */ - if (levelcomplete != LV_HELPFREEZE) { - movetext(); - } + if (!paused) { + /* is screen shaking? */ + if (player->powerup == PW_BOMB) { + if (timer % 5 == 0) { + int amt; + SDL_Rect area; + amt = (rand() % 20)+1; + area.x = 0; + area.y = amt; + area.w = 640; + area.h = 480-amt; - - /********************************************** - * Gravity - */ - if (levelcomplete == LV_INIT) { - // only player - dogravity(player); - checkwrap(player); - dotileeffects(player); - } else { - sprite_t *s; - switch (levelcomplete) { - case LV_INPROGRESS: - case LV_CLEAR: - case LV_WAIT: - case LV_FINAL: - case LV_CLOUD: - /* gravity */ - for (s = sprite ; s ; s = s->next) { - dogravity(s); - checkwrap(s); - } + SDL_BlitSurface(screen, &area, screen, NULL); - /* tile effects */ - for (s = sprite ; s ; s = s->next) { - dotileeffects(s); + area.x = 0; + area.y = 480-amt; + area.w = 640; + area.h = amt; + SDL_FillRect(screen, &area, SDL_MapRGB(screen->format,black.r,black.g,black.b)); + } + + if (--player->timer1 == 0) { + player->powerup = B_FALSE; + } + } else if (player->powerup == PW_SPRAYUP) { // green overlay for fly spray + SDL_SetAlpha(greenbox, SDL_SRCALPHA, sprayalpha); + sprayalpha += 5; + if (sprayalpha >= 100) { + player->powerup = PW_SPRAYDOWN; + } + SDL_BlitSurface(greenbox,NULL,screen,NULL); + } else if (player->powerup == PW_SPRAYDOWN) { // green overlay for fly spray + SDL_SetAlpha(greenbox, SDL_SRCALPHA, sprayalpha); + sprayalpha -= 5; + if (sprayalpha <= 0) { + player->powerup = PW_SPRAYUP; + } + SDL_BlitSurface(greenbox,NULL,screen,NULL); + } else if (player->powerup == PW_RATSHAKE) { // horizontal shake due to rat + // shake screen + if (timer % 5 == 0) { + int amt; + SDL_Rect area; + amt = (rand() % 20)+1; + area.x = amt; + area.y = 0; + area.w = 640-amt; + area.h = 480; + + SDL_BlitSurface(screen, &area, screen, NULL); + + area.x = 640-amt; + area.y = 0; + area.w = amt; + area.h = 480; + SDL_FillRect(screen, &area, SDL_MapRGB(screen->format,black.r,black.g,black.b)); + } + + + // create rat + if (timer % 10 == 0) { + if (countmonsters() < 8) { // max 7 rats + king rat + puffin(P_RAT, rand() % (640-(TILEW*8))+(TILEW*4), TILEH, "gen_rat",0); } - break; - case LV_GAMEOVER: // no collision detection or player movement - /* gravity */ - for (s = sprite->next ; s ; s = s->next) { - dogravity(s); - checkwrap(s); - } - break; - case LV_DOPOKER: // do nothing - case LV_HELPFREEZE: // do nothing - break; + } + + + if (--player->timer1 == 0) { + player->powerup = B_FALSE; + } } + } /********************************************** - * Special effects #2 - ones which need to happen - * after sprite movement + * Update the screen */ - if (player->hasbell) { - /* check for bell sound */ + flip(); - /* play a bell sound if the powerup will be a permenant one */ - if (ispermenant(level->poweruptype)) { - // play sound once - if (!playedbell) { - playfx(FX_BELL); - playedbell = BELL_DONESOUND; - } - if (playedbell != BELL_DONEFLASH) { - if (timer >= BELLTIME) { - playedbell = BELL_DONEFLASH; - } else if (timer % 10 == 0) { - SDL_Rect area; - area.x = 0; - area.y = 0; - area.w = 640; - area.h = 480; - SDL_FillRect(screen, &area, SDL_MapRGB(screen->format,white.r,white.g,white.b)); - flip(); - } - } - } + if (!paused) { + if (++timer == 100) timer = 0; } - /********************************************** - * Collision detection - */ - if ((levelcomplete != LV_DOPOKER) && (levelcomplete != LV_HELPFREEZE)) { - checkcollideall(); - } - } + if (toggletimer > 0) toggletimer--; + tick(); + } // end main loop + // TODO: fade - /********************************************** - * Drawing routines - */ + // TODO: high scores - // player netting - if ((levelcomplete != LV_DOPOKER) && (levelcomplete != LV_HELPFREEZE)) { - drawnetting(player); - } - - // cannon firing - if ((levelcomplete != LV_DOPOKER) && (levelcomplete != LV_HELPFREEZE) && (player->powerup == PW_CANNONFIRE)) { // cannon firing - docannoneffect(); - } - - - // draw sprites - if ((levelcomplete != LV_DOPOKER) && (levelcomplete != LV_HELPFREEZE)) { - drawallsprites(); - } - - - - // poker effect - // this must come last as it clears the screen and blanks out other sprites - if (levelcomplete == LV_DOPOKER) { - SDL_Rect area; - sprite_t *this; - - area.x = 0; - area.y = 0; - area.w = 640; - area.h = 480; - // clear screen - SDL_FillRect(screen, &area, SDL_MapRGB(screen->format,black.r,black.g,black.b)); - - // only fivecards sprite is drawn - for (this = sprite; this ; this = this->next) { - if (this->id == P_FIVECARDS) { - drawsprite(this); - } - } - } else if (levelcomplete == LV_HELPFREEZE) { - SDL_Rect area; - - area.x = 0; - area.y = 0; - area.w = 640; - area.h = 480; - // clear screen - SDL_FillRect(screen, &area, SDL_MapRGB(screen->format,black.r,black.g,black.b)); - } - - // draw text - drawtext(); - - // draw score - drawscore(); - - // draw boss health - if (boss) { - drawbosshealth(); - } - - - // draw 'PAUSED' text - if (paused) { - SDL_Rect area; - // show that we are paused - area.x = (640/2) - (pausedshadow->w/2) - 2; - area.y = (480/2) - (pausedshadow->h/2) + 2; - area.w = 0; - area.h = 0; - SDL_BlitSurface(pausedshadow, NULL, screen, &area); - area.x = (640/2) - (pausedtext->w/2); - area.y = (480/2) - (pausedtext->h/2); - area.w = 0; - area.h = 0; - SDL_BlitSurface(pausedtext, NULL, screen, &area); - } - - /********************************************** - * Special effects #3 - ones which need to happen - * after graphics drawing - */ - if (!paused) { - /* is screen shaking? */ - if (player->powerup == PW_BOMB) { - if (timer % 5 == 0) { - int amt; - SDL_Rect area; - amt = (rand() % 20)+1; - area.x = 0; - area.y = amt; - area.w = 640; - area.h = 480-amt; - - SDL_BlitSurface(screen, &area, screen, NULL); - - area.x = 0; - area.y = 480-amt; - area.w = 640; - area.h = amt; - SDL_FillRect(screen, &area, SDL_MapRGB(screen->format,black.r,black.g,black.b)); - } - - if (--player->timer1 == 0) { - player->powerup = B_FALSE; - } - } else if (player->powerup == PW_SPRAYUP) { // green overlay for fly spray - SDL_SetAlpha(greenbox, SDL_SRCALPHA, sprayalpha); - sprayalpha += 5; - if (sprayalpha >= 100) { - player->powerup = PW_SPRAYDOWN; - } - SDL_BlitSurface(greenbox,NULL,screen,NULL); - } else if (player->powerup == PW_SPRAYDOWN) { // green overlay for fly spray - SDL_SetAlpha(greenbox, SDL_SRCALPHA, sprayalpha); - sprayalpha -= 5; - if (sprayalpha <= 0) { - player->powerup = PW_SPRAYUP; - } - SDL_BlitSurface(greenbox,NULL,screen,NULL); - } else if (player->powerup == PW_RATSHAKE) { // horizontal shake due to rat - // shake screen - if (timer % 5 == 0) { - int amt; - SDL_Rect area; - amt = (rand() % 20)+1; - area.x = amt; - area.y = 0; - area.w = 640-amt; - area.h = 480; - - SDL_BlitSurface(screen, &area, screen, NULL); - - area.x = 640-amt; - area.y = 0; - area.w = amt; - area.h = 480; - SDL_FillRect(screen, &area, SDL_MapRGB(screen->format,black.r,black.g,black.b)); - } - - - // create rat - if (timer % 10 == 0) { - if (countmonsters() < 8) { // max 7 rats + king rat - puffin(P_RAT, rand() % (640-(TILEW*8))+(TILEW*4), TILEH, "gen_rat",0); - } - } - - - if (--player->timer1 == 0) { - player->powerup = B_FALSE; - } - } - - } - - /********************************************** - * Update the screen - */ - flip(); - - if (!paused) { - if (++timer == 100) timer = 0; - } - - if (toggletimer > 0) toggletimer--; - - tick(); - } + // clear screen ready to start again... + SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format,black.r,black.g,black.b)); + } // end outside loop return 0; @@ -666,6 +649,13 @@ void tick(void) { if (fpsticks - fpsstart >= 1000) { gtime++; + // check for game over - 5 seocnds after game over text disappears + if (gameovertime > 0) { + if (gtime >= (gameovertime + GAMEOVERWAIT)) { + gameover = B_TRUE; + } + } + // handle clock effect if (levelcomplete == LV_INPROGRESS) { if (player->powerup == PW_CLOCK) { @@ -3427,6 +3417,10 @@ void movetext(void) { } else if (t->state == t->delay) { t->size -= TEXTSPEED; if (t->size <= 3) { + if ((t->type == TT_GAMEOVER) && (levelcomplete == LV_GAMEOVER)) { + // start game over timer + gameovertime = gtime; + } killtext(t); } @@ -3480,8 +3474,19 @@ void drawbosshealth(void) { void drawscore(void) { SDL_Surface *score; SDL_Rect area; + SDL_Color scorecol; int i; + if (forcegoodcard) { + if ((timer / LUCKYFLASH) % 2 == 0) { + scorecol = green; + } else { + scorecol = red; + } + } else { + scorecol = red; + } + addcommas(tempm, player->score); /* shadow */ @@ -3493,7 +3498,7 @@ void drawscore(void) { SDL_BlitSurface(score, NULL, screen, &area); SDL_FreeSurface(score); /* score */ - score = TTF_RenderText_Solid(font[TEXTSIZE_SCORE], tempm, red); + score = TTF_RenderText_Solid(font[TEXTSIZE_SCORE], tempm, scorecol); area.x = 20; area.y = 5; area.w = 0; @@ -4218,6 +4223,7 @@ void dogravity(sprite_t *s) { int pointsinc = 250; int psize = 6; int gotsomething = B_FALSE; + int gotclover = B_FALSE; int hitboss = B_FALSE; int macex,macey; int numcaught = 0; @@ -4304,6 +4310,11 @@ void dogravity(sprite_t *s) { pointsinc *= 2; psize += 10; gotsomething++; + // killing 5 at a time gives us a clover for good luck + if ((!gotclover) && (gotsomething >= 5)) { + puffin(P_CLOVER, s2->x, s2->y, "clover", 0); + gotclover = B_TRUE; + } } xnet = s2->x; ynet = s2->y - s2->img->h/2; @@ -4444,6 +4455,11 @@ void dogravity(sprite_t *s) { pointsinc *= 2; psize += 10; gotsomething++; + // killing 5 at a time gives us a clover for good luck + if ((!gotclover) && (gotsomething >= 5)) { + puffin(P_CLOVER, s2->x, s2->y, "clover", 0); + gotclover = B_TRUE; + } } } } @@ -4462,11 +4478,6 @@ void dogravity(sprite_t *s) { } } - // killing 5 at a time gives us a bonus on the next level... - if (gotsomething >= 5) { - nextforcegoodcard = B_TRUE; - forcegoodcard = B_TRUE; // and on this level if we get one... - } gotsomething = B_FALSE; @@ -4962,10 +4973,15 @@ int dofruiteffect(sprite_t *s) { playfx(FX_POWERUP); sprintf(tempm, "Shield!"); addoutlinetext(s->x,s->y - s->img->h/2, TEXTSIZE_POINTS, tempm,&white,&black,POINTSDELAY, TT_NORM); - // temp invincibility player->invuln = SHIELDTIME; - + return B_TRUE; + } else if (s->id == P_CLOVER) { + playfx(FX_POWERUP); + sprintf(tempm, "Lucky!"); + addoutlinetext(s->x,s->y - s->img->h/2, TEXTSIZE_CLOVER, tempm,&green2,&black,CLOVERDELAY, TT_NORM); + nextforcegoodcard = B_TRUE; + forcegoodcard = B_TRUE; return B_TRUE; } else if (s->id == P_HELP) { playfx(FX_POWERUP); @@ -5490,12 +5506,9 @@ void checksprites(void) { s->y = (curlevel->p1y * TILEH) + (TILEH/2); s->invuln = INVULNTIME; } else { - if (levelcomplete == LV_GAMEOVER) { - // TODO: Wait until "game over" text is gone, then slowly fade out the screen - // then show hiscores - // then back to title screen - } else { - addoutlinetext(320,240,TEXTSIZE_GAMEOVER,"Game Over",&red,&black,GAMEOVERDELAY,TT_NORM); + if (levelcomplete != LV_GAMEOVER) { + // special type - when it expires, gameover timer will start + addoutlinetext(320,240,TEXTSIZE_GAMEOVER,"Game Over",&red,&black,GAMEOVERDELAY,TT_GAMEOVER); levelcomplete = LV_GAMEOVER; stopmusic(); playfx(FX_GAMEOVER); @@ -6968,3 +6981,77 @@ void dotitlescreen(void) { // clear screen to black //SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0)); } + +void startgame(void) { + int i; + + // initial variables + curlevelnum = 1; + curworld = 1; // TODO: REMOVE THIS + musicplaying = B_FALSE; + levelcompletetime = -1; + oldlevelcomplete = -1; + pokereffect = -1; + pokerpoints = 0; + skiplevels = 0; + + + curfruittype = 0; + curpoweruptype = 0; + + fpsticks = 0; + fpsstart = 0; + + // init player variables - if player + // hasn't been allocated yet then this will + // be done so in loadlevel(), and the below + // settings done in addsprite() + if (player) { + int c; + setdefaults(player); + player->permspeed = B_FALSE; + player->permbignet = B_FALSE; + player->permnumnets = B_FALSE; + player->permsticky = B_FALSE; + player->numcards = 0; + for (c = 0; c < MAXCARDS; c++) { + player->card[c] = -1; + player->usedcard[c] = 0; + } + } + + // is we're skipping to a level, do so now + if (skipto >= 0) { + for (i = 0; i < numlevels; i++) { + if (levelentry[i].id == skipto) { + curlevelnum = i; + } + } + } + + // pre-load initial level + if (loadlevel(curworld,curlevelnum, B_TRUE)) { + exit(1); + } + + // more initial variables + player->invuln = INVULNTIME; + player->score = 0; + player->lives = 3; + forcegoodcard = B_FALSE; + nextforcegoodcard = B_FALSE; + + gameover = B_FALSE; + gameovertime = -1; + + gtime = 0; + + curlevelnum-- ; // since nexlevel() will increment it + + // start the first level + nextlevel(); + flip(); + + // start timer + timer = 0; +} diff --git a/rc.h b/rc.h index 04da968..29f96a9 100644 --- a/rc.h +++ b/rc.h @@ -80,3 +80,4 @@ void trytojump(sprite_t *pl); void trytoshoot(sprite_t *pl); void docannoneffect(void); void dotitlescreen(void); +void startgame(void); diff --git a/shared.c b/shared.c index 2f23dfe..3596e63 100644 --- a/shared.c +++ b/shared.c @@ -1268,6 +1268,9 @@ int loadimagesets(void) { loadspriteimage(P_CANNON,F_WALK1, "sprites/cannon.png"); imageset[P_CANNON].numimages = 1; + loadspriteimage(P_CLOVER,F_WALK1, "sprites/clover.png"); + imageset[P_CLOVER].numimages = 1; + loadspriteimage(P_BIGSPEED,F_WALK1, "sprites/bigspeed.png"); imageset[P_BIGSPEED].numimages = 1; @@ -1879,6 +1882,7 @@ int isfruit(int id) { case P_TAP: case P_SPRAY: case P_CANNONPOWERUP: + case P_CLOVER: return FT_TEMP; /* flowers */ case P_FLOWERYELLOW: @@ -2488,7 +2492,7 @@ int loadlevellist(void) { int randompowerup(void) { int num; - num = rand() % 27; + num = rand() % 28; switch (num) { case 0: @@ -2546,6 +2550,8 @@ int randompowerup(void) { return P_MASKPOWERUP; case 26: return getrandomcard(); + case 27: + return P_CLOVER; } } @@ -2674,8 +2680,7 @@ void setfruitinfo(void) { setinfo(P_LIFE, "Life", "Awards the player an extra life.", "extralife.png"); setinfo(P_UFO, "UFO", "Calls in a powerful meteor strike!", "ufo.png"); setinfo(P_TAP, "Tap", "The leaky tap will flood the level with water, allowing you to acces hard to reach areas.", "tap.png"); - - // TODO: add cards here! + setinfo(P_CLOVER, "4-Leaf Clover", "Increases your luck...", "clover.png"); setinfo(P_RAT, "Rat", "The weakest of the monsters, the rat will simply walk back and forth waiting to be caught. Beward an angry rat though, as it will try to fall or jump in order to catch you!", "rat.png"); @@ -2859,7 +2864,7 @@ int getrandomcard(void) { } // are we forcing it to be good? - if (forcegoodcard) { + if ((forcegoodcard) && (player->numcards > 0)) { int okay = B_FALSE; int csuit,cval; for (i = 0; i < player->numcards; i++) {