From 0e26db03c5aca3622a007b607368b250e40b7f2c Mon Sep 17 00:00:00 2001 From: Joshua Grams Date: Sun, 1 May 2005 20:32:55 +0000 Subject: [PATCH] * main.c: removed a whole bunch of unnecessary src rects for SDL blits. added a rudimentary speed indicator (still a bit buggy, avg speed gets stuck way up high sometimes). * rocks.c: added a rock counter to print out how far from our goal we are. --- data/indicators/speed.png | Bin 0 -> 205 bytes main.c | 118 +++++++++++++++++++++++---------------------- rocks.c | 11 ++++- 3 files changed, 69 insertions(+), 60 deletions(-) create mode 100644 data/indicators/speed.png diff --git a/data/indicators/speed.png b/data/indicators/speed.png new file mode 100644 index 0000000000000000000000000000000000000000..e5c996b3c589e38001198c130938ff951d6d5443 GIT binary patch literal 205 zcmeAS@N?(olHy`uVBq!ia0vp^-ayRC!3GkM5&QQK$!8;-MT+OLG}_)Usv|4EOLCBiYG5HzXu9MdAc};RLprh!I7)MfQRLH*9F)A z|Gob@2I(tpRoYT<_Q0gO6P$0XbVy`1t2n!VcbBY%*4Cfd({+`_jVA8>sP@GFe(m#J r^_#aOd|rCX+)}VaIF(lbj0%`m?l+pi_M>SV&=v+yS3j3^P6w; - src.h = surf_ship->h; - dest.w = src.w; - dest.h = src.h; - dest.x = (int)shipx; - dest.y = (int)shipy; - SDL_BlitSurface(surf_ship,&src,surf_screen,&dest); + dest.x = shipx; + dest.y = shipy; + SDL_BlitSurface(surf_ship,NULL,surf_screen,&dest); } draw_rocks(); @@ -519,13 +518,34 @@ draw() { // Draw the life indicators. if(state == GAMEPLAY || state == DEAD_PAUSE || state == GAME_OVER) for(i = 0; iw; - src.h = surf_life->h; - dest.w = src.w; - dest.h = src.h; - dest.x = (i + 1)*(src.w + 10); + dest.x = (i + 1)*(surf_life->w + 10); dest.y = 20; - SDL_BlitSurface(surf_life, &src, surf_screen, &dest); + SDL_BlitSurface(surf_life, NULL, surf_screen, &dest); + } + + if(state == GAMEPLAY) { + // Update speeds. + cur_speed = shipdx; + if(shipdx < 0) cur_speed = 0; + if(shipdx > 20) cur_speed = 20; + game_dist += cur_speed*ticks_since_last; + game_ticks += ticks_since_last; + if(game_ticks < 2*1000) avg_speed = cur_speed; + else avg_speed = game_dist/game_ticks; + // printf("avg=%.2f, cur=%.2f.\n", avg_speed, cur_speed); + avg_speed_w = 10 + 64*avg_speed/20; + cur_speed_w = 10 + 64*cur_speed/20; + } + + if(state == GAMEPLAY || state == DEAD_PAUSE) { + // Draw the speed indicators. + src.x = 0; src.y = 0; + src.h = surf_speed->h; + dest.x = 240; + src.w = avg_speed_w; dest.y = 10; + SDL_BlitSurface(surf_speed, &src, surf_screen, &dest); + src.w = cur_speed_w; dest.y = 20; + SDL_BlitSurface(surf_speed, &src, surf_screen, &dest); } // Draw the score @@ -549,53 +569,33 @@ draw() { fadeover = 1.0; } - src.w = surf_b_game->w; - src.h = surf_b_game->h; - dest.w = src.w; - dest.h = src.h; - dest.x = (XSIZE-src.w)/2; - dest.y = (YSIZE-src.h)/2-40; + dest.x = (XSIZE-surf_b_game->w)/2; + dest.y = (YSIZE-surf_b_game->h)/2-40; SDL_SetAlpha(surf_b_game, SDL_SRCALPHA, (int)(fadegame*(200 + 55*cos(fadetimer += gamerate/1.0)))); - SDL_BlitSurface(surf_b_game,&src,surf_screen,&dest); - - src.w = surf_b_over->w; - src.h = surf_b_over->h; - dest.w = src.w; - dest.h = src.h; - dest.x = (XSIZE-src.w)/2; - dest.y = (YSIZE-src.h)/2 + 40; + SDL_BlitSurface(surf_b_game,NULL,surf_screen,&dest); + + dest.x = (XSIZE-surf_b_over->w)/2; + dest.y = (YSIZE-surf_b_over->h)/2 + 40; SDL_SetAlpha(surf_b_over, SDL_SRCALPHA, (int)(fadeover*(200 + 55*sin(fadetimer)))); - SDL_BlitSurface(surf_b_over,&src,surf_screen,&dest); + SDL_BlitSurface(surf_b_over,NULL,surf_screen,&dest); break; case TITLE_PAGE: - src.w = surf_b_variations->w; - src.h = surf_b_variations->h; - dest.w = src.w; - dest.h = src.h; - dest.x = (XSIZE-src.w)/2 + cos(fadetimer/6.5)*10; - dest.y = (YSIZE/2-src.h)/2 + sin(fadetimer/5.0)*10; + dest.x = (XSIZE-surf_b_variations->w)/2 + cos(fadetimer/6.5)*10; + dest.y = (YSIZE/2-surf_b_variations->h)/2 + sin(fadetimer/5.0)*10; SDL_SetAlpha(surf_b_variations, SDL_SRCALPHA, (int)(200 + 55*sin(fadetimer += gamerate/2.0))); - SDL_BlitSurface(surf_b_variations,&src,surf_screen,&dest); - - src.w = surf_b_on->w; - src.h = surf_b_on->h; - dest.w = src.w; - dest.h = src.h; - dest.x = (XSIZE-src.w)/2 + cos((fadetimer + 1.0)/6.5)*10; - dest.y = (YSIZE/2-src.h)/2 + surf_b_variations->h + 20 + sin((fadetimer + 1.0)/5.0)*10; + SDL_BlitSurface(surf_b_variations,NULL,surf_screen,&dest); + + dest.x = (XSIZE-surf_b_on->w)/2 + cos((fadetimer + 1.0)/6.5)*10; + dest.y = (YSIZE/2-surf_b_on->h)/2 + surf_b_variations->h + 20 + sin((fadetimer + 1.0)/5.0)*10; SDL_SetAlpha(surf_b_on, SDL_SRCALPHA, (int)(200 + 55*sin(fadetimer-1.0))); - SDL_BlitSurface(surf_b_on,&src,surf_screen,&dest); - - src.w = surf_b_rockdodger->w; - src.h = surf_b_rockdodger->h; - dest.w = src.w; - dest.h = src.h; - dest.x = (XSIZE-src.w)/2 + cos((fadetimer + 2.0)/6.5)*10; - dest.y = (YSIZE/2-src.h)/2 + surf_b_variations->h + surf_b_on->h + 40 + sin((fadetimer + 2.0)/5)*10; + SDL_BlitSurface(surf_b_on,NULL,surf_screen,&dest); + + dest.x = (XSIZE-surf_b_rockdodger->w)/2 + cos((fadetimer + 2.0)/6.5)*10; + dest.y = (YSIZE/2-surf_b_rockdodger->h)/2 + surf_b_variations->h + surf_b_on->h + 40 + sin((fadetimer + 2.0)/5)*10; SDL_SetAlpha(surf_b_rockdodger, SDL_SRCALPHA, (int)(200 + 55*sin(fadetimer-2.0))); - SDL_BlitSurface(surf_b_rockdodger,&src,surf_screen,&dest); + SDL_BlitSurface(surf_b_rockdodger,NULL,surf_screen,&dest); text = "Version " VERSION; x = (XSIZE-SFont_TextWidth(g_font,text))/2 + sin(fadetimer/4.5)*10; @@ -796,6 +796,8 @@ gameloop() { reset_rocks(); + game_ticks = 0; + nships = 4; score = 0; diff --git a/rocks.c b/rocks.c index 94df499..607431d 100644 --- a/rocks.c +++ b/rocks.c @@ -25,6 +25,8 @@ struct shape rock_shapes[NROCKS]; // timers for rock generation. float rtimers[4]; +uint32_t rcnt; + uint32_t nrocks; uint32_t nrocks_timer; uint32_t nrocks_inc_ticks = 2*60*1000/(F_ROCKS-I_ROCKS); @@ -64,6 +66,7 @@ reset_rocks(void) for(i = 0; ix = rnd()*(XSIZE + rockptr->image->w); rockptr->y = YSIZE; - rockptr->dx = RDY*crnd(); + rockptr->dx = RDX*crnd(); rockptr->dy = -weighted_rnd_range(rmin[i], rmax[i]) + screendy; break; case TOP: rockptr->x = rnd()*(XSIZE + rockptr->image->w); rockptr->y = -rockptr->image->h; - rockptr->dx = RDY*crnd(); + rockptr->dx = RDX*crnd(); rockptr->dy = weighted_rnd_range(rmin[i], rmax[i]) + screendy; break; } rockptr->active = 1; + rcnt++; } } } @@ -224,9 +228,12 @@ move_rocks(void) if(rock[i].x < -rock[i].image->w || rock[i].x >= XSIZE || rock[i].y < -rock[i].image->h || rock[i].y >= YSIZE) { rock[i].active = 0; + rcnt--; } } } + // if(rcnt < nrocks) printf("-%d.\n", nrocks-rcnt); + // else printf("%d.\n", rcnt-nrocks); } void -- 1.7.10.4