]> git.itanic.dy.fi Git - sdl-planets/commitdiff
planet.c: Size of the planet is the planet radius
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 20 Mar 2010 11:15:18 +0000 (13:15 +0200)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 20 Mar 2010 11:15:18 +0000 (13:15 +0200)
Thus, rename the 'size' variable to 'radius'.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
planet.c
planet.h

index b2931fe356255fb1098d782fe624f5dbbb02092f..e6716adec5c92383af13224ccaaa863d09a0f83c 100644 (file)
--- a/planet.c
+++ b/planet.c
@@ -18,7 +18,7 @@ static void putpixel(struct SDL_Surface *screen, const int x, const int y,
 
 static void reshape_planet(struct planet *p)
 {
-       p->size = pow(p->mass / 100, 1 / 3.0);
+       p->radius = pow(p->mass / 100, 1 / 3.0);
 }
 
 void init_planet(struct planet *p)
@@ -40,7 +40,7 @@ void draw_planet(SDL_Surface *screen, struct planet *p,
                 const struct camera *cam)
 {
        struct vector pos;
-       int size = p->size * cam->zoom;
+       int radius = p->radius * cam->zoom;
        int x, x_start, y, x_end, y_end;
 
        vector_sub(&p->pos, &cam->pos, &pos);
@@ -48,11 +48,11 @@ void draw_planet(SDL_Surface *screen, struct planet *p,
        pos.x += screen->w / 2;
        pos.y += screen->h / 2;
 
-       x_start = MAX(pos.x - size, 0);
-       y = MAX(pos.y - size, 0);
+       x_start = MAX(pos.x - radius, 0);
+       y = MAX(pos.y - radius, 0);
 
-       x_end = MIN(pos.x + size + 1, screen->w);
-       y_end = MIN(pos.y + size + 1, screen->h);
+       x_end = MIN(pos.x + radius + 1, screen->w);
+       y_end = MIN(pos.y + radius + 1, screen->h);
 
        for (; y < y_end; y++)
                for (x = x_start; x < x_end; x++)
@@ -69,7 +69,7 @@ int gravitize_planets(struct planet *a, struct planet *b, const double time)
        dist = vector_abs(&distance);
 
        /* Return true in case of a collision */
-       if (dist < (a->size + b->size))
+       if (dist < (a->radius + b->radius))
                return 1;
 
        vector_div(&distance, dist, &distance);
@@ -132,6 +132,6 @@ void move_planet(struct planet *p, const double time)
 
 void print_planet(const struct planet *p)
 {
-       printf("pos: (%f,%f), speed: (%f,%f), mass: %f, size %f\n",
-              p->pos.x, p->pos.y, p->speed.x, p->speed.y, p->mass, p->size);
+       printf("pos: (%f,%f), speed: (%f,%f), mass: %f, radius %f\n",
+              p->pos.x, p->pos.y, p->speed.x, p->speed.y, p->mass, p->radius);
 }
index 77d775201792fb5282cc4fd74a0d3568b585f980..30934f5be0c2e454b9220b8a40d60cf39e04ad81 100644 (file)
--- a/planet.h
+++ b/planet.h
@@ -13,7 +13,7 @@ struct planet {
        struct vector pos;
        struct list_head list;
        double mass;
-       float size;
+       float radius;
        unsigned char r, g, b;
 };