X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=main.c;h=96c396831e8e93fc11c45e4703b46bc322c91d01;hp=b075f0dcd4c2ba1f153f507dccfb878771cf3d09;hb=0978da8f14d855eecae9882b559d6e8b0533e78e;hpb=44497dc461bc10bc2c4398e5311d4136007b3488 diff --git a/main.c b/main.c index b075f0d..96c3968 100644 --- a/main.c +++ b/main.c @@ -66,7 +66,7 @@ struct bangdots bdot[MAXBANGDOTS], *bdotptr = bdot; char topline[1024]; char *initerror = ""; -struct ship ship = { SHIP_SPRITE, NULL, XSIZE/2, YSIZE/2, SCREENDXMIN, 0.0 }; +struct ship ship = { SHIP, ALL_FLAGS, NULL, XSIZE/2, YSIZE/2, SCREENDXMIN, 0.0 }; float screendx = SCREENDXMIN, screendy = 0.0; float xscroll, yscroll; @@ -77,6 +77,7 @@ float t_frame; // length of this frame (in ticks = 1/20th second) int ms_frame; // length of this frame (milliseconds) int ms_end; // end of this frame (milliseconds) +int bang = false; float bangx, bangy, bangdx, bangdy; int score; @@ -388,6 +389,7 @@ init(void) { init_dust(); init_sprites(); + add_sprite(SPRITE(&ship)); // Remove the mouse cursor #ifdef SDL_DISABLE @@ -397,16 +399,14 @@ init(void) { return 0; } -int -draw() { +void +draw(void) { int i; SDL_Rect dest; - int bang, x; + int x; char *text; float fadegame,fadeover; - bang = 0; - // Draw a fully black background SDL_FillRect(surf_screen,NULL,0); @@ -509,12 +509,7 @@ draw() { ; // no action necessary } - if(state == GAMEPLAY) { - Sprite *r = collides(SPRITE(&ship)); - if(r) { - bounce(r, SPRITE(&ship)); - } - } + collisions(); ms_frame = SDL_GetTicks() - ms_end; ms_end += ms_frame; @@ -530,9 +525,18 @@ draw() { // Update the surface SDL_Flip(surf_screen); +} - - return bang; +void +do_collision(Sprite *a, Sprite *b) +{ + if(a->type == SHIP) { + a->flags = MOVE_FLAG; bang = true; + } else if (b->type == SHIP) { + b->flags = MOVE_FLAG; bang = true; + } else { + bounce(a, b); + } } int @@ -549,6 +553,7 @@ gameloop() { switch(state) { case DEAD_PAUSE: // Create a new ship and start all over again + ship.flags = ALL_FLAGS; state = GAMEPLAY; play_tune(TUNE_GAMEPLAY); break; @@ -613,7 +618,6 @@ gameloop() { bangx += bangdx*t_frame - xscroll; bangy += bangdy*t_frame - yscroll; - move_sprite(SPRITE(&ship)); move_sprites(); @@ -631,13 +635,15 @@ gameloop() { ship.dy = screendy - (ship.dy-screendy)*opt_bounciness; } + draw(); - if(draw() && state == GAMEPLAY) { + if(state == GAMEPLAY && bang) { // Died + bang = false; play_sound(SOUND_BANG); // Play the explosion sound bangx = ship.x; bangy = ship.y; bangdx = ship.dx; bangdy = ship.dy; - new_bang_dots(ship.x,ship.y,ship.dx,ship.dy,ship.image); - ship.dx *= 0.5; ship.dy *= 0.5; + new_bang_dots(ship.x,ship.y,ship.dx,ship.dy,ship.image); + ship.dx *= 0.5; ship.dy *= 0.5; if(ship.dx < SCREENDXMIN) ship.dx = SCREENDXMIN; if(--ship.lives <= 0) { state = GAME_OVER; @@ -645,8 +651,7 @@ gameloop() { state_timeout = 200.0; fadetimer = 0.0; faderate = t_frame; - } - else { + } else { state = DEAD_PAUSE; state_timeout = DEAD_PAUSE_LENGTH; } @@ -657,17 +662,19 @@ gameloop() { // new game if(keystate[SDLK_SPACE] && (state == HIGH_SCORE_DISPLAY || state == TITLE_PAGE)) { - + reset_sprites(); reset_rocks(); + ship.x = XSIZE/2.2; ship.y = YSIZE/2; + ship.dx = screendx; ship.dy = screendy; ship.lives = 4; + ship.flags = ALL_FLAGS; + add_sprite(SPRITE(&ship)); + score = 0; state = GAMEPLAY; play_tune(TUNE_GAMEPLAY); - - ship.x = XSIZE/2.2; ship.y = YSIZE/2; - ship.dx = screendx; ship.dy = screendy; } ship.jets = 0;