| @@ -29,6 +29,8 @@ | |||||
| box * create_box(game *g, int x, int y, int w, int h) | box * create_box(game *g, int x, int y, int w, int h) | ||||
| { | { | ||||
| box *b = malloc(sizeof(box)); | box *b = malloc(sizeof(box)); | ||||
| if(b == NULL) | |||||
| exit(1); | |||||
| b->x = x; | b->x = x; | ||||
| b->y = y; | b->y = y; | ||||
| @@ -36,6 +36,8 @@ static void start_game (game *); | |||||
| int main (int argc, char **argv) | int main (int argc, char **argv) | ||||
| { | { | ||||
| game *g = malloc(sizeof(game)); | game *g = malloc(sizeof(game)); | ||||
| if(g == NULL) | |||||
| exit(1); | |||||
| srand(time(NULL)); | srand(time(NULL)); | ||||
| @@ -70,11 +72,19 @@ static void start_game (game *g) | |||||
| g->sf = create_starfield(g); | g->sf = create_starfield(g); | ||||
| g->wp = malloc(sizeof(weapons)); | g->wp = malloc(sizeof(weapons)); | ||||
| if(g->wp == NULL) | |||||
| exit(1); | |||||
| g->ex = malloc(sizeof(explosions)); | g->ex = malloc(sizeof(explosions)); | ||||
| if(g->ex == NULL) | |||||
| exit(1); | |||||
| g->bo = malloc(sizeof(bonus)); | g->bo = malloc(sizeof(bonus)); | ||||
| if(g->bo == NULL) | |||||
| exit(1); | |||||
| g->t = create_tunnel(g, g->w, g->h); | g->t = create_tunnel(g, g->w, g->h); | ||||
| g->p = create_player(g); | g->p = create_player(g); | ||||
| g->al = malloc(sizeof(aliens)); | g->al = malloc(sizeof(aliens)); | ||||
| if(g->al == NULL) | |||||
| exit(1); | |||||
| init_bonus(g, g->bo); | init_bonus(g, g->bo); | ||||
| init_weapons(g, g->wp); | init_weapons(g, g->wp); | ||||
| @@ -32,6 +32,8 @@ struct ee_sprite *ship_sprite; | |||||
| player * create_player(game *g) | player * create_player(game *g) | ||||
| { | { | ||||
| player *p = malloc(sizeof(player)); | player *p = malloc(sizeof(player)); | ||||
| if(p == NULL) | |||||
| exit(1); | |||||
| p->x = g->w / 2; | p->x = g->w / 2; | ||||
| p->y = g->h - 3; | p->y = g->h - 3; | ||||
| @@ -32,6 +32,8 @@ starfield * create_starfield(game *g) | |||||
| starfield *s; | starfield *s; | ||||
| s = malloc(STARS * sizeof(starfield)); | s = malloc(STARS * sizeof(starfield)); | ||||
| if(s == NULL) | |||||
| exit(1); | |||||
| for(i = 0; i < STARS; i++) | for(i = 0; i < STARS; i++) | ||||
| { | { | ||||
| @@ -31,9 +31,15 @@ tunnel * create_tunnel(game *g, int w, int h) | |||||
| { | { | ||||
| int i; | int i; | ||||
| tunnel *t = malloc(sizeof(tunnel)); | tunnel *t = malloc(sizeof(tunnel)); | ||||
| if(t == NULL) | |||||
| exit(1); | |||||
| t->left = malloc(h*sizeof(int)); | t->left = malloc(h*sizeof(int)); | ||||
| if(t->left == NULL) | |||||
| exit(1); | |||||
| t->right = malloc(h*sizeof(int)); | t->right = malloc(h*sizeof(int)); | ||||
| if(t->right == NULL) | |||||
| exit(1); | |||||
| t->w = w; | t->w = w; | ||||
| t->h = h; | t->h = h; | ||||
| @@ -169,7 +169,7 @@ void update_weapons(game *g, weapons *wp) | |||||
| /* Normalize direction */ | /* Normalize direction */ | ||||
| if(dx | dy) | if(dx | dy) | ||||
| { | { | ||||
| int norm = ee_sqrt(dx * dx + 4 * dy * dy); | |||||
| unsigned int norm = ee_sqrt(dx * dx + 4 * dy * dy); | |||||
| dx = dx * 32 / norm; | dx = dx * 32 / norm; | ||||
| dy = dy * 32 / norm; | dy = dy * 32 / norm; | ||||
| } | } | ||||
| @@ -181,7 +181,7 @@ void update_weapons(game *g, weapons *wp) | |||||
| /* Normalize speed */ | /* Normalize speed */ | ||||
| if(dx | dy) | if(dx | dy) | ||||
| { | { | ||||
| int norm = ee_sqrt(dx * dx + 4 * dy * dy); | |||||
| unsigned int norm = ee_sqrt(dx * dx + 4 * dy * dy); | |||||
| wp->vx[i] = dx * 32 / norm; | wp->vx[i] = dx * 32 / norm; | ||||
| wp->vy[i] = dy * 32 / norm; | wp->vy[i] = dy * 32 / norm; | ||||
| } | } | ||||