]> git.itanic.dy.fi Git - sdl-planets/commitdiff
planet.c: Add function to reshape the size of the planet
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 7 Mar 2010 11:55:02 +0000 (13:55 +0200)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sun, 7 Mar 2010 11:55:02 +0000 (13:55 +0200)
This will be used when planets can be merged together at collision.

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

index 5c3fdaa33e337c64dd1c214ff97d9bdd1309284e..47d82f3adedae0d2ac388d12a6963fcd351931e9 100644 (file)
--- a/planet.c
+++ b/planet.c
@@ -1,3 +1,5 @@
+#include <math.h>
+
 #include "random.h"
 #include "planet.h"
 #include "utils.h"
@@ -14,6 +16,11 @@ static void putpixel(struct SDL_Surface *screen, const int x, const int y,
        buf[offset]   = r;
 }
 
+static void reshape_planet(struct planet *p)
+{
+       p->size = sqrt(p->mass / 100);
+}
+
 void init_planet(const SDL_Surface *screen, struct planet *p)
 {
        p->speed.x = 0;
@@ -21,7 +28,7 @@ void init_planet(const SDL_Surface *screen, struct planet *p)
        p->pos.x = get_random() % screen->w;
        p->pos.y = get_random() % screen->h;
        p->mass = get_random() % 1000 + 100;
-       p->size = p->mass / 100;
+       reshape_planet(p);
        p->r = get_random() % 256;
        p->g = get_random() % 256;
        p->b = get_random() % 256;