-
Notifications
You must be signed in to change notification settings - Fork 3
/
esideexplosion.cpp
109 lines (82 loc) · 1.76 KB
/
esideexplosion.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
#include "esideexplosion.h"
bool ESideExplosion::finished_init = false;
ZSDL_Surface ESideExplosion::normal_img[7];
ESideExplosion::ESideExplosion(ZTime *ztime_, int x_, int y_, double size_, int type_) : ZEffect(ztime_)
{
double &the_time = ztime->ztime;
int speed;
if(!finished_init)
{
killme = true;
return;
}
speed = 20 + (rand() % 10);
ex = x_ + (20 - (rand() % 40));
ey = y_ + (20 - (rand() % 40));
float mag;
dx = ex - x_;
dy = ey - y_;
mag = sqrt((dx * dx) + (dy * dy));
init_time = the_time;
dx /= mag;
dy /= mag;
dx *= speed;
dy *= speed;
render_i = 0;
next_render_time = init_time + 0.13;
x = sx = x_ - 16;
y = sy = y_ - 16;
size = size_;
type = type_;
switch(type)
{
case ESIDEEXPLOSION_NORMAL:
render_img = normal_img;
break;
default:
killme = true;
break;
}
}
void ESideExplosion::Init()
{
int i;
char filename_c[500];
for(i=0;i<7;i++)
{
sprintf(filename_c, "assets/other/explosions/side_explosion_n%02d.png", i);
normal_img[i].LoadBaseImage(filename_c);
}
finished_init = true;
}
void ESideExplosion::Process()
{
double &the_time = ztime->ztime;
if(killme) return;
if(the_time >= next_render_time)
{
render_i++;
if(render_i>=7)
{
killme = true;
return;
}
next_render_time = the_time + 0.13;
}
//move
{
x = sx + (dx * (the_time - init_time));
y = sy + (dy * (the_time - init_time));
}
}
void ESideExplosion::DoRender(ZMap &zmap, SDL_Surface *dest)
{
SDL_Rect from_rect, to_rect;
//SDL_Surface *surface;
if(killme) return;
//surface = render_img[render_i].GetImage(size);
render_img[render_i].SetSize(size);
zmap.RenderZSurface(&render_img[render_i], x, y);
//if(zmap.GetBlitInfo( surface, x, y, from_rect, to_rect))
// SDL_BlitSurface( surface, &from_rect, dest, &to_rect);
}