indent rain.c
This commit is contained in:
parent
b52cf2b0a5
commit
408bb07151
1 changed files with 140 additions and 108 deletions
134
magic/src/rain.c
134
magic/src/rain.c
|
|
@ -48,7 +48,8 @@ void rain_click(magic_api *, int, int, SDL_Surface *, SDL_Surface *, int, int, S
|
||||||
static const int rain_SIZE = 30;
|
static const int rain_SIZE = 30;
|
||||||
static const int rain_AMOUNT = 200;
|
static const int rain_AMOUNT = 200;
|
||||||
|
|
||||||
enum {
|
enum
|
||||||
|
{
|
||||||
TOOL_rain,
|
TOOL_rain,
|
||||||
rain_NUM_TOOLS
|
rain_NUM_TOOLS
|
||||||
};
|
};
|
||||||
|
|
@ -58,12 +59,15 @@ static Mix_Chunk * rain_snd_effect[rain_NUM_TOOLS];
|
||||||
const char *rain_snd_filenames[rain_NUM_TOOLS] = {
|
const char *rain_snd_filenames[rain_NUM_TOOLS] = {
|
||||||
"rain.ogg",
|
"rain.ogg",
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *rain_icon_filenames[rain_NUM_TOOLS] = {
|
const char *rain_icon_filenames[rain_NUM_TOOLS] = {
|
||||||
"rain.png",
|
"rain.png",
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *rain_names[rain_NUM_TOOLS] = {
|
const char *rain_names[rain_NUM_TOOLS] = {
|
||||||
gettext_noop("Rain"),
|
gettext_noop("Rain"),
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *rain_descs[rain_NUM_TOOLS][2] = {
|
const char *rain_descs[rain_NUM_TOOLS][2] = {
|
||||||
{gettext_noop("Click to place a rain drop onto your picture."),
|
{gettext_noop("Click to place a rain drop onto your picture."),
|
||||||
gettext_noop("Click to cover your picture with rain drops."),},
|
gettext_noop("Click to cover your picture with rain drops."),},
|
||||||
|
|
@ -75,20 +79,14 @@ int rain_get_tool_count(magic_api * api);
|
||||||
SDL_Surface *rain_get_icon(magic_api * api, int which);
|
SDL_Surface *rain_get_icon(magic_api * api, int which);
|
||||||
char *rain_get_name(magic_api * api, int which);
|
char *rain_get_name(magic_api * api, int which);
|
||||||
char *rain_get_description(magic_api * api, int which, int mode);
|
char *rain_get_description(magic_api * api, int which, int mode);
|
||||||
static void do_rain_drop(void * ptr, int which, SDL_Surface * canvas, SDL_Surface * last,
|
static void do_rain_drop(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||||
int x, int y);
|
static void rain_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y);
|
||||||
static void rain_linecb(void * ptr, int which,
|
|
||||||
SDL_Surface * canvas, SDL_Surface * last,
|
|
||||||
int x, int y);
|
|
||||||
void rain_drag(magic_api * api, int which, SDL_Surface * canvas,
|
void rain_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 rain_click(magic_api * api, int which, int mode,
|
void rain_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 rain_release(magic_api * api, int which,
|
void rain_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 rain_shutdown(magic_api * api);
|
void rain_shutdown(magic_api * api);
|
||||||
void rain_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
void rain_set_color(magic_api * api, Uint8 r, Uint8 g, Uint8 b);
|
||||||
int rain_requires_colors(magic_api * api, int which);
|
int rain_requires_colors(magic_api * api, int which);
|
||||||
|
|
@ -96,22 +94,30 @@ void rain_switchin(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||||
void rain_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
void rain_switchout(magic_api * api, int which, int mode, SDL_Surface * canvas);
|
||||||
int rain_modes(magic_api * api, int which);
|
int rain_modes(magic_api * api, int which);
|
||||||
|
|
||||||
Uint32 rain_api_version(void) { return(TP_MAGIC_API_VERSION); }
|
Uint32 rain_api_version(void)
|
||||||
|
{
|
||||||
|
return (TP_MAGIC_API_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
//Checks if a a pixel is inside a raindrop shape centered on the origin
|
//Checks if a a pixel is inside a raindrop shape centered on the origin
|
||||||
static int rain_inRainShape(double x, double y, double r){
|
static int rain_inRainShape(double x, double y, double r)
|
||||||
if ( sqrt( x*x + y*y ) < ( r * pow( cos( atan2(x,y) ), 10.0) ) ){
|
{
|
||||||
|
if (sqrt(x * x + y * y) < (r * pow(cos(atan2(x, y)), 10.0)))
|
||||||
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int rain_init(magic_api * api){
|
int rain_init(magic_api * api)
|
||||||
|
{
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
char fname[1024];
|
char fname[1024];
|
||||||
|
|
||||||
//Load sounds
|
//Load sounds
|
||||||
for (i = 0; i < rain_NUM_TOOLS; i++){
|
for (i = 0; i < rain_NUM_TOOLS; i++)
|
||||||
|
{
|
||||||
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, rain_snd_filenames[i]);
|
snprintf(fname, sizeof(fname), "%s/sounds/magic/%s", api->data_directory, rain_snd_filenames[i]);
|
||||||
rain_snd_effect[i] = Mix_LoadWAV(fname);
|
rain_snd_effect[i] = Mix_LoadWAV(fname);
|
||||||
}
|
}
|
||||||
|
|
@ -119,73 +125,90 @@ int rain_init(magic_api * api){
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int rain_get_tool_count(magic_api * api ATTRIBUTE_UNUSED){
|
int rain_get_tool_count(magic_api * api ATTRIBUTE_UNUSED)
|
||||||
|
{
|
||||||
return (rain_NUM_TOOLS);
|
return (rain_NUM_TOOLS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load our icons:
|
// Load our icons:
|
||||||
SDL_Surface * rain_get_icon(magic_api * api, int which){
|
SDL_Surface *rain_get_icon(magic_api * api, int which)
|
||||||
|
{
|
||||||
char fname[1024];
|
char fname[1024];
|
||||||
|
|
||||||
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, rain_icon_filenames[which]);
|
snprintf(fname, sizeof(fname), "%simages/magic/%s", api->data_directory, rain_icon_filenames[which]);
|
||||||
return (IMG_Load(fname));
|
return (IMG_Load(fname));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return our names, localized:
|
// Return our names, localized:
|
||||||
char * rain_get_name(magic_api * api ATTRIBUTE_UNUSED, int which){
|
char *rain_get_name(magic_api * api ATTRIBUTE_UNUSED, int which)
|
||||||
|
{
|
||||||
return (strdup(gettext_noop(rain_names[which])));
|
return (strdup(gettext_noop(rain_names[which])));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return our descriptions, localized:
|
// Return our descriptions, localized:
|
||||||
char * rain_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode){
|
char *rain_get_description(magic_api * api ATTRIBUTE_UNUSED, int which, int mode)
|
||||||
|
{
|
||||||
return (strdup(gettext_noop(rain_descs[which][mode - 1])));
|
return (strdup(gettext_noop(rain_descs[which][mode - 1])));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do the effect:
|
// Do the effect:
|
||||||
static void do_rain_drop(void * ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas, SDL_Surface * last ATTRIBUTE_UNUSED,
|
static void do_rain_drop(void *ptr, int which ATTRIBUTE_UNUSED, SDL_Surface * canvas,
|
||||||
int x, int y){
|
SDL_Surface * last ATTRIBUTE_UNUSED, int x, int y)
|
||||||
|
{
|
||||||
magic_api *api = (magic_api *) ptr;
|
magic_api *api = (magic_api *) ptr;
|
||||||
|
|
||||||
int xx, yy;
|
int xx, yy;
|
||||||
Uint8 r, g, b;
|
Uint8 r, g, b;
|
||||||
|
|
||||||
for (yy = y - rain_SIZE/2; yy < y + rain_SIZE/2; yy++){
|
for (yy = y - rain_SIZE / 2; yy < y + rain_SIZE / 2; yy++)
|
||||||
for (xx = x - rain_SIZE; xx < x + rain_SIZE; xx++){
|
{
|
||||||
if (rain_inRainShape(xx - x, yy - y + rain_SIZE/2, rain_SIZE)){
|
for (xx = x - rain_SIZE; xx < x + rain_SIZE; xx++)
|
||||||
|
{
|
||||||
|
if (rain_inRainShape(xx - x, yy - y + rain_SIZE / 2, rain_SIZE))
|
||||||
|
{
|
||||||
//api->rgbtohsv(rain_r, rain_g, rain_b, &h, &s, &v);
|
//api->rgbtohsv(rain_r, rain_g, rain_b, &h, &s, &v);
|
||||||
//api->hsvtorgb(h, s, rain_weights[(yy-y)*((rain_SIZE*2) -1)+(xx-x)], &r, &g, &b);
|
//api->hsvtorgb(h, s, rain_weights[(yy-y)*((rain_SIZE*2) -1)+(xx-x)], &r, &g, &b);
|
||||||
SDL_GetRGB(api->getpixel(canvas, xx, yy), canvas->format, &r, &g, &b);
|
SDL_GetRGB(api->getpixel(canvas, xx, yy), canvas->format, &r, &g, &b);
|
||||||
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, clamp(0, r - 50, 255),
|
api->putpixel(canvas, xx, yy, SDL_MapRGB(canvas->format, clamp(0, r - 50, 255),
|
||||||
clamp(0, g - 50, 255),
|
clamp(0, g - 50, 255), clamp(0, b + 200, 255)));
|
||||||
clamp(0, b + 200, 255)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rain_linecb(void * ptr, int which,
|
static void rain_linecb(void *ptr, int which, SDL_Surface * canvas, SDL_Surface * last, int x, int y)
|
||||||
SDL_Surface * canvas, SDL_Surface * last,
|
|
||||||
int x, int y)
|
|
||||||
{
|
{
|
||||||
magic_api *api = (magic_api *) ptr;
|
magic_api *api = (magic_api *) ptr;
|
||||||
SDL_Rect rect;
|
SDL_Rect rect;
|
||||||
|
|
||||||
if (rand() % 10 == 0) {
|
if (rand() % 10 == 0)
|
||||||
|
{
|
||||||
rain_click(api, which, MODE_PAINT, canvas, last,
|
rain_click(api, which, MODE_PAINT, canvas, last,
|
||||||
x + (rand() % rain_SIZE * 2) - rain_SIZE,
|
x + (rand() % rain_SIZE * 2) - rain_SIZE, y + (rand() % rain_SIZE * 2) - rain_SIZE, &rect);
|
||||||
y + (rand() % rain_SIZE * 2) - rain_SIZE,
|
|
||||||
&rect);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Affect the canvas on drag:
|
// Affect the canvas on drag:
|
||||||
void rain_drag(magic_api * api, int which, SDL_Surface * canvas,
|
void rain_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){
|
{
|
||||||
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, rain_linecb);
|
api->line((void *)api, which, canvas, last, ox, oy, x, y, 1, rain_linecb);
|
||||||
|
|
||||||
if (ox > x) { int tmp = ox; ox = x; x = tmp; }
|
if (ox > x)
|
||||||
if (oy > y) { int tmp = oy; oy = y; y = tmp; }
|
{
|
||||||
|
int tmp = ox;
|
||||||
|
|
||||||
|
ox = x;
|
||||||
|
x = tmp;
|
||||||
|
}
|
||||||
|
if (oy > y)
|
||||||
|
{
|
||||||
|
int tmp = oy;
|
||||||
|
|
||||||
|
oy = y;
|
||||||
|
y = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
update_rect->x = ox - rain_SIZE * 2;
|
update_rect->x = ox - rain_SIZE * 2;
|
||||||
update_rect->y = oy - rain_SIZE * 2;
|
update_rect->y = oy - rain_SIZE * 2;
|
||||||
|
|
@ -195,10 +218,11 @@ void rain_drag(magic_api * api, int which, SDL_Surface * canvas,
|
||||||
|
|
||||||
// Affect the canvas on click:
|
// Affect the canvas on click:
|
||||||
void rain_click(magic_api * api, int which, int mode,
|
void rain_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){
|
{
|
||||||
|
|
||||||
if (mode == MODE_PAINT){
|
if (mode == MODE_PAINT)
|
||||||
|
{
|
||||||
do_rain_drop(api, which, canvas, last, x, y);
|
do_rain_drop(api, which, canvas, last, x, y);
|
||||||
|
|
||||||
update_rect->x = x - rain_SIZE;
|
update_rect->x = x - rain_SIZE;
|
||||||
|
|
@ -207,10 +231,14 @@ void rain_click(magic_api * api, int which, int mode,
|
||||||
update_rect->h = rain_SIZE * 2;
|
update_rect->h = rain_SIZE * 2;
|
||||||
|
|
||||||
api->playsound(rain_snd_effect[which], (x * 255) / canvas->w, 255);
|
api->playsound(rain_snd_effect[which], (x * 255) / canvas->w, 255);
|
||||||
}else{
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<rain_AMOUNT; i++){
|
|
||||||
|
for (i = 0; i < rain_AMOUNT; i++)
|
||||||
|
{
|
||||||
do_rain_drop(api, which, canvas, last, rand() % canvas->w, rand() % canvas->h);
|
do_rain_drop(api, which, canvas, last, rand() % canvas->w, rand() % canvas->h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -235,15 +263,19 @@ void rain_shutdown(magic_api * api ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
//Clean up sounds
|
//Clean up sounds
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<rain_NUM_TOOLS; i++){
|
|
||||||
if(rain_snd_effect[i] != NULL){
|
for (i = 0; i < rain_NUM_TOOLS; i++)
|
||||||
|
{
|
||||||
|
if (rain_snd_effect[i] != NULL)
|
||||||
|
{
|
||||||
Mix_FreeChunk(rain_snd_effect[i]);
|
Mix_FreeChunk(rain_snd_effect[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record the color from Tux Paint:
|
// Record the color from Tux Paint:
|
||||||
void rain_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED, Uint8 b ATTRIBUTE_UNUSED)
|
void rain_set_color(magic_api * api ATTRIBUTE_UNUSED, Uint8 r ATTRIBUTE_UNUSED, Uint8 g ATTRIBUTE_UNUSED,
|
||||||
|
Uint8 b ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -254,11 +286,13 @@ int rain_requires_colors(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_U
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void rain_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
void rain_switchin(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||||
|
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void rain_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED, SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
void rain_switchout(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED, int mode ATTRIBUTE_UNUSED,
|
||||||
|
SDL_Surface * canvas ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -266,5 +300,3 @@ int rain_modes(magic_api * api ATTRIBUTE_UNUSED, int which ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
return (MODE_FULLSCREEN | MODE_PAINT);
|
return (MODE_FULLSCREEN | MODE_PAINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue