-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patherobotturrent.cpp
148 lines (113 loc) · 2.83 KB
/
erobotturrent.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
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
#include "erobotturrent.h"
bool ERobotTurrent::finished_init;
ZSDL_Surface ERobotTurrent::robot_flip[MAX_TEAM_TYPES][33];
ERobotTurrent::ERobotTurrent(ZTime *ztime_, int x_, int y_, int owner_, int max_horz, int max_vert) : ZEffect(ztime_)
{
double &the_time = ztime->ztime;
if(!finished_init)
{
killme = true;
return;
}
if(owner_ == NULL_TEAM)
{
printf("ERobotTurrent::owner == NULL_TEAM\n");
killme = true;
return;
}
owner = owner_;
//....
double lifetime;
lifetime = 3.5 + (0.1 * (rand() % 10));
render_i = 0;
size = 1.0;
//16x10
x = x_ + (2 - (rand() % 5));
y = y_ + (2 - (rand() % 5));
sx = x;
sy = y;
ex = x + (max_horz - (rand() % (max_horz + max_horz)));
ey = y + (max_vert - (rand() % (max_vert + max_vert)));
rise = 1.3 + (0.01 * (rand() % 200));
double mag;
dx = ex - sx;
dy = ey - sy;
mag = sqrt((dx * dx) + (dy * dy));
init_time = the_time;
final_time = init_time + lifetime;
dx /= lifetime;
dy /= lifetime;
next_render_i_time = the_time + 0.05;
}
void ERobotTurrent::Init()
{
int i, k;
char filename_c[500];
for(i=1;i<MAX_TEAM_TYPES;i++)
for(k=0;k<33;k++)
{
sprintf(filename_c, "assets/units/robots/die5_%s_n%02d.png", team_type_string[i].c_str(), k);
//robot_flip[i][k].LoadBaseImage(filename_c);
ZTeam::LoadZSurface(i, robot_flip[ZTEAM_BASE_TEAM][k], robot_flip[i][k], filename_c);
}
finished_init = true;
}
void ERobotTurrent::Process()
{
double &the_time = ztime->ztime;
if(killme) return;
if(the_time >= next_render_i_time)
{
render_i++;
if(the_time < final_time)
{
next_render_i_time = the_time + 0.05;
//keep us in the main loop if we are in the air
if(render_i > 7) render_i = 0;
}
else
{
next_render_i_time = the_time + 0.15;
//if we are past airtime go straight to
//the final part of the animimation
if(render_i < 8) render_i = 8;
}
if(render_i > 32)
{
killme = true;
return;
}
}
{
if(the_time < final_time)
{
double time_dif = (the_time - init_time);
double up_amount;
//move
x = sx + (dx * time_dif);
y = sy + (dy * time_dif);
size = -(rise / (final_time - init_time)) * (time_dif * time_dif) + rise * time_dif;
size += 1;
y -= (size-1) * 30;
}
else
{
//if there is a lot of lag
//sometimes we can't properly get back
//to size of 1 for the tail end of the animation
size = 1;
}
}
}
void ERobotTurrent::DoRender(ZMap &zmap, SDL_Surface *dest)
{
SDL_Rect from_rect, to_rect;
//SDL_Surface *surface;
if(killme) return;
//surface = robot_flip[owner][render_i].GetImage(size);
robot_flip[owner][render_i].SetSize(size);
//if(!surface) return;
zmap.RenderZSurface(&robot_flip[owner][render_i], x, y, false, true);
//if(zmap.GetBlitInfo( surface, x - (surface->w >> 1), y - (surface->h >> 1), from_rect, to_rect))
// SDL_BlitSurface( surface, &from_rect, dest, &to_rect);
}