1 /*
2 * GNUjump
3 * =======
4 *
5 * Copyright (C) 2005-2008, Juan Pedro Bolivar Puente
6 *
7 * GNUjump is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * GNUjump is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21
22 #include "gnujump.h"
23 #include "effects.h"
24 #include "surface.h"
25 #include "sprite.h"
26 #include "tools.h"
27
28 extern L_gblOptions gblOps;
29
30 blur_t *
makeBlur(float x,float y,int angle,JPB_surfaceRot * pic)31 makeBlur (float x, float y, int angle, JPB_surfaceRot * pic)
32 {
33 blur_t *blur = malloc (sizeof (trail_t));
34
35 blur->next = NULL;
36 blur->alpha = BLURSTART;
37 blur->x = x;
38 blur->y = y;
39 blur->angle = angle;
40 blur->pic = pic;
41
42 return blur;
43 }
44
45 void
updateBlurs(hero_t * hero,float msec)46 updateBlurs (hero_t * hero, float msec)
47 {
48 blur_t *blur;
49 int falpha;
50 int delta;
51
52 delta = (float) BLURSTART / BLURFADE * msec;
53 blur = hero->blur;
54
55 while (blur != NULL && blur->next != NULL)
56 {
57 blur->alpha -= delta;
58 if (blur->alpha <= 0)
59 {
60 hero->blur = blur->next;
61 free (blur);
62 blur = hero->blur;
63 }
64 else
65 blur = blur->next;
66 }
67 if (blur != NULL)
68 {
69 blur->alpha -= delta;
70 if (blur->alpha <= 0)
71 {
72 hero->blur = blur->next;
73 free (blur);
74 blur = hero->blur;
75 }
76 }
77 if (blur != NULL)
78 falpha = blur->alpha;
79 else
80 falpha = 0;
81
82 if ((falpha > BLURGAP) || (hero->vx == 0 && hero->vy == 0))
83 return;
84
85 if (blur == NULL)
86 hero->blur =
87 makeBlur (hero->x, hero->y, hero->angle,
88 getFrameRot (&hero->sprite[hero->id], hero->dir));
89 else
90 blur->next =
91 makeBlur (hero->x, hero->y, hero->angle,
92 getFrameRot (&hero->sprite[hero->id], hero->dir));
93 }
94
95 void
scrollBlurs(hero_t * hero,float dy)96 scrollBlurs (hero_t * hero, float dy)
97 {
98 blur_t *blur;
99
100 blur = hero->blur;
101 while (blur != NULL)
102 {
103 blur->y += dy;
104 blur = blur->next;
105 }
106 }
107
108 void
drawBlur(data_t * gfx,blur_t * blur,int player)109 drawBlur (data_t * gfx, blur_t * blur, int player)
110 {
111 SDL_Rect dest;
112 int alpha;
113 /* In rotating surface, X and Y refer to the centre of the image */
114 while (blur != NULL)
115 {
116 if (blur->y < BLOCKSIZE * (GRIDHEIGHT) - HEROSIZE)
117 {
118 alpha = blur->pic->alpha;
119 blur->pic->alpha = blur->alpha * (float) gblOps.blur / MAXBLUR;
120 dest.x = blur->x + gfx->gameX - (blur->pic->w - HEROSIZE) / 2
121 + blur->pic->w / 2;
122 dest.y = blur->y + gfx->gameY - (blur->pic->h - HEROSIZE)
123 + blur->pic->h / 2;
124 JPB_PrintSurfaceRot (blur->pic, NULL, &dest, blur->angle);
125 blur->pic->alpha = alpha;
126 }
127 blur = blur->next;
128 }
129 }
130
131 void
freeBlurs(hero_t * hero)132 freeBlurs (hero_t * hero)
133 {
134 blur_t *blur = hero->blur;
135 blur_t *last;
136 while (blur != NULL)
137 {
138 last = blur;
139 blur = blur->next;
140 free (last);
141 }
142 }
143