JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
another try at re-appearing where you were.
[vor.git] / main.c
diff --git a/main.c b/main.c
index 489c352..68c77a4 100644 (file)
--- a/main.c
+++ b/main.c
@@ -54,6 +54,8 @@ struct rock_struct {
        // soon as it isn't we BLOW UP
        float x,y,xvel,yvel;
        int active;
+       int dead;  // has been blown out of the way
+                  // to make room for a new ship appearing.
        SDL_Surface *image;
        int type_number;
        float heat;
@@ -134,6 +136,7 @@ float xvel,yvel;    // Change in X position per tick.
 float rockrate,rockspeed;
 float movementrate;
 float yscroll;
+float scrollvel;
 
 int nships,score,initticks,ticks_since_last, last_ticks;
 int gameover;
@@ -1001,15 +1004,9 @@ int gameloop() {
                                                // Create a new ship and start all over again
                                                state = GAMEPLAY;
                                                play_tune(1);
-                                               xship = 10;
-                                               yship = YSIZE/2;
-                                               xvel = 3;
-                                               yvel = 0;
-                                               for(i = 0; i<MAXROCKS; i++ ) {
-                                                       if(dist_sq(xship, yship, rock[i].x, rock[i].y) < START_RAD_SQ) {
-                                                               rock[i].active = 0;
-                                                       }
-                                               }
+                                               xship -= 50;
+                                               // xvel = 3;
+                                               // yvel = 0;
                                        break;
                                        case GAME_OVER:
                                                state = HIGH_SCORE_ENTRY;
@@ -1054,6 +1051,23 @@ int gameloop() {
                                                state_timeout = 200.0;
                                        break;
                                }
+                       } else {
+                               if(state == DEAD_PAUSE) {
+                                       float blast_radius = START_RAD * state_timeout / 50.0;
+                                       for(i = 0; i<MAXROCKS; i++ ) {
+                                               float dx, dy, n;
+                                               if(rock[i].x <= 0) continue;
+                                               dx = rock[i].x - xship;
+                                               dy = rock[i].y - yship;
+                                               n = sqrt(dx*dx + dy*dy);
+                                               if(n < blast_radius) {
+                                                       n *= 50;
+                                                       rock[i].xvel += rockrate*(dx+30)/n;
+                                                       rock[i].yvel += rockrate*dy/n;
+                                                       rock[i].dead = 1;
+                                               }
+                                       }
+                               }
                        }
 
                        if(--countdown <= 0 && (rnd()*100.0<(rockrate += 0.025))) {
@@ -1093,7 +1107,10 @@ int gameloop() {
 
                        // SCROLLING
                        yscroll = yship - (YSIZE / 2);
-                       yscroll /= -15;
+                       yscroll += yvel * 25;
+                       yscroll /= -25;
+                       yscroll = ((scrollvel * (12 - movementrate)) + (yscroll * movementrate)) / 12;
+                       scrollvel = yscroll;
                        yscroll = yscroll*movementrate;
                        yship += yscroll;
                        
@@ -1101,15 +1118,15 @@ int gameloop() {
                        for(i = 0; i<MAXROCKS; i++) if(rock[i].active) {
                                rock[i].x += rock[i].xvel*movementrate;
                                rock[i].y += rock[i].yvel*movementrate + yscroll;
-                       if(rock[i].y > YSIZE) {
-                               rock[i].y -= YSIZE;
-                               rock[i].y -= rock[i].image->w;
-                       } else if(rock[i].y < -rock[i].image->w) {
-                               rock[i].y += YSIZE;
-                               rock[i].y += rock[i].image->w;
-                       }
-                       if(rock[i].x<-32.0)
-                               rock[i].active = 0;
+                               if(rock[i].dead && rock[i].y < 0 || rock[i].y > YSIZE) rock[i].active = 0;
+                               if(rock[i].y > YSIZE) {
+                                       rock[i].y -= YSIZE;
+                                       rock[i].y -= rock[i].image->w;
+                               } else if(rock[i].y < -rock[i].image->w) {
+                                       rock[i].y += YSIZE;
+                                       rock[i].y += rock[i].image->w;
+                               }
+                               if(rock[i].x < -32.0) rock[i].active = 0;
                        }
 
 
@@ -1144,7 +1161,8 @@ int gameloop() {
                                else {
                                        state = DEAD_PAUSE;
                                        state_timeout = 50.0;
-
+                                       xvel = 0;
+                                       yvel = 0;
                                }
                        }
 
@@ -1159,6 +1177,7 @@ int gameloop() {
 
                                for(i = 0; i<MAXROCKS; i++ ) {
                                        rock[i].active = 0;
+                                       rock[i].dead = 0;
                                }
 
                                rockrate = 54.0;
@@ -1270,6 +1289,7 @@ main(int argc, char **argv) {
        while(1) {
                for(i = 0; i<MAXROCKS; i++) {
                        rock[i].active = 0;
+                       rock[i].dead = 0;
                }
                rockrate = 54.0;
                rockspeed = 5.0;