]> git.itanic.dy.fi Git - sdl-planets/commitdiff
Make planet initialization independent from the screen size
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 20 Mar 2010 10:23:05 +0000 (12:23 +0200)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Sat, 20 Mar 2010 10:42:33 +0000 (12:42 +0200)
Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
main.c
planet.c
planet.h

diff --git a/main.c b/main.c
index 6d983d5f439e187381a40153a25c682c3e10c9df..85d43562e23445483ae7c72821d6654d494dedbb 100644 (file)
--- a/main.c
+++ b/main.c
@@ -36,12 +36,12 @@ static void loop(SDL_Surface *screen, int num_of_planets)
        init_camera(&camera);
 
        planet = malloc(sizeof(*planet));
-       init_planet(screen, planet);
+       init_planet(planet);
 
        for (i = 1; i < num_of_planets; i++) {
                struct planet *new_planet;
                new_planet = malloc(sizeof(*planet));
-               init_planet(screen, new_planet);
+               init_planet(new_planet);
                list_add(&new_planet->list, &planet->list);
        }
 
index 3a158dc4125cf2ca3fb622786b211e1180e34d9a..b2931fe356255fb1098d782fe624f5dbbb02092f 100644 (file)
--- a/planet.c
+++ b/planet.c
@@ -21,12 +21,12 @@ static void reshape_planet(struct planet *p)
        p->size = pow(p->mass / 100, 1 / 3.0);
 }
 
-void init_planet(const SDL_Surface *screen, struct planet *p)
+void init_planet(struct planet *p)
 {
        p->speed.x = 0;
        p->speed.y = 0;
-       p->pos.x = get_random() % screen->w;
-       p->pos.y = get_random() % screen->h;
+       p->pos.x = (signed)(get_random() % 1000) - 500;
+       p->pos.y = (signed)(get_random() % 1000) - 500;
        p->mass = get_random() % 1000 + 100;
        reshape_planet(p);
        p->r = get_random() % 256;
index f8a464cd4626798f947264e92d28a4c5f713d361..77d775201792fb5282cc4fd74a0d3568b585f980 100644 (file)
--- a/planet.h
+++ b/planet.h
@@ -19,7 +19,7 @@ struct planet {
 
 #define list_to_planet(list_head) container_of((list_head), struct planet, list)
 
-void init_planet(const SDL_Surface *screen, struct planet *p);
+void init_planet(struct planet *p);
 void draw_planet(SDL_Surface *screen, struct planet *p, const struct camera *);
 int gravitize_planets(struct planet *a, struct planet *b, const double time);
 struct planet *merge_planets(struct planet *a, struct planet *b);