~ubuntu-branches/debian/sid/astromenace/sid

« back to all changes in this revision

Viewing changes to AstroMenaceSource/Object3D/SpaceObject/SpaceObject.cpp

  • Committer: Package Import Robot
  • Author(s): Boris Pek
  • Date: 2013-04-09 02:04:25 UTC
  • Revision ID: package-import@ubuntu.com-20130409020425-a7fl9xk4diamw6di
Tags: upstream-1.3.1+repack
Import upstream version 1.3.1+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/************************************************************************************
 
2
 
 
3
        AstroMenace (Hardcore 3D space shooter with spaceship upgrade possibilities)
 
4
        Copyright © 2006-2012 Michael Kurinnoy, Viewizard
 
5
 
 
6
 
 
7
        AstroMenace is free software: you can redistribute it and/or modify
 
8
        it under the terms of the GNU General Public License as published by
 
9
        the Free Software Foundation, either version 3 of the License, or
 
10
        (at your option) any later version.
 
11
 
 
12
        AstroMenace is distributed in the hope that it will be useful,
 
13
        but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
15
        GNU General Public License for more details.
 
16
 
 
17
        You should have received a copy of the GNU General Public License
 
18
        along with AstroMenace. If not, see <http://www.gnu.org/licenses/>.
 
19
 
 
20
 
 
21
        Web Site: http://www.viewizard.com/
 
22
        Project: http://sourceforge.net/projects/openastromenace/
 
23
        E-mail: viewizard@viewizard.com
 
24
 
 
25
*************************************************************************************/
 
26
 
 
27
 
 
28
/// подключаем нужные файлы
 
29
#include "SpaceObject.h"
 
30
#include "../../Game.h"
 
31
 
 
32
 
 
33
 
 
34
 
 
35
//-----------------------------------------------------------------------------
 
36
// Конструктор, инициализация всех переменных
 
37
//-----------------------------------------------------------------------------
 
38
CSpaceObject::CSpaceObject(void)
 
39
{
 
40
 
 
41
        ObjectStatus = 1; // чужой
 
42
 
 
43
        Speed = 0.0f;
 
44
 
 
45
        Velocity = RotationSpeed = VECTOR3D(0.0f,0.0f,0.0f);
 
46
 
 
47
        GFXQuantity = 0;
 
48
        GFX = 0;
 
49
        GFXLocation = 0;
 
50
 
 
51
        BossPartCountDown = -1.0f;
 
52
 
 
53
        LastCameraPoint = GamePoint;
 
54
 
 
55
        // подключаем к своему списку
 
56
        Next = Prev = 0;
 
57
        AttachSpaceObject(this);
 
58
 
 
59
}
 
60
 
 
61
 
 
62
 
 
63
 
 
64
//-----------------------------------------------------------------------------
 
65
// Деструктор
 
66
//-----------------------------------------------------------------------------
 
67
CSpaceObject::~CSpaceObject(void)
 
68
{
 
69
        if (GFXLocation != 0) {delete [] GFXLocation; GFXLocation = 0;}
 
70
        if (GFX != 0)
 
71
        {
 
72
                for (int i=0; i<GFXQuantity; i++)
 
73
                        if (GFX[i] != 0)
 
74
                        {
 
75
                                GFX[i]->IsSuppressed = true;
 
76
                                GFX[i]->DestroyIfNoParticles = true;
 
77
                        }
 
78
                delete [] GFX; GFX = 0;
 
79
        }
 
80
 
 
81
        DetachSpaceObject(this);
 
82
}
 
83
 
 
84
 
 
85
 
 
86
 
 
87
 
 
88
 
 
89
 
 
90
 
 
91
 
 
92
 
 
93
//-----------------------------------------------------------------------------
 
94
// Установка положения объекта
 
95
//-----------------------------------------------------------------------------
 
96
void CSpaceObject::SetLocation(VECTOR3D NewLocation)
 
97
{
 
98
        // вызываем родительскую функцию
 
99
        ::CObject3D::SetLocation(NewLocation);
 
100
 
 
101
 
 
102
        if (GFX != 0)
 
103
        for (int i=0; i<GFXQuantity; i++)
 
104
        {
 
105
                if (GFX[i] != 0)
 
106
                {
 
107
                        GFX[i]->MoveSystem(NewLocation + GFXLocation[i]);
 
108
                        GFX[i]->SetStartLocation(GFXLocation[i] + NewLocation);
 
109
                }
 
110
        }
 
111
}
 
112
 
 
113
 
 
114
 
 
115
 
 
116
//-----------------------------------------------------------------------------
 
