-
Notifications
You must be signed in to change notification settings - Fork 3
/
etankoil.cpp
117 lines (93 loc) · 1.58 KB
/
etankoil.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
#include "etankoil.h"
bool ETankOil::finished_init = false;
ZSDL_Surface ETankOil::tank_oil[3][3];
#define ETANKOIL_TIME 3.0
ETankOil::ETankOil(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_);
oil_i = rand()%3;
ni=0;
next_ni_time = the_time + ETANKOIL_TIME + ((rand()%10) * 0.1);
}
void ETankOil::Init()
{
char filename[500];
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
{
sprintf(filename, "assets/units/vehicles/tank_oil_%d_n%02d.png", i, j);
tank_oil[i][j].LoadBaseImage(filename);
}
finished_init = true;
}
void ETankOil::Process()
{
double &the_time = ztime->ztime;
if(killme) return;
if(the_time >= next_ni_time)
{
next_ni_time = the_time + ETANKOIL_TIME + ((rand()%10) * 0.1);
ni++;
if(ni>=3)
{
ni=0;
killme=true;
}
}
}
void ETankOil::DoPreRender(ZMap &zmap, SDL_Surface *dest)
{
ZSDL_Surface *render_img;
if(killme) return;
render_img = &tank_oil[oil_i][ni];
if(!render_img) return;
zmap.RenderZSurface(render_img, cx, cy, false, true);
}
void ETankOil::SetCoords(int cx_, int cy_, int direction_)
{
cx = cx_;
cy = cy_;
direction = direction_;
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+=5;
cx-=3;
cy-=3;
cx+=rand()%7;
cy+=rand()%7;
}