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
149
150
/*
*
* planet.cpp
*
* 23rd August 2005: Created planet.c
* 3rd February 2009: Renamed planet.c to planet.cpp
*
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2009 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/*
* Deals with the loading, displaying and freeing of the planet landing
* sequence.
*
*/
#include "planet.h"
#include "io/controls.h"
#include "io/file.h"
#include "io/gfx/font.h"
#include "io/gfx/video.h"
#include "io/sound.h"
#include "loop.h"
#include "util.h"
#include <string.h>
Planet::Planet (char * fileName, int previous) {
File *file;
unsigned char *pixels;
int count;
try {
file = new File(fileName, false);
} catch (int e) {
throw e;
}
id = file->loadShort();
if (id == previous) {
// Not approaching a planet if already there
delete file;
throw E_NONE;
}
// Load planet name
name = file->loadString();
// Lower-case the name
for (count = 0; name[count]; count++) {
if ((name[count] >= 65) && (name[count] <= 90)) name[count] += 32;
}
// Load the palette
file->loadPalette(palette, false);
// Load the planet image
pixels = file->loadBlock(64 * 55);
sprite.setPixels(pixels, 64, 55, 0);
delete[] pixels;
delete file;
return;
}
Planet::~Planet () {
delete[] name;
return;
}
int Planet::getId () {
return id;
}
int Planet::play () {
unsigned int tickOffset;
tickOffset = globalTicks;
stopMusic();
video.setPalette(palette);
while (true) {
if (loop(NORMAL_LOOP) == E_QUIT) return E_QUIT;
if (controls.release(C_ESCAPE)) return E_NONE;
SDL_Delay(T_FRAME);
clearScreen(0);
if (globalTicks - tickOffset < F2)
sprite.drawScaled(canvasW >> 1, canvasH >> 1, globalTicks - tickOffset);
else if (globalTicks - tickOffset < F4)
sprite.drawScaled(canvasW >> 1, canvasH >> 1, F2);
else if (globalTicks - tickOffset < F4 + FQ)
sprite.drawScaled(canvasW >> 1, canvasH >> 1, (globalTicks - tickOffset - F4) * 32 + F2);
else return E_NONE;
fontmn1->showString("now approaching", (canvasW - 288) >> 1, 0);
fontmn1->showString(name, (canvasW - fontmn1->getStringWidth(name)) >> 1, canvasH - 24);
}
return E_NONE;
}