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 trail_t *
makeTrail(float x0,float y0,float x1,float y1)31 makeTrail (float x0, float y0, float x1, float y1)
32 {
33   trail_t *trail = malloc (sizeof (trail_t));
34 
35   trail->next = NULL;
36   trail->alpha = 255;
37   trail->x0 = x0;
38   trail->y0 = y0;
39   trail->x1 = x1;
40   trail->y1 = y1;
41 
42   return trail;
43 }
44 
45 void
updateTrails(hero_t * hero,float msec)46 updateTrails (hero_t * hero, float msec)
47 {
48   trail_t *trail;
49   int delta;
50 
51   delta = (float) TRAILSTART / TRAILFADE * msec;
52   trail = hero->trail;
53   while (trail != NULL && trail->next != NULL)
54     {
55       trail->alpha -= delta;
56       if (trail->alpha <= 0)
57 	{
58 	  hero->trail = trail->next;
59 	  free (trail);
60 	  trail = hero->trail;
61 	}
62       else
63 	trail = trail->next;
64     }
65   if (trail != NULL)
66     {
67       trail->alpha -= delta;
68       if (trail->alpha <= 0)
69 	{
70 	  hero->trail = trail->next;
71 	  free (trail);
72 	  trail = hero->trail;
73 	}
74     }
75 
76   if (trail == NULL)
77     hero->trail = makeTrail (hero->x, hero->y, hero->x, hero->y);
78   else
79     trail->next = makeTrail (trail->x1, trail->y1, hero->x, hero->y);
80 }
81 
82 void
scrollTrails(hero_t * hero,float dy)83 scrollTrails (hero_t * hero, float dy)
84 {
85   trail_t *trail;
86 
87   trail = hero->trail;
88   while (trail != NULL)
89     {
90       trail->y1 += dy;
91       trail->y0 += dy;
92       trail = trail->next;
93     }
94 }
95 
96 void
drawTrail(data_t * gfx,trail_t * trail,int player)97 drawTrail (data_t * gfx, trail_t * trail, int player)
98 {
99   int x0, y0, x1, y1;
100   while (trail != NULL)
101     {
102       if (trail->y1 + 1 < BLOCKSIZE * (GRIDHEIGHT - 1) &&
103 	  trail->y0 + 1 < BLOCKSIZE * (GRIDHEIGHT - 1))
104 	{
105 	  x0 = trail->x0 + gfx->gameX + HEROSIZE / 2;
106 	  y0 = trail->y0 + gfx->gameY + HEROSIZE / 2;
107 	  x1 = trail->x1 + gfx->gameX + HEROSIZE / 2;
108 	  y1 = trail->y1 + gfx->gameY + HEROSIZE / 2;
109 	  switch (gblOps.trailMode)
110 	    {
111 	    case THINTRAIL:
112 	      JPB_drawLine (gfx->tcolorr[player], gfx->tcolorg[player],
113 			    gfx->tcolorb[player], trail->alpha, x0, y0, x1,
114 			    y1);
115 	      break;
116 	    case NORMALTRAIL:
117 	      JPB_drawLine (gfx->tcolorr[player], gfx->tcolorg[player],
118 			    gfx->tcolorb[player], trail->alpha, x0, y0, x1,
119 			    y1);
120 	      JPB_drawLine (gfx->tcolorr[player], gfx->tcolorg[player],
121 			    gfx->tcolorb[player], trail->alpha / 2, x0 - 1,
122 			    y0, x1 - 1, y1);
123 	      JPB_drawLine (gfx->tcolorr[player], gfx->tcolorg[player],
124 			    gfx->tcolorb[player], trail->alpha / 2, x0,
125 			    y0 + 1, x1, y1 + 1);
126 	      JPB_drawLine (gfx->tcolorr[player], gfx->tcolorg[player],
127 			    gfx->tcolorb[player], trail->alpha / 2, x0 + 1,
128 			    y0, x1 + 1, y1);
129 	      JPB_drawLine (gfx->tcolorr[player], gfx->tcolorg[player],
130 			    gfx->tcolorb[player], trail->alpha / 2, x0,
131 			    y0 - 1, x1, y1 - 1);
132 	      break;
133 	    case STRONGTRAIL:
134 	      JPB_drawLine (gfx->tcolorr[player], gfx->tcolorg[player],
135 			    gfx->tcolorb[player], trail->alpha, x0, y0, x1,
136 			    y1);
137 	      JPB_drawLine (gfx->tcolorr[player], gfx->tcolorg[player],
138 			    gfx->tcolorb[player], trail->alpha, x0 - 1, y0,
139 			    x1 - 1, y1);
140 	      JPB_drawLine (gfx->tcolorr[player], gfx->tcolorg[player],
141 			    gfx->tcolorb[player], trail->alpha, x0, y0 + 1,
142 			    x1, y1 + 1);
143 	      JPB_drawLine (gfx->tcolorr[player], gfx->tcolorg[player],
144 			    gfx->tcolorb[player], trail->alpha, x0 + 1, y0,
145 			    x1 + 1, y1);
146 	      JPB_drawLine (gfx->tcolorr[player], gfx->tcolorg[player],
147 			    gfx->tcolorb[player], trail->alpha / 2, x0,
148 			    y0 - 1, x1, y1 - 1);
149 	      break;
150 	    default:
151 	      break;
152 	    }
153 	}
154 
155       trail = trail->next;
156     }
157 }
158 
159 void
freeTrails(hero_t * hero)160 freeTrails (hero_t * hero)
161 {
162   trail_t *trail = hero->trail;
163   trail_t *last;
164   while (trail != NULL)
165     {
166       last = trail;
167       trail = trail->next;
168       free (last);
169     }
170 }
171