JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
bbox collision detection.
[vor.git] / main.c
diff --git a/main.c b/main.c
index 058fbad..ad3ab56 100644 (file)
--- a/main.c
+++ b/main.c
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "file.h"
 #include "score.h"
+#include "shape.h"
 #include "sound.h"
 
 #include <math.h>
@@ -52,6 +53,7 @@ struct rock_struct {
        int dead;  // has been blown out of the way
                   // to make room for a new ship appearing.
        SDL_Surface *image;
+       struct shape *shape;
        int type_number;
 }; 
 struct black_point_struct {
@@ -96,6 +98,8 @@ SDL_Surface
        *surf_rock[NROCKS],     // THE ROCKS
        *surf_font_big; // The big font
 
+struct shape rock_shapes[NROCKS];
+
 SFont_Font *g_font;
 
 // Structure global variables
@@ -109,6 +113,7 @@ struct spacedot sdot[MAXSPACEDOTS];
 char topline[1024];
 char *initerror = "";
 
+struct shape shipshape;
 float shipx,shipy = 240.0;     // X position, 0..XSIZE
 float shipdx,shipdy;   // Change in X position per tick.
 float rockrate,rockspeed;
@@ -467,6 +472,7 @@ drawdots(SDL_Surface *s) {
        SDL_UnlockSurface(s);
 }
 
+               char a[MAX_PATH_LEN];
 int
 init(int fullscreen) {
 
@@ -538,6 +544,7 @@ init(int fullscreen) {
        // Load the spaceship graphic.
        NULLERROR(temp = IMG_Load(add_path("sprites/ship.png")));
        NULLERROR(surf_ship = SDL_DisplayFormat(temp));
+       get_shape(surf_ship, &shipshape);
 
        // Load the life indicator (small ship) graphic.
        NULLERROR(temp = IMG_Load(add_path("indicators/life.png")));
@@ -563,11 +570,11 @@ init(int fullscreen) {
 
        // Load all our lovely rocks
        for(i = 0; i<NROCKS; i++) {
-               char a[MAX_PATH_LEN];
 
-               snprintf(a,MAX_PATH_LEN,add_path("sprites/rock%d.png"),i);
+               snprintf(a,MAX_PATH_LEN,add_path("sprites/rock%02d.png"),i);
                NULLERROR(temp = IMG_Load(a));
                NULLERROR(surf_rock[i] = SDL_DisplayFormat(temp));
+               get_shape(surf_rock[i], &rock_shapes[i]);
        }
 
        // Remove the mouse cursor
@@ -729,6 +736,13 @@ draw() {
        }
 
        if(!gameover && state == GAMEPLAY) {
+               for(i=0; i<MAXROCKS; i++) {
+                       if(rock[i].active) {
+                               if(collide(shipx-rock[i].x, shipy-rock[i].y, rock[i].shape, &shipshape)) 
+                                       bang = 1;
+                       }
+               }
+               /*
                SDL_LockSurface(surf_screen);
                raw_pixels = (Uint16 *) surf_screen->pixels;
                // Check that the black points on the ship are
@@ -741,6 +755,7 @@ draw() {
                        }
                }
                SDL_UnlockSurface(surf_screen);
+               */
        }
 
        // Draw all the little ships
@@ -881,6 +896,7 @@ gameloop() {
                                        rockptr->dy = rnd()-0.5;
                                        rockptr->type_number = random() % NROCKS;
                                        rockptr->image = surf_rock[rockptr->type_number];// [random()%NROCKS];
+                                       rockptr->shape = &rock_shapes[rockptr->type_number];
                                        rockptr->active = 1;
                                        rockptr->y = rnd()*(YSIZE + rockptr->image->h);
                                }