Commit b482cdbe authored by alistert's avatar alistert

Improved font handling. Little more on bonus levels.

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