X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=main.c;h=5341e289c380fef401b7b141549083d20ab2060a;hp=0e0188aa3ae614f39c18aa0a03a16af7686b30de;hb=7e7335ed9dcf2b1484543fec9bfa196bdc658fd5;hpb=e19c2c96e7370d93f19c8b0741a5649c4bbe21ee diff --git a/main.c b/main.c index 0e0188a..5341e28 100644 --- 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 @@ -44,19 +45,14 @@ // ************************************* STRUCTS struct rock_struct { - // Array of black pixel coordinates. This is scanned - // every frame to see if it's still black, and as - // soon as it isn't we BLOW UP float x,y,dx,dy; int active; 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 { - int x,y; -}; struct bangdots { // Bang dots have the same colour as shield dots. // Bang dots get darker as they age. @@ -96,12 +92,13 @@ 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 struct enginedots edot[MAXENGINEDOTS], *dotptr = edot; struct rock_struct rock[MAXROCKS], *rockptr = rock; -struct black_point_struct black_point[MAXBLACKPOINTS], *blackptr = black_point; struct bangdots bdot[MAXBANGDOTS], *bdotptr = bdot; struct spacedot sdot[MAXSPACEDOTS]; @@ -109,6 +106,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; @@ -216,7 +214,7 @@ makebangdots(int xbang, int ybang, int dx, int dy, SDL_Surface *s, int power) { for(x = 0; xw; x++) { for(y = 0; yh; y++) { c = rawpixel[s->pitch/2*y + x]; - if(c && c != SDL_MapRGB(s->format,0,255,0)) { + if(c && c != s->format->colorkey) { theta = rnd()*M_PI*2; @@ -467,12 +465,12 @@ drawdots(SDL_Surface *s) { SDL_UnlockSurface(s); } + char a[MAX_PATH_LEN]; int init(int fullscreen) { - int i,j; + int i; SDL_Surface *temp; - Uint16 *raw_pixels; Uint32 flag; // Where are our data files? @@ -538,36 +536,21 @@ 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"))); NULLERROR(surf_life = SDL_DisplayFormat(temp)); - // Create the array of black points; - SDL_LockSurface(surf_ship); - raw_pixels = (Uint16 *) surf_ship->pixels; - for(i = 0; iw; i++) { - for(j = 0; jh; j++) { - if(raw_pixels[j*(surf_ship->pitch)/2 + i] == 0) { - blackptr->x = i; - blackptr->y = j; - blackptr++; - } - } - } - - SDL_UnlockSurface(surf_ship); - init_engine_dots(); init_space_dots(); // Load all our lovely rocks for(i = 0; ipixels; - // Check that the black points on the ship are - // still black, and not covered up by rocks. - for(p = black_point; ppitch/2 * (p->y + (int)shipy) + p->x + (int)shipx; - if(raw_pixels[offset]) { - // Set the bang flag - bang = 1; + for(i=0; idy = 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); } @@ -1019,18 +995,6 @@ gameloop() { if(keystate[SDLK_p] | keystate[SDLK_s]) { if(!pausedown) { paused = !paused; - if(paused) { - SDL_Rect src,dest; - 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; - dest.y = (YSIZE-src.h)/2; - SDL_BlitSurface(surf_b_variations,&src,surf_screen,&dest); - // Update the surface - SDL_Flip(surf_screen); - } pausedown = 1; } } else {