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
sprites now have a flag field (MOVE/DRAW/COLLIDE).
[vor.git]
/
main.c
diff --git
a/main.c
b/main.c
index
d57aa3b
..
96c3968
100644
(file)
--- a/
main.c
+++ b/
main.c
@@
-66,7
+66,7
@@
struct bangdots bdot[MAXBANGDOTS], *bdotptr = bdot;
char topline[1024];
char *initerror = "";
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;
float screendx = SCREENDXMIN, screendy = 0.0;
float xscroll, yscroll;
@@
-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;
@@
-203,7
+204,7
@@
draw_bang_dots(SDL_Surface *s)
}
// check collisions
}
// 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];
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];
@@
-268,7
+269,7
@@
draw_engine_dots(SDL_Surface *s) {
edot[i].active = 0;
continue;
}
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;
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;
@@
-311,6
+312,12
@@
load_image(char *filename)
return img;
}
return img;
}
+void
+load_ship(void)
+{
+ load_sprite(SPRITE(&ship), "sprites/ship.png");
+}
+
int
init(void) {
int
init(void) {
@@
-367,9
+374,6
@@
init(void) {
NULLERROR(surf_b_game = load_image("banners/game.png"));
NULLERROR(surf_b_over = load_image("banners/over.png"));
NULLERROR(surf_b_game = load_image("banners/game.png"));
NULLERROR(surf_b_over = load_image("banners/over.png"));
- // Load the spaceship graphic.
- load_sprite(SPRITE(&ship), "sprites/ship.png");
-
// Load the life indicator (small ship) graphic.
NULLERROR(surf_life = load_image("indicators/life.png"));
// Load the life indicator (small ship) graphic.
NULLERROR(surf_life = load_image("indicators/life.png"));
@@
-384,7
+388,8
@@
init(void) {
init_engine_dots();
init_dust();
init_engine_dots();
init_dust();
- init_rocks();
+ init_sprites();
+ add_sprite(SPRITE(&ship));
// Remove the mouse cursor
#ifdef SDL_DISABLE
// Remove the mouse cursor
#ifdef SDL_DISABLE
@@
-394,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);
@@
-411,11
+414,7
@@
draw() {
drawdots(surf_screen);
// Draw ship
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();
draw_rocks();
@@
-510,9
+509,7
@@
draw() {
; // no action necessary
}
; // no action necessary
}
- if(state == GAMEPLAY) {
- bang = hit_rocks(SPRITE(&ship));
- }
+ collisions();
ms_frame = SDL_GetTicks() - ms_end;
ms_end += ms_frame;
ms_frame = SDL_GetTicks() - ms_end;
ms_end += ms_frame;
@@
-528,9
+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)
+{
+ 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
}
int
@@
-547,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.flags = ALL_FLAGS;
state = GAMEPLAY;
play_tune(TUNE_GAMEPLAY);
break;
state = GAMEPLAY;
play_tune(TUNE_GAMEPLAY);
break;
@@
-579,16
+586,10
@@
gameloop() {
} else {
if(state == DEAD_PAUSE) {
float blast_radius;
} 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;
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;
}
if(bangx < 60) bangx = 60;
}
@@
-613,14
+614,11
@@
gameloop() {
xscroll = screendx * t_frame;
yscroll = screendy * t_frame;
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 bang center
bangx += bangdx*t_frame - xscroll;
bangy += bangdy*t_frame - yscroll;
- move_rocks();
+ move_sprites();
// BOUNCE X
// BOUNCE X
@@
-637,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;
@@
-651,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;
}
@@
-663,17
+662,19
@@
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;
+ ship.flags = ALL_FLAGS;
+ 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;