Got questions, comments, patches, etc.?
Contact Jason Woofenden
gitweb
/
vor.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
we now return you to your regularly scheduled exploding ship.
[vor.git]
/
main.c
diff --git
a/main.c
b/main.c
index
880f14e
..
a068033
100644
(file)
--- a/
main.c
+++ b/
main.c
@@
-77,6
+77,7
@@
float t_frame; // length of this frame (in ticks = 1/20th second)
int ms_frame; // length of this frame (milliseconds)
int ms_end; // end of this frame (milliseconds)
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;
float bangx, bangy, bangdx, bangdy;
int score;
@@
-388,6
+389,7
@@
init(void) {
init_dust();
init_sprites();
init_dust();
init_sprites();
+ add_sprite(SPRITE(&ship));
// Remove the mouse cursor
#ifdef SDL_DISABLE
// Remove the mouse cursor
#ifdef SDL_DISABLE
@@
-397,16
+399,14
@@
init(void) {
return 0;
}
return 0;
}
-int
-draw() {
+void
+draw(void) {
int i;
SDL_Rect dest;
int i;
SDL_Rect dest;
- int bang, x;
+ int x;
char *text;
float fadegame,fadeover;
char *text;
float fadegame,fadeover;
- bang = 0;
-
// Draw a fully black background
SDL_FillRect(surf_screen,NULL,0);
// Draw a fully black background
SDL_FillRect(surf_screen,NULL,0);
@@
-509,13
+509,7
@@
draw() {
; // no action necessary
}
; // no action necessary
}
- if(state == GAMEPLAY) {
- Sprite *r = collides(SPRITE(&ship));
- if(r) {
- bounce(r, SPRITE(&ship));
- }
- collisions();
- }
+ collisions();
ms_frame = SDL_GetTicks() - ms_end;
ms_end += ms_frame;
ms_frame = SDL_GetTicks() - ms_end;
ms_end += ms_frame;
@@
-531,15
+525,18
@@
draw() {
// Update the surface
SDL_Flip(surf_screen);
// Update the surface
SDL_Flip(surf_screen);
-
-
- return bang;
}
void
do_collision(Sprite *a, Sprite *b)
{
}
void
do_collision(Sprite *a, Sprite *b)
{
- bounce(a, 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
}
int
@@
-556,6
+553,7
@@
gameloop() {
switch(state) {
case DEAD_PAUSE:
// Create a new ship and start all over again
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;
state = GAMEPLAY;
play_tune(TUNE_GAMEPLAY);
break;
@@
-620,7
+618,6
@@
gameloop() {
bangx += bangdx*t_frame - xscroll;
bangy += bangdy*t_frame - yscroll;
bangx += bangdx*t_frame - xscroll;
bangy += bangdy*t_frame - yscroll;
- move_sprite(SPRITE(&ship));
move_sprites();
move_sprites();
@@
-638,13
+635,15
@@
gameloop() {
ship.dy = screendy - (ship.dy-screendy)*opt_bounciness;
}
ship.dy = screendy - (ship.dy-screendy)*opt_bounciness;
}
+ draw();
- if(draw() && state == GAMEPLAY) {
+ if(state == GAMEPLAY && bang) {
// Died
// Died
+ bang = false;
play_sound(SOUND_BANG); // Play the explosion sound
bangx = ship.x; bangy = ship.y; bangdx = ship.dx; bangdy = ship.dy;
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;
if(ship.dx < SCREENDXMIN) ship.dx = SCREENDXMIN;
if(--ship.lives <= 0) {
state = GAME_OVER;
@@
-652,8
+651,7
@@
gameloop() {
state_timeout = 200.0;
fadetimer = 0.0;
faderate = t_frame;
state_timeout = 200.0;
fadetimer = 0.0;
faderate = t_frame;
- }
- else {
+ } else {
state = DEAD_PAUSE;
state_timeout = DEAD_PAUSE_LENGTH;
}
state = DEAD_PAUSE;
state_timeout = DEAD_PAUSE_LENGTH;
}
@@
-664,17
+662,18
@@
gameloop() {
// new game
if(keystate[SDLK_SPACE] && (state == HIGH_SCORE_DISPLAY || state == TITLE_PAGE)) {
// new game
if(keystate[SDLK_SPACE] && (state == HIGH_SCORE_DISPLAY || state == TITLE_PAGE)) {
-
+ reset_sprites();
reset_rocks();
reset_rocks();
+ ship.x = XSIZE/2.2; ship.y = YSIZE/2;
+ ship.dx = screendx; ship.dy = screendy;
ship.lives = 4;
ship.lives = 4;
+ add_sprite(SPRITE(&ship));
+
score = 0;
state = GAMEPLAY;
play_tune(TUNE_GAMEPLAY);
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;
}
ship.jets = 0;