117
// Установка углов поворота объекта
 
118
//-----------------------------------------------------------------------------
 
119
void CSpaceObject::SetRotation(VECTOR3D NewRotation)
 
120
{
 
121
        // вызываем родительскую функцию
 
122
        ::CObject3D::SetRotation(NewRotation);
 
123
 
 
124
 
 
125
        if (GFX != 0)
 
126
        for (int i=0; i<GFXQuantity; i++)
 
127
        {
 
128
                Matrix33CalcPoint(&(GFXLocation[i]), OldInvRotationMat);
 
129
                Matrix33CalcPoint(&(GFXLocation[i]), CurrentRotationMat);
 
130
 
 
131
                if (GFX[i] != 0)
 
132
                {
 
133
                        if (GFX[i]->SpeedOnCreation == -1.0f)
 
134
                        {
 
135
                                GFX[i]->MoveSystem(GFXLocation[i] + Location);
 
136
                                GFX[i]->SetStartLocation(GFXLocation[i] + Location);
 
137
                                GFX[i]->RotateSystemAndParticlesByAngle(Rotation);
 
138
                        }
 
139
                        else
 
140
                        {
 
141
                                GFX[i]->MoveSystemLocation(GFXLocation[i] + Location);
 
142
                                GFX[i]->RotateSystemByAngle(Rotation);
 
143
                        }
 
144
                }
 
145
        }
 
146
}
 
147
 
 
148
 
 
149
 
 
150
 
 
151
 
 
152
 
 
153
 
 
154
 
 
155
 
 
156
//-----------------------------------------------------------------------------
 
157
// Обновление данных объектa
 
158
//-----------------------------------------------------------------------------
 
159
bool CSpaceObject::Update(float Time)
 
