-
Notifications
You must be signed in to change notification settings - Fork 0
/
jj1planet.cpp
168 lines (111 loc) · 2.8 KB
/
jj1planet.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**
*
* @file jj1planet.cpp
*
* Part of the OpenJazz project
*
* @par History:
* - 23rd August 2005: Created planet.c
* - 3rd February 2009: Renamed planet.c to planet.cpp
* - 1st August 2012: Renamed planet.cpp to jj1planet.cpp
*
* @par Licence:
* Copyright (c) 2005-2017 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
*
* @par Description:
* Deals with the loading, displaying and freeing of the planet landing
* sequence.
*
*/
#include "jj1planet.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>
/**
* Create a JJ1 planet approach sequence.
*
* @param fileName Name of the file containing the planet data
* @param previous The ID of the last planet approach sequence
*/
JJ1Planet::JJ1Planet (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;
}
/**
* Delete the JJ1 planet approach sequence.
*/
JJ1Planet::~JJ1Planet () {
delete[] name;
return;
}
/**
* Get the ID of the planet approach squence.
*
* @return The ID
*/
int JJ1Planet::getId () {
return id;
}
/**
* Run the JJ1 planet approach sequence.
*
* @return Error code
*/
int JJ1Planet::play () {
unsigned int tickOffset;
tickOffset = globalTicks;
//stopMusic();
video.setPalette(palette);
//video.setPalette(palette);
while (true) {
if (loop(NORMAL_LOOP) == E_QUIT) return E_QUIT;
if (controls.release(C_ESCAPE) || controls.wasCursorReleased()) return E_NONE;
SDL_Delay(T_MENU_FRAME);
video.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);
fontmn1->setPalette(palette);
}
return E_NONE;
}