1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
/*
* Copyright 1994-2012 Olivier Girondel
*
* This file is part of lebiniou.
*
* lebiniou is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* lebiniou is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with lebiniou. If not, see <http://www.gnu.org/licenses/>.
*/
#include "translation.h"
u_long id = 1071318964;
u_long options = BE_DISPLACE;
char dname[] = "Big half wheel";
char desc[] = "Translation effect";
/* Pour garder le centre de la translation bien visible dans le screen */
#define SHIFT_X (WIDTH / 10)
#define SHIFT_Y (HEIGHT / 10)
static Translation_t *t_bighalfwheel = NULL;
static int cx, cy;
const float q = 3.14159265399 / 2;
/* TODO check against original cthugha --oliv3 */
const float p = 45.0 / 180.0 * M_PI;
static Map_t
cth_bighalfwheel(u_short i, u_short j)
{
int dx, dy;
Map_t m;
if (j==0 || j == HEIGHT) {
dx = (float)(cx - i) * 0.75;
dy = cy - j;
} else {
int dist;
float ang;
dist = sqrt((i-cx)*(i-cx) + (j-cy)*(j-cy));
if (i==cx) {
if (j>cx)
ang = q;
else
ang = -q;
} else
ang = atanf((float)(j-cy)/(i-cx));
if (i<cx)
ang += M_PI;
if (dist < HEIGHT) {
dx = ceil(-sinf(ang-p)*dist/10.0);
dy = ceil(cosf(ang-p)*dist/10.0);
} else {
if (i<cx)
dx = 3;
else
dx = -3;
dy = 0;
}
if (i==0 || i==WIDTH) {
dx = cx - i;
dy = (float)(cy - j) * 0.75;
}
}
/* return abs(i+dx + ((j+dy)*WIDTH)) % BUFFSIZE; */
m.map_x = abs((i+dx) % WIDTH);
m.map_y = abs((j+dy) % HEIGHT);
return m;
}
static void
init_params()
{
cx = b_rand_int_range(SHIFT_X, (MAXX - SHIFT_X));
cy = b_rand_int_range(SHIFT_Y, (MAXY - SHIFT_Y));
}
void
on_switch_on()
{
Translation_batch_init(t_bighalfwheel);
}
void
create(__attribute__ ((unused)) Context_t *ctx)
{
t_bighalfwheel = Translation_new(&cth_bighalfwheel, &init_params);
}
void
destroy(__attribute__ ((unused)) Context_t *ctx)
{
Translation_delete(t_bighalfwheel);
}
void
run(Context_t *ctx)
{
Translation_run(t_bighalfwheel, ctx);
}
#ifndef EVT_DAWA
#ifdef HAVE_SDL_H
u_char
on_SDL_Event(SDL_Event *e)
{
if (key(e, SDLK_n)) {
on_switch_on();
return 1;
}
return 0;
}
#endif /* HAVE_SDL_H */
#endif
|