160
{
 
161
        // вызываем родительскую функцию
 
162
        // если там передали удалить - выходим
 
163
        if (!::CObject3D::Update(Time)) return false;
 
164
 
 
165
        // если это часть корабля босса, взрываем через время
 
166
        if (BossPartCountDown > -1.0f)
 
167
        {
 
168
                BossPartCountDown -= TimeDelta;
 
169
 
 
170
                if (BossPartCountDown<=0.0f)
 
171
                {
 
172
                        CSpaceExplosion *TMPExplosion;
 
173
                        TMPExplosion = new CSpaceExplosion;
 
174
                        TMPExplosion->Create(this, 34, Location, Speed, -1);
 
175
 
 
176
                        return false;
 
177
                }
 
178
        }
 
179
 
 
180
 
 
181
        // если астероиды
 
182
        if (ObjectType == 7 || ObjectType == 15)
 
183
        {
 
184
                // если большие астероиды летящие сверху
 
185
                if (ObjectType == 15 && (ObjectCreationType>20 && ObjectCreationType<30))
 
186
                {
 
187
                        SetRotation(VECTOR3D(RotationSpeed.x*TimeDelta, RotationSpeed.y*TimeDelta, 0.0f));
 
188
                }
 
189
                else
 
190
                {
 
191
                        if (RotationSpeed.x != 0.0f)
 
192
                        {
 
193
                                Rotation.x -= RotationSpeed.x*TimeDelta;
 
194
                                if (Rotation.x <= 360.0f) Rotation.x += 360.0f;
 
195
                        }
 
196
                        if (RotationSpeed.y != 0.0f)
 
197
                        {
 
198
                                Rotation.y -= RotationSpeed.y*TimeDelta;
 
199
                                if (Rotation.y <= 360.0f) Rotation.y += 360.0f;
 
200
                        }
 
201
                }
 
202
        }
 
203
 
 
204
 
 
205
 
 
206
 
 
207
 
 
208
        // если части корабля или техники, останавливаем
 
209
        if (ObjectType == 8)
 
210
        {
 
211
                if (Speed>0.0f)
 
212
                {
 
213
                        Speed -= 1.0f*TimeDelta;
 
214
                        if (Speed<0.0f) Speed=0.0f;
 
215
                }
 
216
                if (Speed<0.0f)
 
217
                {
 
218
                        Speed += 1.0f*TimeDelta;
 
219
                        if (Speed>0.0f) Speed=0.0f;
 
220
                }
 
221
 
 
222
                if (RotationSpeed.x != 0.0f)
 
223
                {
 
224
                        SetRotation(VECTOR3D(-RotationSpeed.x*TimeDelta,0.0f,0.0f));
 
225
                        RotationSpeed.x -= (RotationSpeed.x/4.0f)*TimeDelta;
 
226
                }
 
227
                if (RotationSpeed.y != 0.0f)
 
228
                {
 
229
                        SetRotation(VECTOR3D(0.0f,-RotationSpeed.y*TimeDelta,0.0f));
 
230
                        RotationSpeed.y -= (RotationSpeed.y/4.0f)*TimeDelta;
 
231
                }
 
232
                if (RotationSpeed.z != 0.0f)
 
233
                {
 
234
                        SetRotation(VECTOR3D(0.0f,0.0f,-RotationSpeed.z*TimeDelta));
 
235
                        RotationSpeed.z -= (RotationSpeed.z/4.0f)*TimeDelta;
 
236
                }
 
237
        }
 
238
 
 
239
 
 
240
 
 
241
 
 
242
        // если планеты, должны учесть положение камеры т.е. ее смещение
 
243
        if (ObjectType == 14 || ObjectType == 15)
 
244
        {
 
245
                VECTOR3D Temp = GamePoint - LastCameraPoint;
 
246
 
 
247
                // у планет особое движение... они немного могут двигаться на камеру...
 
248
                VECTOR3D OrientTTT = Temp^(-1);
 
249
                OrientTTT.Normalize();
 
250
                SetLocation(Location + (OrientTTT^(Speed*TimeDelta)) + Temp);
 
251
                LastCameraPoint = GamePoint;
 
252
 
 
253
                // вращения планет и их частей
 
254
                if (ObjectType == 14)
 
255
                {
 
256
                        switch (ObjectCreationType)
 
257
                        {
 
258
                                // планета с астероидным кольцом
 
259
                                case 1:
 
260
                                        DrawObjectList[0].Rotation.y += 0.5f*TimeDelta;
 
261
                                        // кольца
 
262
                                        DrawObjectList[1].Rotation.y += 0.7f*TimeDelta;
 
263
                                        DrawObjectList[2].Rotation.y += 0.8f*TimeDelta;
 
264
                                        DrawObjectList[3].Rotation.y += 0.9f*TimeDelta;
 
265
                                        break;
 
266
                                // полу разрушенная планета
 
267
                                case 2:
 
268
                                        Rotation.y += 0.5f*TimeDelta;
 
269
                                        if (Rotation.y >= 360.0f) Rotation.y -= 360.0f;
 
270
                                        break;
 
271
                                // планета с атмосферой
 
272
                                case 3:
 
273
                                        DrawObjectList[0].Rotation.y += 0.5f*TimeDelta;
 
274
                                        // атмосфера
 
275
                                        DrawObjectList[1].Rotation.y -= 0.7*TimeDelta;
 
276
                                        break;
 
277
                                // луна
 
278
                                case 4:
 
279
                                        DrawObjectList[0].Rotation.y += 1.0f*TimeDelta;
 
280
                                        break;
 
281
                                // планета пришельцев, с подсветкой
 
282
                                case 5:
 
283
                                        DrawObjectList[0].Rotation.y += 0.5f*TimeDelta;
 
284
                                        break;
 
285
                                // планета пришельцев
 
286
                                case 6:
 
287
                                        DrawObjectList[0].Rotation.y += 0.5f*TimeDelta;
 
288
                                        break;
 
289
                        }
 
290
 
 
291
                        for (int i=0; i<DrawObjectQuantity; i++)
 
292
                        {
 
293
                                if (DrawObjectList[i].Rotation.x >= 360.0f) DrawObjectList[i].Rotation.x -= 360.0f;
 
294
                                if (DrawObjectList[i].Rotation.x <= -360.0f) DrawObjectList[i].Rotation.x += 360.0f;
 
295
                                if (DrawObjectList[i].Rotation.y >= 360.0f) DrawObjectList[i].Rotation.y -= 360.0f;
 
296
                                if (DrawObjectList[i].Rotation.y <= -360.0f) DrawObjectList[i].Rotation.y += 360.0f;
 
297
                        }
 
298
                }
 
299
 
 
300
        }
 
301
        else
 
302
        {
 
303
                SetLocation(Location + (Orientation^(Speed*TimeDelta)));
 
304
        }
 
305
 
 
306
 
 
307
 
 
308
        if (Velocity.x + Velocity.y + Velocity.z != 0.0f)
 
309
        {
 
310
                SetLocation(Location + (Velocity^TimeDelta));
 
311
                Velocity -= Velocity^(0.5f*TimeDelta);
 
312
        }
 
313
 
 
314
 
 
315
 
 
316
        // объект в порядке - удалять не нужно
 
317
        return true;
 
318
}
 
319
 
 
320
 
 
321