* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#undef DEBUG
+#ifdef DEBUG
+#include "debug.h"
+#endif
#include "config.h"
#include "file.h"
#include "score.h"
+#include "shape.h"
#include "sound.h"
#include <math.h>
// ************************************* 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.
*surf_ship, // Spaceship element
*surf_life, // Indicator of number of ships remaining
*surf_rock[NROCKS], // THE ROCKS
- *surf_deadrock[NROCKS], // THE DEAD 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];
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;
for(x = 0; x<s->w; x++) {
for(y = 0; y<s->h; 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;
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?
// 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; i<surf_ship->w; i++) {
- for(j = 0; j<surf_ship->h; 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; i<NROCKS; i++) {
- char a[100];
-
- sprintf(a,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));
-
- sprintf(a,add_path("sprites/deadrock%d.png"),i);
- NULLERROR(temp = IMG_Load(a));
- NULLERROR(surf_deadrock[i] = SDL_DisplayFormat(temp));
+ get_shape(surf_rock[i], &rock_shapes[i]);
}
// Remove the mouse cursor
draw() {
int i;
SDL_Rect src,dest;
- struct black_point_struct *p;
- Uint16 *raw_pixels;
- int bang, offset, x;
+ int bang, x;
char *text;
float fadegame,fadeover;
case HIGH_SCORE_DISPLAY:
// Display de list o high scores mon.
display_scores(surf_screen, 150,50);
+ break;
case GAMEPLAY:
case DEAD_PAUSE:
; // no action necessary
}
if(!gameover && state == GAMEPLAY) {
- SDL_LockSurface(surf_screen);
- raw_pixels = (Uint16 *) surf_screen->pixels;
- // Check that the black points on the ship are
- // still black, and not covered up by rocks.
- for(p = black_point; p<blackptr; p++) {
- offset = surf_screen->pitch/2 * (p->y + (int)shipy) + p->x + (int)shipx;
- if(raw_pixels[offset]) {
- // Set the bang flag
- bang = 1;
+ 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_UnlockSurface(surf_screen);
}
// Draw all the little ships
}
} else {
if(state == DEAD_PAUSE) {
- float blast_radius = BLAST_RADIUS * state_timeout / 20.0;
+ float blast_radius;
+ int fixonly;
+
+ if(state_timeout < DEAD_PAUSE_LENGTH - 20.0) {
+ blast_radius = BLAST_RADIUS * 1.3;
+ fixonly = 1;
+ } else {
+ blast_radius = BLAST_RADIUS * (DEAD_PAUSE_LENGTH - state_timeout) / 20.0;
+ fixonly = 0;
+ }
+
if(shipx < 60) shipx = 60;
for(i = 0; i<MAXROCKS; i++ ) {
float dx, dy, n;
if(rock[i].x <= 0) continue;
+
+ // This makes it so your explosion from dying magically doesn't leave
+ // any rocks that aren't moving much on the x axis. After the first
+ // 20 tics, only rocks that are barely moving will be pushed.
+ if(fixonly && (!rock[i].dead || rock[i].dx < -4 || rock[i].dx > 3)) {
+ continue;
+ }
+
dx = rock[i].x - shipx;
dy = rock[i].y - shipy;
+
n = sqrt(dx*dx + dy*dy);
if(n < blast_radius) {
n *= 20;
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);
}
}
else {
state = DEAD_PAUSE;
- state_timeout = 20.0;
+ state_timeout = DEAD_PAUSE_LENGTH;
shipdx = 0;
shipdy = 0;
}
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 {