-
Notifications
You must be signed in to change notification settings - Fork 3
/
etankspark.cpp
122 lines (96 loc) · 1.69 KB
/
etankspark.cpp
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
#include "etankspark.h"
bool ETankSpark::finished_init = false;
ZSDL_Surface ETankSpark::tank_spark[6];
#define ETANKSPARK_TIME 0.1
ETankSpark::ETankSpark(ZTime *ztime_, int cx_, int cy_, int direction_) : ZEffect(ztime_)
{
double &the_time = ztime->ztime;
if(!finished_init)
{
killme = true;
return;
}
SetCoords(cx_, cy_, direction_);
ni_max = 36 + (rand()%25);
ni_i = 0;
ni = 0;
next_ni_time = the_time + ETANKSPARK_TIME;
}
void ETankSpark::Init()
{
char filename[500];
for(int i=0;i<6;i++)
{
sprintf(filename, "assets/units/vehicles/ground_spark_n%02d.png", i);
tank_spark[i].LoadBaseImage(filename);
}
finished_init = true;
}
void ETankSpark::Process()
{
double &the_time = ztime->ztime;
if(killme) return;
if(the_time >= next_ni_time)
{
next_ni_time = the_time + ETANKSPARK_TIME;
ni++;
ni_i++;
if(ni>=6) ni=0;
if(ni_i>=ni_max) killme=true;
}
}
void ETankSpark::DoPreRender(ZMap &zmap, SDL_Surface *dest)
{
ZSDL_Surface *render_img;
if(killme) return;
render_img = &tank_spark[ni];
if(!render_img) return;
zmap.RenderZSurface(render_img, cx, cy, false, true);
}
void ETankSpark::SetCoords(int cx_, int cy_, int dir_)
{
cx = cx_;
cy = cy_;
direction = dir_;
//if(tank_spark[0].GetBaseSurface())
//{
// cx -= tank_spark[0].GetBaseSurface()->w >> 1;
// cy -= tank_spark[0].GetBaseSurface()->h;
//}
switch(direction)
{
case R0:
cx-=5;
break;
case R180:
cx+=5;
break;
case R90:
cy+=5;
break;
case R270:
cy-=5;
break;
case R45:
cx-=4;
cy+=4;
break;
case R135:
cx+=4;
cy+=4;
break;
case R225:
cx+=4;
cy-=4;
break;
case R315:
cx-=4;
cy-=4;
break;
}
cy+=3;
cx-=5;
cy-=5;
cx+=rand()%11;
cy+=rand()%11;
}