char topline[1024];
char *initerror = "";
-struct ship ship = { SHIP_SPRITE, NULL, XSIZE/2, YSIZE/2, SCREENDXMIN, 0.0 };
+struct ship ship = { SHIP, ALL_FLAGS, 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;
init_dust();
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);
; // no action necessary
}
- if(state == GAMEPLAY) {
- bang = collides(SPRITE(&ship));
- }
+ 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->flags = MOVE_FLAG; bang = true;
+ } else if (b->type == SHIP) {
+ b->flags = MOVE_FLAG; bang = true;
+ } else {
+ bounce(a, b);
+ }
}
int
switch(state) {
case DEAD_PAUSE:
// Create a new ship and start all over again
+ ship.flags = ALL_FLAGS;
state = GAMEPLAY;
play_tune(TUNE_GAMEPLAY);
break;
bangx += bangdx*t_frame - xscroll;
bangy += bangdy*t_frame - yscroll;
- move_sprite(SPRITE(&ship));
move_sprites();
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;
+ ship.flags = ALL_FLAGS;
+ 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;