#define WIDTH 800
#define HEIGHT 600
+#include <stdio.h>
+#include <stdlib.h>
#include <SDL.h>
#include <SDL_image.h>
#define IS_CENTER(cx, cy, x, y) \
((x + WIDTH/2 == cx) && (y + HEIGHT/2 == cy))
-SDL_Rect points[] = {
- {400, 300, 800, 600},
- {450, 350, 800, 600}
-};
+SDL_Rect *points;
+int psize;
+
+void
+ReadPoints (char *filename)
+{
+ FILE *file;
+ char *buffer;
+ char *next;
+ size_t len;
+ int i;
+ file = fopen (filename, "r");
+ fscanf (file, "%d\n", &psize);
+ points = malloc (sizeof (SDL_Rect) * psize);
+ if (points == NULL)
+ abort ();
+ buffer = NULL;
+ len = 0;
+ for (i = 0; i < psize; i++)
+ {
+ getline (&buffer, &len, file);
+ points[i].x = strtol (buffer, &next, 0);
+ points[i].y = strtol (next+1, NULL, 0);
+ }
+ fclose (file);
+}
SDL_Rect *
GetNextPoint (void)
static int x1, y1, x2, y2;
static int x, y;
int next;
- next = (cur + 1) % (sizeof (points) / sizeof (SDL_Rect));
+ next = (cur + 1) % psize;
if (IS_CENTER (points[next].x, points[next].y, rect.x, rect.y) || cur == -1)
{
cur = next;
- next = (cur + 1) % (sizeof (points) / sizeof (SDL_Rect));
+ next = (cur + 1) % psize;
err = 0;
swap = 0;
x1 = points[cur].x;
SDL_Surface *screen;
SDL_Surface *image;
SDL_Event event;
+ ReadPoints ("pro-gnu");
SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER);
screen = SDL_SetVideoMode (800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN);
image = IMG_Load ("/home/cascardo/fotos/debconf.jpg");
}
SDL_FreeSurface (image);
SDL_Quit ();
+ free (points);
return 0;
}