From 5ffcd94bc184af41794eeead327e7880e0d8f65f Mon Sep 17 00:00:00 2001 From: Joshua Grams Date: Tue, 13 Jun 2006 20:33:17 +0000 Subject: [PATCH] refactoring main loop organization --- main.c | 88 ++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/main.c b/main.c index e6449fe..06f46c1 100644 --- a/main.c +++ b/main.c @@ -180,28 +180,21 @@ new_bang_dots(int xbang, int ybang, int dx, int dy, SDL_Surface *s) } void -draw_bang_dots(SDL_Surface *s) +move_bang_dots(float ticks) { int i; - int first_i, last_i; - uint16_t *pixels, *pixel, c; - int row_inc = s->pitch/sizeof(uint16_t); Sprite *hit; - pixels = (uint16_t *) s->pixels; - first_i = -1; - last_i = 0; - for(i=0; i= XSIZE || bdot[i].y < 0 || bdot[i].y >= YSIZE) { bdot[i].active = 0; continue; @@ -216,6 +209,21 @@ draw_bang_dots(SDL_Surface *s) continue; } } + } +} + + +void +draw_bang_dots(SDL_Surface *s) +{ + int i; + uint16_t *pixels, *pixel, c; + int row_inc = s->pitch/sizeof(uint16_t); + + pixels = (uint16_t *) s->pixels; + + for(i=0; i> 2) & 1) - (ship.jets & 1); @@ -287,18 +295,29 @@ new_engine_dots(float time_span, int dir) { } void -move_engine_dots() { +move_engine_dots(float ticks) { int i; + Sprite *hit; + for(i = 0; i= XSIZE || edot[i].y < 0 || edot[i].y >= YSIZE) { edot[i].active = 0; } + + // check collisions + if((hit = pixel_collides(edot[i].x, edot[i].y))) { + if(hit->type != SHIP) { // they shouldn't hit the ship, but they do + edot[i].active = 0; + hit->dx += ENGINE_DOT_WEIGHT * edot[i].life * edot[i].dx / sprite_mass(hit); + hit->dy += ENGINE_DOT_WEIGHT * edot[i].life * edot[i].dy / sprite_mass(hit); + continue; + } + } } } @@ -309,21 +328,10 @@ draw_engine_dots(SDL_Surface *s) { uint16_t *pixels = (uint16_t *) s->pixels; int row_inc = s->pitch/sizeof(uint16_t); int heatindex; - Sprite *hit; for(i = 0; itype != SHIP) { // they shouldn't hit the ship, but they do - edot[i].active = 0; - hit->dx += ENGINE_DOT_WEIGHT * edot[i].life * edot[i].dx / sprite_mass(hit); - hit->dy += ENGINE_DOT_WEIGHT * edot[i].life * edot[i].dy / sprite_mass(hit); - continue; - } - } + if(!edot[i].active) 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; @@ -331,11 +339,9 @@ draw_engine_dots(SDL_Surface *s) { } void -drawdots(SDL_Surface *s) { +draw_dots(SDL_Surface *s) { int m; - move_engine_dots(); - // Create engine dots for(m = 0; m<4; m++) { if(ship.jets & 1< XSIZE) { @@ -709,6 +713,8 @@ gameloop() { ship.dy = screendy - (ship.dy-screendy)*opt_bounciness; } + new_rocks(t_frame); + draw(); if(state == GAMEPLAY && bang) { -- 1.7.10.4