Commit b482cdbe authored by alistert's avatar alistert

Improved font handling. Little more on bonus levels.

parent c0b880a1
...@@ -37,12 +37,14 @@ BaseLevel::BaseLevel () { ...@@ -37,12 +37,14 @@ BaseLevel::BaseLevel () {
// Arbitrary initial value // Arbitrary initial value
smoothfps = 50.0f; smoothfps = 50.0f;
paused = false;
return; return;
} }
void BaseLevel::timeCalcs (bool paused) { void BaseLevel::timeCalcs () {
// Calculate smoothed fps // Calculate smoothed fps
smoothfps = smoothfps + 1.0f - smoothfps = smoothfps + 1.0f -
......
...@@ -57,8 +57,9 @@ class BaseLevel { ...@@ -57,8 +57,9 @@ class BaseLevel {
unsigned int endTime; unsigned int endTime;
float smoothfps; float smoothfps;
int items; int items;
bool paused;
void timeCalcs (bool paused); void timeCalcs ();
void drawStats (int stats); void drawStats (int stats);
public: public:
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
#include "menu/menu.h" #include "menu/menu.h"
#include "player/player.h" #include "player/player.h"
#include <math.h> #include <math.h>
int Bonus::loadTiles (char *fileName) { int Bonus::loadTiles (char *fileName) {
...@@ -55,7 +55,11 @@ int Bonus::loadTiles (char *fileName) { ...@@ -55,7 +55,11 @@ int Bonus::loadTiles (char *fileName) {
} }
file->skipRLE(); file->skipRLE();
// Load palette
file->loadPalette(palette); file->loadPalette(palette);
// Load tile graphics
tileSet = file->loadSurface(32, 32 * 60); tileSet = file->loadSurface(32, 32 * 60);
delete file; delete file;
...@@ -200,25 +204,23 @@ int Bonus::play () { ...@@ -200,25 +204,23 @@ int Bonus::play () {
const char *options[3] = {"continue game", "setup options", "quit game"}; const char *options[3] = {"continue game", "setup options", "quit game"};
PaletteEffect *levelPE; PaletteEffect *levelPE;
bool paused, pmenu; bool pmenu, pmessage;
int stats, option; int stats, option;
SDL_Rect src, dst; SDL_Rect src, dst;
int x, y; int x, y;
fixed pX, pY, pDirection; int msps;
int mspf;
tickOffset = globalTicks; tickOffset = globalTicks;
ticks = 16; ticks = 16;
prevStepTicks = 0; prevStepTicks = 0;
pmenu = paused = false; pmessage = pmenu = false;
option = 0; option = 0;
stats = S_NONE; stats = S_NONE;
// Arbitrary position // Arbitrary position
localPlayer->setPosition(TTOF(32) + F16, TTOF(7) + F16); localPlayer->setPosition(TTOF(32) + F16, TTOF(7) + F16);
pDirection = FQ;
while (true) { while (true) {
...@@ -226,12 +228,12 @@ int Bonus::play () { ...@@ -226,12 +228,12 @@ int Bonus::play () {
if (controls.release(C_ESCAPE)) { if (controls.release(C_ESCAPE)) {
if (!gameMode) paused = !paused;
pmenu = !pmenu; pmenu = !pmenu;
option = 0;
} }
if (controls.release(C_PAUSE) && !gameMode) paused = !paused; if (controls.release(C_PAUSE)) pmessage = !pmessage;
if (controls.release(C_STATS)) { if (controls.release(C_STATS)) {
...@@ -254,7 +256,7 @@ int Bonus::play () { ...@@ -254,7 +256,7 @@ int Bonus::play () {
case 0: // Continue case 0: // Continue
paused = pmenu = false; pmenu = false;
break; break;
...@@ -288,35 +290,23 @@ int Bonus::play () { ...@@ -288,35 +290,23 @@ int Bonus::play () {
} }
timeCalcs(paused); if (!gameMode) paused = pmessage || pmenu;
mspf = ticks - prevTicks; timeCalcs();
// Milliseconds per step
msps = ticks - prevStepTicks;
prevStepTicks = ticks;
pX = localPlayer->getX();
pY = localPlayer->getY();
if (!paused) { if (!paused) {
if (controls.getState(C_UP)) { // Apply controls to local player
for (x = 0; x < PCONTROLS; x++)
pX += fixed(sin(pDirection * 6.283185 / 1024.0) * 64 * mspf); localPlayer->setControl(x, controls.getState(x));
pY -= fixed(cos(pDirection * 6.283185 / 1024.0) * 64 * mspf);
}
if (controls.getState(C_DOWN)) {
pX -= fixed(sin(pDirection * 6.283185 / 1024.0) * 32 * mspf);
pY += fixed(cos(pDirection * 6.283185 / 1024.0) * 32 * mspf);
}
if (controls.getState(C_LEFT)) pDirection -= mspf / 2;
if (controls.getState(C_RIGHT)) pDirection += mspf / 2;
localPlayer->setPosition(pX, pY); // Process players
for (x = 0; x < nPlayers; x++) players[x].bonusStep(ticks, msps);
} }
...@@ -324,8 +314,8 @@ int Bonus::play () { ...@@ -324,8 +314,8 @@ int Bonus::play () {
src.w = 32; src.w = 32;
src.h = 32; src.h = 32;
int vX = FTOI(pX) - (canvasW >> 1); int vX = FTOI(localPlayer->getX()) - (canvasW >> 1);
int vY = FTOI(pY) - (canvasH >> 1); int vY = FTOI(localPlayer->getY()) - (canvasH >> 1);
for (y = 0; y <= ITOT(canvasH - 1) + 1; y++) { for (y = 0; y <= ITOT(canvasH - 1) + 1; y++) {
...@@ -384,8 +374,8 @@ int Bonus::play () { ...@@ -384,8 +374,8 @@ int Bonus::play () {
// Draw the "player" // Draw the "player"
drawRect( drawRect(
(canvasW >> 1) + fixed(sin(pDirection * 6.283185 / 1024.0) * 3) - 4, (canvasW >> 1) + fixed(sin(localPlayer->getDirection() * 6.283185 / 1024.0) * 3) - 4,
(canvasH >> 1) - fixed(cos(pDirection * 6.283185 / 1024.0) * 3) - 4, 8, 8, 0); (canvasH >> 1) - fixed(cos(localPlayer->getDirection() * 6.283185 / 1024.0) * 3) - 4, 8, 8, 0);
drawRect((canvasW >> 1) - 4, (canvasH >> 1) - 4, 8, 8, 22); drawRect((canvasW >> 1) - 4, (canvasH >> 1) - 4, 8, 8, 22);
...@@ -401,7 +391,7 @@ int Bonus::play () { ...@@ -401,7 +391,7 @@ int Bonus::play () {
// If paused, draw "PAUSE" // If paused, draw "PAUSE"
if (paused && !pmenu) if (paused && !pmenu)
fontmn1->showString("PAUSE", (canvasW >> 1) - 44, 32); fontmn1->showString("pause", (canvasW >> 1) - 44, 32);
// Draw statistics // Draw statistics
drawStats(stats); drawStats(stats);
......
...@@ -103,11 +103,11 @@ int Game::setLevel (char *fileName) { ...@@ -103,11 +103,11 @@ int Game::setLevel (char *fileName) {
} }
int Game::setBonus (char *fileName) { int Game::setBonus (int ext) {
if (bonusFile) delete[] bonusFile; if (bonusFile) delete[] bonusFile;
if (fileName) bonusFile = createString(fileName); if (level >= 0) bonusFile = createFileName(F_BONUSMAP, ext);
else bonusFile = NULL; else bonusFile = NULL;
return E_NONE; return E_NONE;
...@@ -130,6 +130,8 @@ int Game::play () { ...@@ -130,6 +130,8 @@ int Game::play () {
sendTime = checkTime = 0; sendTime = checkTime = 0;
level = NULL;
if (levelFile) { if (levelFile) {
// Load and play the level // Load and play the level
...@@ -146,10 +148,10 @@ int Game::play () { ...@@ -146,10 +148,10 @@ int Game::play () {
levelRet = level->play(); levelRet = level->play();
} } else levelRet = WON;
if (bonusFile) { if (bonusFile && (levelRet == WON)) {
// Load and play the bonus level // Load and play the bonus level
...@@ -177,7 +179,7 @@ int Game::play () { ...@@ -177,7 +179,7 @@ int Game::play () {
} }
if (!levelFile) continue; if (!level) continue;
switch (levelRet) { switch (levelRet) {
......
...@@ -96,7 +96,7 @@ class Game { ...@@ -96,7 +96,7 @@ class Game {
virtual ~Game (); virtual ~Game ();
virtual int setLevel (char *fileName); virtual int setLevel (char *fileName);
int setBonus (char *fileName); int setBonus (int ext);
int play (); int play ();
void view (int change); void view (int change);
virtual void send (unsigned char *buffer); virtual void send (unsigned char *buffer);
......
...@@ -212,7 +212,7 @@ unsigned char * File::loadRLE (int length) { ...@@ -212,7 +212,7 @@ unsigned char * File::loadRLE (int length) {
rle = fgetc(f); rle = fgetc(f);
if (rle > 127) { if (rle & 128) {
byte = fgetc(f); byte = fgetc(f);
...@@ -223,7 +223,7 @@ unsigned char * File::loadRLE (int length) { ...@@ -223,7 +223,7 @@ unsigned char * File::loadRLE (int length) {
} }
} else if (rle > 0) { } else if (rle) {
for (count = 0; count < rle; count++) { for (count = 0; count < rle; count++) {
...@@ -302,8 +302,17 @@ char * File::loadString () { ...@@ -302,8 +302,17 @@ char * File::loadString () {
} }
SDL_Surface * File::loadSurface (int width, int height) { SDL_Surface * File::loadSurface (int width, int height) {
SDL_Surface *surface;
unsigned char *pixels;
pixels = loadRLE(width * height);
return createSurface(loadRLE(width * height), width, height); surface = createSurface(pixels, width, height);
delete[] pixels;
return surface;
} }
......
...@@ -36,9 +36,9 @@ ...@@ -36,9 +36,9 @@
Font::Font (const char * fileName) { Font::Font (const char * fileName) {
File *file; File *file;
unsigned char *pixels, *character; unsigned char *pixels;
int rle, pos, byte, count, next, fileSize; int fileSize;
int chr, width, height, y; int count, size, width, height;
// Load font from a font file // Load font from a font file
...@@ -51,147 +51,100 @@ Font::Font (const char * fileName) { ...@@ -51,147 +51,100 @@ Font::Font (const char * fileName) {
throw e; throw e;
} }
file->seek(20, true);
lineHeight = file->loadChar() << 1;
// Create the first character
pixels = new unsigned char[3 * lineHeight];
memset(pixels, 0, 3 * lineHeight);
characters[0] = createSurface(pixels, 3, lineHeight);
SDL_SetColorKey(characters[0], SDL_SRCCOLORKEY, 0);
delete[] pixels;
// Create remaining characters
fileSize = file->getSize();
nCharacters = 128;
file->seek(19, true); file->seek(23, true);
width = file->loadChar() << 2; for (count = 1; count < 128; count++) {
h = file->loadChar() << 1;
w = new unsigned char[128];
pixels = new unsigned char[width * h * 128];
memset(pixels, 0, width * h * 128);
file->seek(23, true);
w[0] = width >> 1;
fileSize = file->getSize();
for (chr = 1; chr < 128; chr++) {
file->seek(2, false);
next = file->loadChar();
if (file->tell() > fileSize) break;
next += file->loadChar() << 8;
next += file->tell();
file->seek(1, false);
w[chr] = file->loadChar();
file->seek(1, false);
height = file->loadChar();
character = new unsigned char[(w[chr] * height) + 1];
pos = 0;
while (pos < w[chr] * height) {
rle = file->loadChar();
if (rle > 127) {
byte = file->loadChar();
for (count = 0; count < (rle & 127); count++) {
character[pos++] = byte;
if (pos >= w[chr] * height) break;
}
} else if (rle > 0) {
for (count = 0; count < rle; count++) {
character[pos++] = file->loadChar();
if (pos >= w[chr] * height) break;
}
} else break;
}
character[pos] = character[pos - 1];
for (y = 0; y < height; y++)
memcpy(pixels + (((chr * h) + y) * width),
character + (y * w[chr]) + 1, w[chr]);
delete[] character;
w[chr] += 2;
file->seek(next, true); size = file->loadShort();
if (file->tell() >= fileSize) {
nCharacters = count;
break;
}
if (size) {
pixels = file->loadRLE(size);
width = pixels[0];
width += pixels[1] << 8;
height = pixels[2];
height += pixels[3] << 8;
characters[count] = createSurface(pixels + 4, width, height);
SDL_SetColorKey(characters[count], SDL_SRCCOLORKEY, 0);
delete[] pixels;
} else characters[count] = createSurface(NULL, 1, 1);
} }
delete file; delete file;
for (; chr < 128; chr++) w[chr] = width >> 1;
surface = createSurface(pixels, width, h * 128);
SDL_SetColorKey(surface, SDL_SRCCOLORKEY, 0);
// Create ASCII->font map // Create ASCII->font map
if (!strcmp(fileName, "fontmn1.0fn")) { for (count = 0; count < 33; count++) map[count] = 0;
map[33] = 107; // !
for (count = 0; count < 48; count++) map[count] = 0; map[34] = 116; // "
for (; count < 58; count++) map[count] = count - 8; map[35] = 0; // #
for (; count < 65; count++) map[count] = 0; map[36] = 63; // $
for (; count < 91; count++) map[count] = count - 64; map[37] = 0; // %
for (; count < 97; count++) map[count] = 0; map[38] = 0; // &
for (; count < 123; count++) map[count] = count - 96; map[39] = 115; // '
for (; count < 128; count++) map[count] = 0; map[40] = 111; // (
map[41] = 112; // )
} else if (!strcmp(fileName, "fontmn2.0fn")) { map[42] = 0; // *
map[43] = 105; // +
for (count = 0; count < 43; count++) map[count] = 0; map[44] = 101; // ,
map[33] = 89; map[45] = 104; // -
map[34] = 96; map[46] = 102; // .
map[39] = 95; map[47] = 108; // /
map[43] = 87; for (count = 48; count < 58; count++) map[count] = count + 5; // Numbers
map[44] = 83; map[58] = 114; // :
map[45] = 86; map[59] = 113; // ;
map[46] = 84; map[60] = 0; // <
map[47] = 90; map[61] = 106; // =
count = 48; map[62] = 0; // >
for (; count < 58; count++) map[count] = count + 5; map[63] = 103; // ?
map[58] = 94; map[64] = 0; // @
map[59] = 93; for (count = 65; count < 91; count++) map[count] = count - 38; // Upper-case letters
map[60] = 0; for (; count < 97; count++) map[count] = 0;
map[61] = 88; for (; count < 123; count++) map[count] = count - 96; // Lower-case letters
map[62] = 0; for (; count < 128; count++) map[count] = 0;
map[63] = 85;
map[64] = 0; for (count = 0; count < 128; count++) {
count = 65;
for (; count < 91; count++) map[count] = count - 38; if (map[count] >= nCharacters) map[count] = 0;
for (; count < 97; count++) map[count] = 0;
for (; count < 123; count++) map[count] = count - 96; }
for (; count < 128; count++) map[count] = 0;
} else {
for (count = 0; count < 40; count++) map[count] = 0;
for (; count < 42; count++) map[count] = count + 25;
for (; count < 48; count++) map[count] = 0;
map[44] = 101;
map[45] = 104;
map[46] = 102;
for (; count < 58; count++) map[count] = count + 5;
for (; count < 65; count++) map[count] = 0;
map[63] = 103;
for (; count < 91; count++) map[count] = count - 64;
for (; count < 97; count++) map[count] = 0;
for (; count < 123; count++) map[count] = count - 70;
for (; count < 128; count++) map[count] = 0;
}
return; return;
} }
...@@ -204,10 +157,10 @@ Font::Font (File *file, bool big) { ...@@ -204,10 +157,10 @@ Font::Font (File *file, bool big) {
// Load font from panel.000 // Load font from panel.000
if (big) h = 8; if (big) lineHeight = 8;
else h = 7; else lineHeight = 7;
pixels = new unsigned char[320 * h]; pixels = new unsigned char[320 * lineHeight];
if (big) { if (big) {
...@@ -232,7 +185,7 @@ Font::Font (File *file, bool big) { ...@@ -232,7 +185,7 @@ Font::Font (File *file, bool big) {
} }
// RLE decompression and horizontal to vertical character rearrangement // RLE decompression and horizontal to vertical character rearrangement
while (pos < 320 * h) { while (pos < 320 * lineHeight) {
rle = file->loadChar(); rle = file->loadChar();
...@@ -243,7 +196,7 @@ Font::Font (File *file, bool big) { ...@@ -243,7 +196,7 @@ Font::Font (File *file, bool big) {
for (count = 0; count < (rle & 127); count++) { for (count = 0; count < (rle & 127); count++) {
pixels[(pos & 7) + ((pos / 320) * 8) + pixels[(pos & 7) + ((pos / 320) * 8) +
(((pos % 320)>>3) * 8 * h)] = index; (((pos % 320)>>3) * 8 * lineHeight)] = index;
pos++; pos++;
} }
...@@ -253,7 +206,7 @@ Font::Font (File *file, bool big) { ...@@ -253,7 +206,7 @@ Font::Font (File *file, bool big) {
for (count = 0; count < rle; count++) { for (count = 0; count < rle; count++) {
pixels[(pos & 7) + ((pos / 320) * 8) + pixels[(pos & 7) + ((pos / 320) * 8) +
(((pos % 320)>>3) * 8 * h)] = file->loadChar(); (((pos % 320)>>3) * 8 * lineHeight)] = file->loadChar();
pos++; pos++;
} }
...@@ -261,8 +214,15 @@ Font::Font (File *file, bool big) { ...@@ -261,8 +214,15 @@ Font::Font (File *file, bool big) {
} else break; } else break;
} }
for (count = 0; count < 40; count++)
characters[count] = createSurface(pixels + (count * 8 * lineHeight), 8, lineHeight);
nCharacters= 40;
delete[] pixels;
if (big) { if (big) {
// Create ASCII->font map // Create ASCII->font map
...@@ -278,10 +238,6 @@ Font::Font (File *file, bool big) { ...@@ -278,10 +238,6 @@ Font::Font (File *file, bool big) {
for (; count < 123; count++) map[count] = count - 87; for (; count < 123; count++) map[count] = count - 87;
for (; count < 128; count++) map[count] = 39; for (; count < 128; count++) map[count] = 39;
// Set font dimensions
w = new unsigned char[40];
for (count = 0; count < 40; count++) w[count] = 8;
} else { } else {
// Create ASCII->font map // Create ASCII->font map
...@@ -290,66 +246,56 @@ Font::Font (File *file, bool big) { ...@@ -290,66 +246,56 @@ Font::Font (File *file, bool big) {
for (; count < 60; count++) map[count] = count - 48; for (; count < 60; count++) map[count] = count - 48;
for (; count < 128; count++) map[count] = 12; for (; count < 128; count++) map[count] = 12;
// Set font dimensions
w = new unsigned char[13];
for (count = 0; count < 13; count++) w[count] = 8;
} }
surface = createSurface(pixels, 8, 40 * h);
return; return;
} }
Font::~Font () { Font::~Font () {
int count;
SDL_FreeSurface(surface); for (count = 0; count < nCharacters; count++) SDL_FreeSurface(characters[count]);
delete[] w;
return; return;
} }
int Font::showString (const char * s, int x, int y) { int Font::showString (const char *string, int x, int y) {
SDL_Rect src, dst; SDL_Surface *surface;
SDL_Rect dst;
unsigned int count; unsigned int count;
int xOffset, yOffset; int xOffset, yOffset;
// Determine the characters' dimensions
src.x = 0;
src.h = h;
// Determine the position at which to draw the first character // Determine the position at which to draw the first character
xOffset = x; xOffset = x;
yOffset = y; yOffset = y;
// Go through each character of the string // Go through each character of the string
for (count = 0; s[count]; count++) { for (count = 0; string[count]; count++) {
if (s[count] == '\n') { if (string[count] == '\n') {
xOffset = x; xOffset = x;
yOffset += h; yOffset += lineHeight;
} else { } else {
// Determine the character's position on the screen // Determine the character's position on the screen
src.w = w[(int)(map[(int)(s[count])])];
dst.y = yOffset; dst.y = yOffset;
dst.x = xOffset; dst.x = xOffset;
// Determine the character's position in the font // Determine the character's surface
if (s[count] >= 0) src.y = map[(int)(s[count])] * h; surface = characters[int(map[int(string[count])])];
else src.y = 0;
// Draw the character to the screen // Draw the character to the screen
SDL_BlitSurface(surface, &src, canvas, &dst); SDL_BlitSurface(surface, NULL, canvas, &dst);
xOffset += src.w; xOffset += surface->w + 2;
} }
...@@ -360,68 +306,58 @@ int Font::showString (const char * s, int x, int y) { ...@@ -360,68 +306,58 @@ int Font::showString (const char * s, int x, int y) {
} }
int Font::showSceneString (const char * s, int x, int y) { int Font::showSceneString (const unsigned char *string, int x, int y) {
SDL_Rect src, dst; SDL_Surface *surface;
SDL_Rect dst;
unsigned int count; unsigned int count;
int xOffset; int offset;
// Determine the characters' dimensions
src.x = 0;
src.h = h;
// Determine the position at which to draw the first character // Determine the position at which to draw the first character
xOffset = x; offset = x;
// Go through each character of the string // Go through each character of the string
for (count = 0; s[count]; count++) { for (count = 0; string[count]; count++) {
// Determine the character's position on the screen // Determine the character's position on the screen
src.w = w[(int)(s[count])];
if (s[count] == 0x7F) src.w -= 3;
dst.y = y; dst.y = y;
dst.x = xOffset; dst.x = offset;
// Determine the character's position in the font // Determine the character's surface
if (s[count] >= 0) src.y = s[count] * h; if (string[count] < nCharacters) surface = characters[int(string[count])];
else src.y = 0; else surface = characters[0];
// Draw the character to the screen // Draw the character to the screen
SDL_BlitSurface(surface, &src, canvas, &dst); SDL_BlitSurface(surface, NULL, canvas, &dst);
xOffset += src.w - 1; offset += surface->w + 1;
} }
return xOffset; return offset;
} }
void Font::showNumber (int n, int x, int y) { void Font::showNumber (int n, int x, int y) {
SDL_Rect src, dst; SDL_Surface *surface;
SDL_Rect dst;
int count, offset; int count, offset;
// Determine the characters' dimensions
src.x = 0;
src.h = h;
// n being 0 is a special case. It must not be considered to be a trailing // n being 0 is a special case. It must not be considered to be a trailing
// zero, as these are not displayed. // zero, as these are not displayed.
if (!n) { if (!n) {
// Determine 0's surface
surface = characters[int(map[int('0')])];
// Determine 0's position on the screen // Determine 0's position on the screen
src.w = w[(int)(map[(int)'0'])];
dst.y = y; dst.y = y;
dst.x = x - src.w; dst.x = x - surface->w;
// Determine 0's position in the font
src.y = map[(int)'0'] * h;
// Draw 0 to the screen // Draw 0 to the screen
SDL_BlitSurface(surface, &src, canvas, &dst); SDL_BlitSurface(surface, NULL, canvas, &dst);
return; return;
...@@ -436,35 +372,34 @@ void Font::showNumber (int n, int x, int y) { ...@@ -436,35 +372,34 @@ void Font::showNumber (int n, int x, int y) {
while (count) { while (count) {
// Determine the digit's surface
surface = characters[int(map['0' + (count % 10)])];
offset -= surface->w;
// Determine the digit's position on the screen // Determine the digit's position on the screen
src.w = w[(int)(map['0' + (count % 10)])];
offset -= src.w;
dst.y = y; dst.y = y;
dst.x = offset; dst.x = offset;
// Determine the digit's position in the font
src.y = map['0' + (count % 10)] * h;
// Draw the digit to the screen // Draw the digit to the screen
SDL_BlitSurface(surface, &src, canvas, &dst); SDL_BlitSurface(surface, NULL, canvas, &dst);
count /= 10; count /= 10;
} }
// If needed, draw the negative sign // If needed, draw the negative sign
if (n < 0) { if (n < 0) {
// Determine the negative sign's surface
surface = characters[int(map[int('-')])];
// Determine the negative sign's position on the screen // Determine the negative sign's position on the screen
src.w = w[(int)(map[(int)'-'])];
dst.y = y; dst.y = y;
dst.x = offset - src.w; dst.x = offset - surface->w;
// Determine the negative sign's position on the screen
src.y = map[(int)'-'] * h;
// Draw the negative sign to the screen // Draw the negative sign to the screen
SDL_BlitSurface(surface, &src, canvas, &dst); SDL_BlitSurface(surface, NULL, canvas, &dst);
} }
...@@ -484,7 +419,8 @@ void Font::mapPalette (int start, int length, int newStart, int newLength) { ...@@ -484,7 +419,8 @@ void Font::mapPalette (int start, int length, int newStart, int newLength) {
palette[count].r = palette[count].g = palette[count].b = palette[count].r = palette[count].g = palette[count].b =
(count * newLength / length) + newStart; (count * newLength / length) + newStart;
SDL_SetPalette(surface, SDL_LOGPAL, palette, start, length); for (count = 0; count < nCharacters; count++)
SDL_SetPalette(characters[count], SDL_LOGPAL, palette, start, length);
return; return;
...@@ -492,8 +428,11 @@ void Font::mapPalette (int start, int length, int newStart, int newLength) { ...@@ -492,8 +428,11 @@ void Font::mapPalette (int start, int length, int newStart, int newLength) {
void Font::restorePalette () { void Font::restorePalette () {
int count;
::restorePalette(surface); for (count = 0; count < nCharacters; count++)
::restorePalette(characters[count]);
return; return;
...@@ -502,7 +441,7 @@ void Font::restorePalette () { ...@@ -502,7 +441,7 @@ void Font::restorePalette () {
int Font::getHeight () { int Font::getHeight () {
return h; return lineHeight;
} }
...@@ -518,7 +457,7 @@ int Font::getStringWidth (const char *string) { ...@@ -518,7 +457,7 @@ int Font::getStringWidth (const char *string) {
// Only get the width of the first line // Only get the width of the first line
if (string[count] == '\n') return stringWidth; if (string[count] == '\n') return stringWidth;
stringWidth += w[(int)(string[count])]; stringWidth += characters[int(map[int(string[count])])]->w + 2;
} }
...@@ -527,19 +466,17 @@ int Font::getStringWidth (const char *string) { ...@@ -527,19 +466,17 @@ int Font::getStringWidth (const char *string) {
} }
int Font::getSceneStringWidth (const char *string) { int Font::getSceneStringWidth (const unsigned char *string) {
int count; int count;
int width, stringWidth = 0; int stringWidth = 0;
// Go through each character of the string // Go through each character of the string
for (count = 0; string[count]; count++) { for (count = 0; string[count]; count++) {
width = w[(int)(string[count])]; if (string[count] < nCharacters) stringWidth += characters[int(string[count])]->w + 1;
if (string[count] == 0x7F) width -= 3; else stringWidth += characters[0]->w + 1;
stringWidth += width - 1;
} }
return stringWidth; return stringWidth;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Part of the OpenJazz project * Part of the OpenJazz project
* *
* *
* Copyright (c) 2005-2009 Alister Thomson * Copyright (c) 2005-2010 Alister Thomson
* *
* OpenJazz is distributed under the terms of * OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0 * the GNU General Public License, version 2.0
...@@ -36,10 +36,10 @@ class File; ...@@ -36,10 +36,10 @@ class File;
class Font { class Font {
private: private:
SDL_Surface *surface; SDL_Surface *characters[128];
unsigned char *w; int nCharacters;
unsigned char h; // Dimensions of the letters unsigned char lineHeight;
char map[128]; // Maps ASCII values to letter positions char map[128]; // Maps ASCII values to letter positions
public: public:
Font (const char *fileName); Font (const char *fileName);
...@@ -47,13 +47,14 @@ class Font { ...@@ -47,13 +47,14 @@ class Font {
~Font (); ~Font ();
int showString (const char *s, int x, int y); int showString (const char *s, int x, int y);
int showSceneString (const char *s, int x, int y); int showSceneString (const unsigned char *s, int x, int y);
void showNumber (int n, int x, int y); void showNumber (int n, int x, int y);
void mapPalette (int start, int length, int newStart, int newLength); void mapPalette (int start, int length, int newStart, int newLength);
void restorePalette (); void restorePalette ();
int getHeight (); int getHeight ();
int getStringWidth (const char *string); int getStringWidth (const char *string);
int getSceneStringWidth (const char *string); int getSceneStringWidth (const unsigned char *string);
}; };
// Variables // Variables
......
...@@ -45,13 +45,12 @@ Sprite::~Sprite () { ...@@ -45,13 +45,12 @@ Sprite::~Sprite () {
void Sprite::clearPixels () { void Sprite::clearPixels () {
unsigned char *data; unsigned char data;
if (pixels) SDL_FreeSurface(pixels); if (pixels) SDL_FreeSurface(pixels);
data = new unsigned char[1]; data = SKEY;
*data = SKEY; pixels = createSurface(&data, 1, 1);
pixels = createSurface(data, 1, 1);
SDL_SetColorKey(pixels, SDL_SRCCOLORKEY, SKEY); SDL_SetColorKey(pixels, SDL_SRCCOLORKEY, SKEY);
return; return;
......
...@@ -53,9 +53,6 @@ SDL_Surface * createSurface (unsigned char * pixels, int width, int height) { ...@@ -53,9 +53,6 @@ SDL_Surface * createSurface (unsigned char * pixels, int width, int height) {
if (SDL_MUSTLOCK(ret)) SDL_UnlockSurface(ret); if (SDL_MUSTLOCK(ret)) SDL_UnlockSurface(ret);
// Free redundant pixel data
delete[] pixels;
} }
return ret; return ret;
......
...@@ -71,8 +71,7 @@ EXTERN SDL_Surface *panelAmmo[5]; ...@@ -71,8 +71,7 @@ EXTERN SDL_Surface *panelAmmo[5];
// Functions // Functions
EXTERN SDL_Surface * createSurface (unsigned char *pixels, int width, EXTERN SDL_Surface * createSurface (unsigned char *pixels, int width, int height);
int height);
EXTERN void createScreen (); EXTERN void createScreen ();
EXTERN void usePalette (SDL_Color *palette); EXTERN void usePalette (SDL_Color *palette);
EXTERN void restorePalette (SDL_Surface *surface); EXTERN void restorePalette (SDL_Surface *surface);
......
...@@ -113,7 +113,7 @@ int DemoLevel::play () { ...@@ -113,7 +113,7 @@ int DemoLevel::play () {
if (controls.release(C_STATS)) stats ^= S_SCREEN; if (controls.release(C_STATS)) stats ^= S_SCREEN;
timeCalcs(false); timeCalcs();
...@@ -171,7 +171,7 @@ int DemoLevel::play () { ...@@ -171,7 +171,7 @@ int DemoLevel::play () {
drawStats(stats); drawStats(stats);
fontmn1->showString("DEMO", (canvasW >> 1) - 36, 32); fontmn1->showString("demo", (canvasW >> 1) - 36, 32);
} }
......
...@@ -525,7 +525,7 @@ int Level::play () { ...@@ -525,7 +525,7 @@ int Level::play () {
{"continue game", "save game", "load game", "setup options", "quit game"}; {"continue game", "save game", "load game", "setup options", "quit game"};
PaletteEffect *levelPE; PaletteEffect *levelPE;
char *string; char *string;
bool paused, pmenu; bool pmessage, pmenu;
int stats, option; int stats, option;
unsigned int returnTime; unsigned int returnTime;
int perfect; int perfect;
...@@ -537,7 +537,7 @@ int Level::play () { ...@@ -537,7 +537,7 @@ int Level::play () {
ticks = 16; ticks = 16;
prevStepTicks = 0; prevStepTicks = 0;
pmenu = paused = false; pmessage = pmenu = false;
option = 0; option = 0;
stats = S_NONE; stats = S_NONE;
...@@ -547,18 +547,16 @@ int Level::play () { ...@@ -547,18 +547,16 @@ int Level::play () {
while (true) { while (true) {
// Do general processing
if (loop(NORMAL_LOOP) == E_QUIT) return E_QUIT; if (loop(NORMAL_LOOP) == E_QUIT) return E_QUIT;
if (controls.release(C_ESCAPE)) { if (controls.release(C_ESCAPE)) {
if (!gameMode) paused = !paused;
pmenu = !pmenu; pmenu = !pmenu;
option = 0; option = 0;
} }
if (controls.release(C_PAUSE) && !gameMode) paused = !paused; if (controls.release(C_PAUSE)) pmessage = !pmessage;
if (controls.release(C_STATS)) { if (controls.release(C_STATS)) {
...@@ -581,7 +579,7 @@ int Level::play () { ...@@ -581,7 +579,7 @@ int Level::play () {
case 0: // Continue case 0: // Continue
paused = pmenu = false; pmenu = false;
break; break;
...@@ -623,8 +621,9 @@ int Level::play () { ...@@ -623,8 +621,9 @@ int Level::play () {
} }
if (!gameMode) paused = pmessage || pmenu;
timeCalcs(paused);
timeCalcs();
...@@ -689,7 +688,7 @@ int Level::play () { ...@@ -689,7 +688,7 @@ int Level::play () {
// If paused, draw "PAUSE" // If paused, draw "PAUSE"
if (paused && !pmenu) if (paused && !pmenu)
fontmn1->showString("PAUSE", (canvasW >> 1) - 44, 32); fontmn1->showString("pause", (canvasW >> 1) - 44, 32);
// If this is a competitive game, draw the score // If this is a competitive game, draw the score
...@@ -745,27 +744,27 @@ int Level::play () { ...@@ -745,27 +744,27 @@ int Level::play () {
// Display statistics & bonuses // Display statistics & bonuses
// TODO: Display percentage symbol // TODO: Display percentage symbol
fontmn1->showString("TIME", (canvasW >> 1) - 152, (canvasH >> 1) - 60); fontmn1->showString("time", (canvasW >> 1) - 152, (canvasH >> 1) - 60);
fontmn1->showNumber(timeBonus, (canvasW >> 1) + 124, (canvasH >> 1) - 60); fontmn1->showNumber(timeBonus, (canvasW >> 1) + 124, (canvasH >> 1) - 60);
fontmn1->showString("ENEMIES", (canvasW >> 1) - 152, (canvasH >> 1) - 40); fontmn1->showString("enemies", (canvasW >> 1) - 152, (canvasH >> 1) - 40);
if (enemies) if (enemies)
fontmn1->showNumber((localPlayer->getEnemies() * 100) / enemies, (canvasW >> 1) + 124, (canvasH >> 1) - 40); fontmn1->showNumber((localPlayer->getEnemies() * 100) / enemies, (canvasW >> 1) + 124, (canvasH >> 1) - 40);
else else
fontmn1->showNumber(0, (canvasW >> 1) + 124, (canvasH >> 1) - 40); fontmn1->showNumber(0, (canvasW >> 1) + 124, (canvasH >> 1) - 40);
fontmn1->showString("ITEMS", (canvasW >> 1) - 152, (canvasH >> 1) - 20); fontmn1->showString("items", (canvasW >> 1) - 152, (canvasH >> 1) - 20);
if (items) if (items)
fontmn1->showNumber((localPlayer->getItems() * 100) / items, (canvasW >> 1) + 124, (canvasH >> 1) - 20); fontmn1->showNumber((localPlayer->getItems() * 100) / items, (canvasW >> 1) + 124, (canvasH >> 1) - 20);
else else
fontmn1->showNumber(0, (canvasW >> 1) + 124, (canvasH >> 1) - 20); fontmn1->showNumber(0, (canvasW >> 1) + 124, (canvasH >> 1) - 20);
fontmn1->showString("PERFECT", (canvasW >> 1) - 152, canvasH >> 1); fontmn1->showString("perfect", (canvasW >> 1) - 152, canvasH >> 1);
fontmn1->showNumber(perfect, (canvasW >> 1) + 124, canvasH >> 1); fontmn1->showNumber(perfect, (canvasW >> 1) + 124, canvasH >> 1);
fontmn1->showString("SCORE", (canvasW >> 1) - 152, (canvasH >> 1) + 40); fontmn1->showString("score", (canvasW >> 1) - 152, (canvasH >> 1) + 40);
fontmn1->showNumber(localPlayer->getScore(), (canvasW >> 1) + 124, (canvasH >> 1) + 40); fontmn1->showNumber(localPlayer->getScore(), (canvasW >> 1) + 124, (canvasH >> 1) + 40);
} }
...@@ -789,8 +788,8 @@ int Level::play () { ...@@ -789,8 +788,8 @@ int Level::play () {
fontmn2->restorePalette(); fontmn2->restorePalette();
} }
// Networking // Networking
if (gameMode) { if (gameMode) {
......
...@@ -182,7 +182,8 @@ void Level::draw () { ...@@ -182,7 +182,8 @@ void Level::draw () {
Bullet *bullet; Bullet *bullet;
SDL_Rect src, dst; SDL_Rect src, dst;
int vX, vY; int vX, vY;
int x, y, bgScale; int x, y, bgScale;
unsigned int change;
// Set tile drawing dimensions // Set tile drawing dimensions
...@@ -275,12 +276,16 @@ void Level::draw () { ...@@ -275,12 +276,16 @@ void Level::draw () {
} }
// Calculate change since last step
change = paused? 0: ticks - prevStepTicks;
// Show active events // Show active events
event = firstEvent; event = firstEvent;
while (event) { while (event) {
event->draw(ticks, ticks - prevStepTicks); event->draw(ticks, change);
event = event->getNext(); event = event->getNext();
} }
...@@ -288,7 +293,7 @@ void Level::draw () { ...@@ -288,7 +293,7 @@ void Level::draw () {
// Show the players // Show the players
for (x = 0; x < nPlayers; x++) for (x = 0; x < nPlayers; x++)
players[x].draw(ticks, ticks - prevStepTicks); players[x].draw(ticks, change);
// Show bullets // Show bullets
...@@ -296,7 +301,7 @@ void Level::draw () { ...@@ -296,7 +301,7 @@ void Level::draw () {
while (bullet) { while (bullet) {
bullet->draw(ticks - prevStepTicks); bullet->draw(change);
bullet = bullet->getNext(); bullet = bullet->getNext();
} }
......
...@@ -284,7 +284,8 @@ int Level::loadSprites (char * fileName) { ...@@ -284,7 +284,8 @@ int Level::loadSprites (char * fileName) {
spriteSet[count].setPixels(sorted, width, height); spriteSet[count].setPixels(sorted, width, height);
// Free redundant data // Free redundant data
delete[] pixels; delete[] pixels;
delete[] sorted;
// Check if the next sprite exists // Check if the next sprite exists
...@@ -402,6 +403,8 @@ int Level::loadTiles (char * fileName) { ...@@ -402,6 +403,8 @@ int Level::loadTiles (char * fileName) {
tileSet = createSurface(buffer, TTOI(1), TTOI(tiles)); tileSet = createSurface(buffer, TTOI(1), TTOI(tiles));
SDL_SetColorKey(tileSet, SDL_SRCCOLORKEY, TKEY); SDL_SetColorKey(tileSet, SDL_SRCCOLORKEY, TKEY);
delete[] buffer;
return tiles; return tiles;
......
...@@ -345,9 +345,10 @@ int loadMain (int argc, char *argv[]) { ...@@ -345,9 +345,10 @@ int loadMain (int argc, char *argv[]) {
} }
panelAmmo[0] = createSurface(sorted, 64, 27); panelAmmo[0] = createSurface(sorted, 64, 27);
sorted = pixels; // Re-use the allocated memory
delete[] pixels;
file->seek(8264, true); file->seek(8264, true);
pixels = file->loadRLE(64 * 27); pixels = file->loadRLE(64 * 27);
...@@ -359,7 +360,8 @@ int loadMain (int argc, char *argv[]) { ...@@ -359,7 +360,8 @@ int loadMain (int argc, char *argv[]) {
} }
panelAmmo[1] = createSurface(sorted, 64, 27); panelAmmo[1] = createSurface(sorted, 64, 27);
sorted = pixels; // Re-use the allocated memory
delete[] pixels;
file->seek(9550, true); file->seek(9550, true);
pixels = file->loadRLE(64 * 27); pixels = file->loadRLE(64 * 27);
...@@ -372,7 +374,8 @@ int loadMain (int argc, char *argv[]) { ...@@ -372,7 +374,8 @@ int loadMain (int argc, char *argv[]) {
} }
panelAmmo[2] = createSurface(sorted, 64, 27); panelAmmo[2] = createSurface(sorted, 64, 27);
sorted = pixels; // Re-use the allocated memory
delete[] pixels;
file->seek(11060, true); file->seek(11060, true);
pixels = file->loadRLE(64 * 27); pixels = file->loadRLE(64 * 27);
...@@ -385,7 +388,8 @@ int loadMain (int argc, char *argv[]) { ...@@ -385,7 +388,8 @@ int loadMain (int argc, char *argv[]) {
} }
panelAmmo[3] = createSurface(sorted, 64, 27); panelAmmo[3] = createSurface(sorted, 64, 27);
sorted = pixels; // Re-use the allocated memory
delete[] pixels;
file->seek(12258, true); file->seek(12258, true);
pixels = file->loadRLE(64 * 27); pixels = file->loadRLE(64 * 27);
...@@ -398,7 +402,9 @@ int loadMain (int argc, char *argv[]) { ...@@ -398,7 +402,9 @@ int loadMain (int argc, char *argv[]) {
} }
panelAmmo[4] = createSurface(sorted, 64, 27); panelAmmo[4] = createSurface(sorted, 64, 27);
delete[] pixels; // Don't re-use the allocated memory
delete[] pixels;
delete[] sorted;
// Load fonts // Load fonts
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* Part of the OpenJazz project * Part of the OpenJazz project
* *
* *
* Copyright (c) 2005-2009 Alister Thomson * Copyright (c) 2005-2010 Alister Thomson
* *
* OpenJazz is distributed under the terms of * OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0 * the GNU General Public License, version 2.0
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
Menu::Menu () { Menu::Menu () {
File *file; File *file;
unsigned char *pixels; unsigned char pixel;
time_t currentTime; time_t currentTime;
int count, col; int count, col;
...@@ -154,9 +154,8 @@ Menu::Menu () { ...@@ -154,9 +154,8 @@ Menu::Menu () {
for (; count < 11; count++) { for (; count < 11; count++) {
pixels = new unsigned char[1]; pixel = 0;
*pixels = 0; screens[count + 3] = createSurface(&pixel, 1, 1);
screens[count + 3] = createSurface(pixels, 1, 1);
} }
......
...@@ -211,7 +211,8 @@ void Player::reset () { ...@@ -211,7 +211,8 @@ void Player::reset () {
energy = 4; energy = 4;
shield = 0; shield = 0;
floating = false; floating = false;
facing = true; facing = true;
direction = FQ;
reaction = PR_NONE; reaction = PR_NONE;
reactionTime = 0; reactionTime = 0;
jumpHeight = ITOF(92); jumpHeight = ITOF(92);
...@@ -402,6 +403,8 @@ bool Player::takeEvent (unsigned char gridX, unsigned char gridY, unsigned int t ...@@ -402,6 +403,8 @@ bool Player::takeEvent (unsigned char gridX, unsigned char gridY, unsigned int t
break; break;
case 37: // Diamond case 37: // Diamond
if (game) game->setBonus(0);
// Yellow flash // Yellow flash
firstPE = new FlashPaletteEffect(255, 255, 0, 320, firstPE); firstPE = new FlashPaletteEffect(255, 255, 0, 320, firstPE);
...@@ -694,6 +697,13 @@ bool Player::getFacing () { ...@@ -694,6 +697,13 @@ bool Player::getFacing () {
} }
fixed Player::getDirection () {
return direction;
}
Anim * Player::getAnim () { Anim * Player::getAnim () {
return level->getAnim(anims[animType]); return level->getAnim(anims[animType]);
......
...@@ -113,6 +113,10 @@ ...@@ -113,6 +113,10 @@
#define PYS_FALL ITOF(350) #define PYS_FALL ITOF(350)
#define PYS_SINK ITOF(150) #define PYS_SINK ITOF(150)
#define PYS_JUMP ITOF(-350) #define PYS_JUMP ITOF(-350)
#define PRS_REVERSE ITOF(-32)
#define PRS_RUN ITOF(64)
#define PRS_ROLL ITOF(96)
// Player accelerations // Player accelerations
#define PXA_REVERSE 900 #define PXA_REVERSE 900
...@@ -122,6 +126,10 @@ ...@@ -122,6 +126,10 @@
#define PXA_FFRUN 200 #define PXA_FFRUN 200
#define PYA_GRAVITY 2750 #define PYA_GRAVITY 2750
#define PYA_SINK 1000 #define PYA_SINK 1000
#define PRA_REVERSE 450
#define PRA_STOP 500
#define PRA_RUN 100
// Player colours // Player colours
#define PC_WHITE 0 #define PC_WHITE 0
...@@ -172,7 +180,8 @@ class Player : public Movable { ...@@ -172,7 +180,8 @@ class Player : public Movable {
int lives; int lives;
int shield; /* 0 = none, 1 = 1 yellow, 2 = 2 yellow, 3 = 1 orange, 4 = 2 orange, 5 = 3 orange, 6 = 4 orange */ int shield; /* 0 = none, 1 = 1 yellow, 2 = 2 yellow, 3 = 1 orange, 4 = 2 orange, 5 = 3 orange, 6 = 4 orange */
bool floating; /* false = normal, true = boarding/bird/etc. */ bool floating; /* false = normal, true = boarding/bird/etc. */
bool facing; bool facing;
fixed direction;
unsigned char animType; unsigned char animType;
unsigned char eventX; unsigned char eventX;
unsigned char eventY; /* Position of an event (spring, platform, bridge) */ unsigned char eventY; /* Position of an event (spring, platform, bridge) */
...@@ -221,13 +230,15 @@ class Player : public Movable { ...@@ -221,13 +230,15 @@ class Player : public Movable {
bool overlap (fixed left, fixed top, fixed width, fixed height); bool overlap (fixed left, fixed top, fixed width, fixed height);
void setPosition (fixed newX, fixed newY); void setPosition (fixed newX, fixed newY);
void setSpeed (fixed newDx, fixed newDy); void setSpeed (fixed newDx, fixed newDy);
bool getFacing (); bool getFacing ();
fixed getDirection ();
Anim * getAnim (); Anim * getAnim ();
unsigned char getTeam (); unsigned char getTeam ();
void send (unsigned char *data); void send (unsigned char *data);
void receive (unsigned char *buffer); void receive (unsigned char *buffer);
void control (unsigned int ticks, int msps); void control (unsigned int ticks, int msps);
void move (unsigned int ticks, int msps); void move (unsigned int ticks, int msps);
void bonusStep (unsigned int ticks, int msps);
void view (unsigned int ticks, int mspf); void view (unsigned int ticks, int mspf);
void draw (unsigned int ticks, int change); void draw (unsigned int ticks, int change);
int reacted (unsigned int ticks); int reacted (unsigned int ticks);
......
...@@ -619,6 +619,63 @@ void Player::move (unsigned int ticks, int msps) { ...@@ -619,6 +619,63 @@ void Player::move (unsigned int ticks, int msps) {
return; return;
} }
void Player::bonusStep (unsigned int ticks, int msps) {
// Bonus stages use polar coordinates for movement (but not position)
// Treat dx as change in radius
if (pcontrols[C_UP]) {
// Walk/run forwards
if (dx < 0) dx += PRA_REVERSE * msps;
else if (dx < PRS_RUN) dx += PRA_RUN * msps;
facing = true;
} else if (pcontrols[C_DOWN]) {
// Walk/run back
if (dx > 0) dx -= PRA_REVERSE * msps;
else if (dx > PRS_REVERSE) dx -= PRA_RUN * msps;
facing = false;
} else {
// Slow down
if (dx > 0) {
if (dx < PRA_STOP * msps) dx = 0;
else dx -= PRA_STOP * msps;
}
if (dx < 0) {
if (dx > -PRA_STOP * msps) dx = 0;
else dx += PRA_STOP * msps;
}
}
if (pcontrols[C_LEFT]) direction -= msps >> 1;
if (pcontrols[C_RIGHT]) direction += msps >> 1;
// Apply trajectory
x += fixed(sin(direction * 6.283185 / 1024.0) * dx * msps) >> 10;
y -= fixed(cos(direction * 6.283185 / 1024.0) * dx * msps) >> 10;
return;
}
void Player::view (unsigned int ticks, int mspf) { void Player::view (unsigned int ticks, int mspf) {
......
...@@ -67,13 +67,13 @@ class Font; ...@@ -67,13 +67,13 @@ class Font;
class SceneText { class SceneText {
public: public:
char *text; unsigned char *text;
int alignment; int alignment;
int fontId; int fontId;
int x; int x;
int y; int y;
SDL_Rect textRect; SDL_Rect textRect;
int extraLineHeight; int extraLineHeight;
SceneText (); SceneText ();
~SceneText (); ~SceneText ();
......
...@@ -659,20 +659,20 @@ void Scene::loadScripts (File *f) { ...@@ -659,20 +659,20 @@ void Scene::loadScripts (File *f) {
if (datalen > 0) { if (datalen > 0) {
text->text = f->loadBlock(datalen + 1);
f->seek(-1, false); f->seek(-1, false);
text->text = f->loadString();
// Convert number placeholders // Convert number placeholders
for (int pos = 1; pos < datalen; pos++) { for (int pos = 1; pos < datalen; pos++) {
if (text->text[pos] == -117) { if (text->text[pos] == 0x8B) {
if (loop >= 9) if (loop >= 9)
text->text[pos - 1] = ((loop + 1) / 10) + 53; text->text[pos - 1] = ((loop + 1) / 10) + 53;
text->text[pos] = ((loop + 1) % 10) + 53; text->text[pos] = ((loop + 1) % 10) + 53;
} else if (text->text[pos] == -118) { } else if (text->text[pos] == 0x8A) {
if (scriptItems >= 10) if (scriptItems >= 10)
text->text[pos - 1] = (scriptItems / 10) + 53; text->text[pos - 1] = (scriptItems / 10) + 53;
...@@ -683,9 +683,11 @@ void Scene::loadScripts (File *f) { ...@@ -683,9 +683,11 @@ void Scene::loadScripts (File *f) {
} }
text->text[datalen] = 0;
} else { } else {
text->text = new char[1]; text->text = new unsigned char[1];
text->text[0] = 0; text->text[0] = 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment