#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 *
GetNextPoint (void)
{
static SDL_Rect rect = {0, 0, WIDTH, HEIGHT};
- rect.x = (rect.x++) % WIDTH;
- rect.y = (rect.y++) % HEIGHT;
+ static int cur = 0;
+ int dx, dy;
+ int next;
+ next = (cur + 1) % (sizeof (points) / sizeof (SDL_Rect));
+ if (IS_CENTER (points[next].x, points[next].y, rect.x, rect.y))
+ {
+ cur = next;
+ next = (cur + 1) % (sizeof (points) / sizeof (SDL_Rect));
+ }
+ dx = (points[next].x > points[cur].x) ? 1 : -1;
+ dy = (points[next].y > points[cur].y) ? 1 : -1;
+ rect.x = (rect.x + dx) % WIDTH;
+ rect.y = (rect.y + dy) % HEIGHT;
return ▭
}