indent tornado.c

This commit is contained in:
Bill Kendrick 2017-10-15 11:51:13 -07:00
parent cf3173690d
commit 011f7f27c1

View file

@ -40,19 +40,21 @@
/* Our globals: */ /* Our globals: */
enum { SIDE_LEFT, SIDE_RIGHT }; enum
enum { LEAFSIDE_RIGHT_DOWN, { SIDE_LEFT, SIDE_RIGHT };
enum
{ LEAFSIDE_RIGHT_DOWN,
LEAFSIDE_LEFT_DOWN, LEAFSIDE_LEFT_DOWN,
LEAFSIDE_RIGHT_UP, LEAFSIDE_RIGHT_UP,
LEAFSIDE_LEFT_UP }; LEAFSIDE_LEFT_UP
};
static Mix_Chunk /* * tornado_click_snd, */ * tornado_release_snd; static Mix_Chunk /* * tornado_click_snd, */ * tornado_release_snd;
static Uint8 tornado_r, tornado_g, tornado_b; static Uint8 tornado_r, tornado_g, tornado_b;
static int tornado_min_x, tornado_max_x, tornado_bottom_x, tornado_bottom_y; static int tornado_min_x, tornado_max_x, tornado_bottom_x, tornado_bottom_y;
static int tornado_side_first; static int tornado_side_first;
static int tornado_side_decided; static int tornado_side_decided;
static SDL_Surface * tornado_base, * tornado_cloud, static SDL_Surface *tornado_base, *tornado_cloud, *tornado_cloud_colorized;
* tornado_cloud_colorized;
static int top_w; static int top_w;
/* Local function prototypes: */ /* Local function prototypes: */
@ -62,12 +64,10 @@ typedef struct
float x, y; float x, y;
} Point2D; } Point2D;
static void tornado_predrag(magic_api * api, SDL_Surface * canvas, static void tornado_predrag(magic_api * api, SDL_Surface * canvas, SDL_Surface * last, int ox, int oy, int x, int y);
SDL_Surface * last, int ox, int oy, int x, int y);
static void tornado_drawbase(magic_api * api, SDL_Surface * canvas); static void tornado_drawbase(magic_api * api, SDL_Surface * canvas);
static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas, SDL_Surface * last, static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas, SDL_Surface * last,
int top_x, int top_y, int minx, int maxx, int top_x, int top_y, int minx, int maxx, int bottom_x, int bottom_y, int final);
int bottom_x, int bottom_y, int final);
static void tornado_drawtornado(magic_api * api, SDL_Surface * canvas, int x, int y); static void tornado_drawtornado(magic_api * api, SDL_Surface * canvas, int x, int y);
static Point2D tornado_PointOnCubicBezier(Point2D * cp, float t); static Point2D tornado_PointOnCubicBezier(Point2D * cp, float t);
static void tornado_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve); static void tornado_ComputeBezier(Point2D * cp, int numberOfPoints, Point2D * curve);
@ -87,14 +87,11 @@ char * tornado_get_description(magic_api * api, int which, int mode);
void tornado_drag(magic_api * api, int which, SDL_Surface * canvas, void tornado_drag(magic_api * api, int which, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect);
SDL_Rect * update_rect);
void tornado_click(magic_api * api, int which, int mode, void tornado_click(magic_api * api, int which, int mode,
SDL_Surface * canvas, SDL_Surface * last, SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
int x, int y, SDL_Rect * update_rect);
void tornado_release(magic_api * api, int which, void tornado_release(magic_api * api, int which,
SDL_Surface * canvas, SDL_Surface * last, SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect);
int x, int y, SDL_Rect * update_rect);
void tornado_shutdown(magic_api * api); void tornado_shutdown(magic_api * api);
void tornado_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b); void tornado_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
@ -105,7 +102,10 @@ int tornado_modes(magic_api * api, int which);
Uint32 tornado_api_version(void) { return(TP_MAGIC_API_VERSION); } Uint32 tornado_api_version(void)
{
return (TP_MAGIC_API_VERSION);
}
// No setup required: // No setup required:
@ -119,16 +119,13 @@ int tornado_init(magic_api * api)
tornado_click_snd = Mix_LoadWAV(fname); tornado_click_snd = Mix_LoadWAV(fname);
*/ */
snprintf(fname, sizeof(fname), "%s/sounds/magic/tornado_release.ogg", snprintf(fname, sizeof(fname), "%s/sounds/magic/tornado_release.ogg", api->data_directory);
api->data_directory);
tornado_release_snd = Mix_LoadWAV(fname); tornado_release_snd = Mix_LoadWAV(fname);
snprintf(fname, sizeof(fname), "%s/images/magic/tornado_base.png", snprintf(fname, sizeof(fname), "%s/images/magic/tornado_base.png", api->data_directory);
api->data_directory);
tornado_base = IMG_Load(fname); tornado_base = IMG_Load(fname);
snprintf(fname, sizeof(fname), "%s/images/magic/tornado_cloud.png", snprintf(fname, sizeof(fname), "%s/images/magic/tornado_cloud.png", api->data_directory);
api->data_directory);
tornado_cloud = IMG_Load(fname); tornado_cloud = IMG_Load(fname);
return (1); return (1);
@ -145,8 +142,7 @@ SDL_Surface * tornado_get_icon(magic_api * api, int which ATTRIBUTE_UNUSED)
{ {
char fname[1024]; char fname[1024];
snprintf(fname, sizeof(fname), "%s/images/magic/tornado.png", snprintf(fname, sizeof(fname), "%s/images/magic/tornado.png", api->data_directory);
api->data_directory);
return (IMG_Load(fname)); return (IMG_Load(fname));
} }
@ -199,8 +195,7 @@ static void tornado_predrag(magic_api * api ATTRIBUTE_UNUSED, SDL_Surface * canv
} }
void tornado_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, void tornado_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
SDL_Surface * last, int ox, int oy, int x, int y, SDL_Surface * last, int ox, int oy, int x, int y, SDL_Rect * update_rect)
SDL_Rect * update_rect)
{ {
tornado_predrag(api, canvas, last, ox, oy, x, y); tornado_predrag(api, canvas, last, ox, oy, x, y);
@ -213,8 +208,7 @@ void tornado_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * can
/* Draw the base and the stalk (low-quality) for now: */ /* Draw the base and the stalk (low-quality) for now: */
tornado_drawstalk(api, canvas, last, tornado_drawstalk(api, canvas, last,
x, y, tornado_min_x, tornado_max_x, x, y, tornado_min_x, tornado_max_x, tornado_bottom_x, tornado_bottom_y, !(api->button_down()));
tornado_bottom_x, tornado_bottom_y, !(api->button_down()));
tornado_drawbase(api, canvas); tornado_drawbase(api, canvas);
@ -226,8 +220,7 @@ void tornado_drag(magic_api * api, int which ATTRIBUTE_UNUSED, SDL_Surface * can
// Affect the canvas on click: // Affect the canvas on click:
void tornado_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED, void tornado_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
int x, int y, SDL_Rect * update_rect)
{ {
tornado_min_x = x; tornado_min_x = x;
tornado_max_x = x; tornado_max_x = x;
@ -246,8 +239,7 @@ void tornado_click(magic_api * api, int which, int mode ATTRIBUTE_UNUSED,
// Affect the canvas on release: // Affect the canvas on release:
void tornado_release(magic_api * api, int which ATTRIBUTE_UNUSED, void tornado_release(magic_api * api, int which ATTRIBUTE_UNUSED,
SDL_Surface * canvas, SDL_Surface * last, SDL_Surface * canvas, SDL_Surface * last, int x, int y, SDL_Rect * update_rect)
int x, int y, SDL_Rect * update_rect)
{ {
/* Don't let tornado be too low compared to base: */ /* Don't let tornado be too low compared to base: */
@ -267,9 +259,7 @@ void tornado_release(magic_api * api, int which ATTRIBUTE_UNUSED,
/* Draw high-quality stalk, and tornado: */ /* Draw high-quality stalk, and tornado: */
tornado_drawstalk(api, canvas, last, tornado_drawstalk(api, canvas, last, x, y, tornado_min_x, tornado_max_x, tornado_bottom_x, tornado_bottom_y, 1);
x, y, tornado_min_x, tornado_max_x,
tornado_bottom_x, tornado_bottom_y, 1);
tornado_drawtornado(api, canvas, x, y); tornado_drawtornado(api, canvas, x, y);
@ -312,17 +302,15 @@ static Uint32 tornado_mess(Uint32 pixel, SDL_Surface * canvas)
{ {
Uint8 r, g, b, a; Uint8 r, g, b, a;
float f = (float)rand() * 255 / RAND_MAX; float f = (float)rand() * 255 / RAND_MAX;
SDL_GetRGBA(pixel, canvas->format, &r, &g, &b, &a); SDL_GetRGBA(pixel, canvas->format, &r, &g, &b, &a);
return (SDL_MapRGBA(canvas->format, return (SDL_MapRGBA(canvas->format,
(tornado_r + r + (Uint8) f * 2) / 4, (tornado_r + r + (Uint8) f * 2) / 4,
(tornado_g + g + (Uint8)f * 2) / 4, (tornado_g + g + (Uint8) f * 2) / 4, (tornado_b + b + (Uint8) f * 2) / 4, a));
(tornado_b + b + (Uint8)f * 2) / 4,
a));
} }
static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas, SDL_Surface * last, static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas, SDL_Surface * last,
int top_x, int top_y, int minx, int maxx, int top_x, int top_y, int minx, int maxx, int bottom_x, int bottom_y, int final)
int bottom_x, int bottom_y, int final)
{ {
Point2D control_points[4]; Point2D control_points[4];
Point2D *curve; Point2D *curve;
@ -410,7 +398,9 @@ static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas, SDL_Surface
} }
else else
{ {
api->putpixel(canvas, p, dest.y, tornado_mess(api->getpixel(last, dest.x + (p - dest.x + rotation) % dest.w , dest.y), canvas)); api->putpixel(canvas, p, dest.y,
tornado_mess(api->getpixel(last, dest.x + (p - dest.x + rotation) % dest.w, dest.y),
canvas));
} }
} }
@ -418,7 +408,8 @@ static void tornado_drawstalk(magic_api * api, SDL_Surface * canvas, SDL_Surface
for (p = dest.x - dest.w * 20 / 100; p < dest.x + dest.w + dest.w * 20 / 100; p++) for (p = dest.x - dest.w * 20 / 100; p < dest.x + dest.w + dest.w * 20 / 100; p++)
{ {
if ((float)rand() * 100 / RAND_MAX < 5 && ((p < dest.x) || (p > dest.w))) if ((float)rand() * 100 / RAND_MAX < 5 && ((p < dest.x) || (p > dest.w)))
api->putpixel(canvas, p, dest.y, tornado_mess(api->getpixel(last, dest.x + (p - dest.x + rotation) % dest.w , dest.y), canvas)); api->putpixel(canvas, p, dest.y,
tornado_mess(api->getpixel(last, dest.x + (p - dest.x + rotation) % dest.w, dest.y), canvas));
} }
} }
@ -532,9 +523,7 @@ static void tornado_colorize_cloud(magic_api * api)
/* Create a surface to render into: */ /* Create a surface to render into: */
amask = ~(tornado_cloud->format->Rmask | amask = ~(tornado_cloud->format->Rmask | tornado_cloud->format->Gmask | tornado_cloud->format->Bmask);
tornado_cloud->format->Gmask |
tornado_cloud->format->Bmask);
tornado_cloud_colorized = tornado_cloud_colorized =
SDL_CreateRGBSurface(SDL_SWSURFACE, SDL_CreateRGBSurface(SDL_SWSURFACE,
@ -542,8 +531,7 @@ static void tornado_colorize_cloud(magic_api * api)
tornado_cloud->h, tornado_cloud->h,
tornado_cloud->format->BitsPerPixel, tornado_cloud->format->BitsPerPixel,
tornado_cloud->format->Rmask, tornado_cloud->format->Rmask,
tornado_cloud->format->Gmask, tornado_cloud->format->Gmask, tornado_cloud->format->Bmask, amask);
tornado_cloud->format->Bmask, amask);
/* Render the new cloud: */ /* Render the new cloud: */
@ -554,8 +542,7 @@ static void tornado_colorize_cloud(magic_api * api)
{ {
for (x = 0; x < tornado_cloud->w; x++) for (x = 0; x < tornado_cloud->w; x++)
{ {
SDL_GetRGBA(api->getpixel(tornado_cloud, x, y), SDL_GetRGBA(api->getpixel(tornado_cloud, x, y), tornado_cloud->format, &r, &g, &b, &a);
tornado_cloud->format, &r, &g, &b, &a);
api->putpixel(tornado_cloud_colorized, x, y, api->putpixel(tornado_cloud_colorized, x, y,
SDL_MapRGBA(tornado_cloud_colorized->format, SDL_MapRGBA(tornado_cloud_colorized->format,
@ -567,11 +554,13 @@ static void tornado_colorize_cloud(magic_api * api)
SDL_UnlockSurface(tornado_cloud); SDL_UnlockSurface(tornado_cloud);
} }
void tornado_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) void tornado_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
} }
void tornado_switchout(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED) void tornado_switchout(magic_api * api, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
SDL_Surface * canvas ATTRIBUTE_UNUSED)
{ {
api->stopsound(); api->stopsound();
} }