#include <argp.h>
#include <math.h>
-#include <SDL/SDL.h>
-#include <SDL/SDL_image.h>
+#include <SDL.h>
+#include <SDL_image.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
char topline[1024];
char *initerror = "";
-struct ship ship = { SHIP_SPRITE, NULL, XSIZE/2, YSIZE/2, SCREENDXMIN, 0.0 };
+struct ship ship = { SHIP, NULL, XSIZE/2, YSIZE/2, SCREENDXMIN, 0.0 };
float screendx = SCREENDXMIN, screendy = 0.0;
float xscroll, yscroll;
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;
}
// check collisions
- if(pixel_hit_rocks(bdot[i].x, bdot[i].y)) { bdot[i].active = 0; continue; }
+ if(pixel_collides(bdot[i].x, bdot[i].y)) { bdot[i].active = 0; continue; }
pixel = pixels + row_inc*(int)(bdot[i].y) + (int)(bdot[i].x);
if(bdot[i].c) c = bdot[i].c; else c = heatcolor[(int)(bdot[i].life)*3];
edot[i].active = 0;
continue;
}
- if(pixel_hit_rocks(edot[i].x, edot[i].y)) { edot[i].active = 0; continue; }
+ if(pixel_collides(edot[i].x, edot[i].y)) { edot[i].active = 0; continue; }
heatindex = edot[i].life * 6;
c = heatindex>3*W ? heatcolor[3*W-1] : heatcolor[heatindex];
pixels[row_inc*(int)(edot[i].y) + (int)(edot[i].x)] = c;
return img;
}
+void
+load_ship(void)
+{
+ load_sprite(SPRITE(&ship), "sprites/ship.png");
+}
+
int
init(void) {
NULLERROR(surf_b_game = load_image("banners/game.png"));
NULLERROR(surf_b_over = load_image("banners/over.png"));
- // Load the spaceship graphic.
- ship.shape = malloc(sizeof(struct shape));
- if(!ship.shape) {
- fprintf(stderr, "can't allocate ship shape.\n");
- exit(1);
- }
- NULLERROR(ship.image = load_image("sprites/ship.png"));
- get_shape(ship.image, ship.shape);
-
// Load the life indicator (small ship) graphic.
NULLERROR(surf_life = load_image("indicators/life.png"));
init_engine_dots();
init_dust();
- init_rocks();
+ init_sprites();
+ add_sprite(SPRITE(&ship));
// Remove the mouse cursor
#ifdef SDL_DISABLE
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);
drawdots(surf_screen);
// Draw ship
- if(state == GAMEPLAY ) {
- dest.x = ship.x;
- dest.y = ship.y;
- SDL_BlitSurface(ship.image,NULL,surf_screen,&dest);
- }
+ if(state == GAMEPLAY) draw_sprite(SPRITE(&ship));
draw_rocks();
; // no action necessary
}
- if(state == GAMEPLAY) {
- bang = hit_rocks(ship.x, ship.y, ship.shape);
- }
+ collisions();
ms_frame = SDL_GetTicks() - ms_end;
ms_end += ms_frame;
// Update the surface
SDL_Flip(surf_screen);
+}
-
- return bang;
+void
+do_collision(Sprite *a, Sprite *b)
+{
+ if(a->type == SHIP) {
+ a->type = -SHIP; bang = true;
+ } else if (b->type == SHIP) {
+ b->type = -SHIP; bang = true;
+ } else {
+ bounce(a, b);
+ }
}
int
switch(state) {
case DEAD_PAUSE:
// Create a new ship and start all over again
+ ship.sprite_type = SHIP;
state = GAMEPLAY;
play_tune(TUNE_GAMEPLAY);
break;
} else {
if(state == DEAD_PAUSE) {
float blast_radius;
- int fixonly;
-
- if(state_timeout < DEAD_PAUSE_LENGTH - 20.0) {
- blast_radius = BLAST_RADIUS * 1.3;
- fixonly = 1;
- } else {
+ if(state_timeout >= DEAD_PAUSE_LENGTH - 20.0) {
blast_radius = BLAST_RADIUS * (DEAD_PAUSE_LENGTH - state_timeout) / 20.0;
- fixonly = 0;
+ blast_rocks(bangx, bangy, blast_radius);
}
- blast_rocks(bangx, bangy, blast_radius, fixonly);
if(bangx < 60) bangx = 60;
}
xscroll = screendx * t_frame;
yscroll = screendy * t_frame;
- ship.x += ship.dx*t_frame - xscroll;
- ship.y += ship.dy*t_frame - yscroll;
-
// move bang center
bangx += bangdx*t_frame - xscroll;
bangy += bangdy*t_frame - yscroll;
- move_rocks();
+ move_sprites();
// BOUNCE X
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;
state_timeout = 200.0;
fadetimer = 0.0;
faderate = t_frame;
- }
- else {
+ } else {
state = DEAD_PAUSE;
state_timeout = DEAD_PAUSE_LENGTH;
}
// 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;
+ 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;