forked from erezsh/zodengine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathetrack.cpp
More file actions
180 lines (155 loc) · 2.92 KB
/
Copy pathetrack.cpp
File metadata and controls
180 lines (155 loc) · 2.92 KB
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include "etrack.h"
bool ETrack::finished_init = false;
ZSDL_Surface ETrack::track_img[MAX_ETRACK_TYPES][MAX_PLANET_TYPES][MAX_ANGLE_TYPES][3];
ETrack::ETrack(ZTime *ztime_, int cx_, int cy_, int dir_, int type_, int p_, bool lay1, bool lay2) : ZEffect(ztime_)
{
double &the_time = ztime->ztime;
if(!finished_init)
{
killme = true;
return;
}
start_time = the_time + (0.1 * (rand()%10));
cx = cx_;
cy = cy_;
dir = dir_;
type = type_;
p = p_;
if(type<0) type=0;
if(type>=MAX_ETRACK_TYPES) type=0;
if(p<0) p=0;
if(p>=MAX_PLANET_TYPES) p=0;
if(dir<0) dir=0;
if(dir>=MAX_ANGLE_TYPES) dir=0;
lay_track[0] = lay1;
lay_track[1] = lay2;
ti = 0;
if(!track_img[type][p][dir][ti].GetBaseSurface())
{
killme = true;
return;
}
SetTrackCoords(cx, cy, dir, x, y);
}
void ETrack::Init()
{
int i,j,k,l;
char filename_c[500];
for(i=0;i<MAX_ETRACK_TYPES;i++)
for(j=0;j<MAX_PLANET_TYPES;j++)
{
if(j==CITY) continue;
if(i==ET_JEEP && j!=DESERT) continue;
for(k=0;k<4;k++)
for(l=0;l<3;l++)
{
sprintf(filename_c, "assets/units/vehicles/track_effects/%s_track_%s_r%03d_n%02d.png",
etrack_type_string[i].c_str(),
planet_type_string[j].c_str(),
ROTATION[k],
l);
track_img[i][j][k][l].LoadBaseImage(filename_c);
track_img[i][j][k+4][l] = track_img[i][j][k][l];
}
}
finished_init = true;
}
void ETrack::Process()
{
double &the_time = ztime->ztime;
double delta;
if(killme) return;
delta = the_time - start_time;
if(delta >= 3.9) killme = true;
else if(delta >= 3.6) ti = 2;
else if(delta >= 3.3) ti = 1;
else ti = 0;
}
void ETrack::DoPreRender(ZMap &zmap, SDL_Surface *dest)
{
if(killme) return;
for(int i=0;i<2;i++)
if(lay_track[i])
zmap.RenderZSurface(&track_img[type][p][dir][ti], x[i], y[i], false, true);
}
void ETrack::SetTrackCoords(int cx_, int cy_, int dir_, int *x_, int *y_)
{
switch(dir_)
{
case 0: //0
x_[0]=x_[1]= cx_-15;
y_[0]=cy_-6;
y_[1]=cy_+6;
y_[0]+=4;
y_[1]+=4;
break;
case 4: //180
x_[0]=x_[1]=cx_+17;
y_[0]=cy_-6;
y_[1]=cy_+6;
y_[0]+=4;
y_[1]+=4;
break;
case 2: //90
y_[0]=y_[1]=cy_+15;
x_[0]=cx_-8;
x_[1]=cx_+8;
break;
case 6: //270
y_[0]=y_[1]=cy_-11;
x_[0]=cx_-8;
x_[1]=cx_+8;
break;
case 1: //45
x_[0]=-14;
y_[0]=4;
x_[1]=-y_[0];
y_[1]=-x_[0];
x_[0]+=cx_;
x_[1]+=cx_;
y_[0]+=(cy_+3);
y_[1]+=(cy_+3);
break;
case 5: //225
x_[0]=14;
y_[0]=-4;
x_[1]=-y_[0];
y_[1]=-x_[0];
x_[0]+=(cx_-1);
x_[1]+=(cx_-1);
y_[0]+=(cy_+4);
y_[1]+=(cy_+4);
break;
case 3: //135
x_[0]=14;
y_[0]=4;
x_[1]=y_[0];
y_[1]=x_[0];
x_[0]+=(cx_+1);
x_[1]+=(cx_+1);
y_[0]+=(cy_+4);
y_[1]+=(cy_+4);
break;
case 7: //315
x_[0]=-14;
y_[0]=-4;
x_[1]=y_[0];
y_[1]=x_[0];
x_[0]+=cx_;
x_[1]+=cx_;
y_[0]+=(cy_+3);
y_[1]+=(cy_+3);
break;
default:
x_[0]=x_[1]=cx_;
y_[0]=y_[1]=cy_;
break;
}
int x_r, y_r;
x_r=rand()%2;
y_r=rand()%2;
x_[0]+=x_r;
x_[1]+=x_r;
y_[0]+=y_r;
y_[1]+=y_r;
}