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:
......
...@@ -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++) {
...@@ -303,7 +303,16 @@ char * File::loadString () { ...@@ -303,7 +303,16 @@ char * File::loadString () {
SDL_Surface * File::loadSurface (int width, int height) { 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;
} }
......
This diff is collapsed.
...@@ -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,9 +36,9 @@ class File; ...@@ -36,9 +36,9 @@ 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:
...@@ -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);
} }
......
...@@ -183,6 +183,7 @@ void Level::draw () { ...@@ -183,6 +183,7 @@ void Level::draw () {
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();
} }
......
...@@ -285,6 +285,7 @@ int Level::loadSprites (char * fileName) { ...@@ -285,6 +285,7 @@ int Level::loadSprites (char * fileName) {
// Free redundant data // Free redundant data
delete[] pixels; delete[] pixels;
delete[] sorted;
// Check if the next sprite exists // Check if the next sprite exists
...@@ -403,6 +404,8 @@ int Level::loadTiles (char * fileName) { ...@@ -403,6 +404,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;
} }
......
...@@ -346,7 +346,8 @@ int loadMain (int argc, char *argv[]) { ...@@ -346,7 +346,8 @@ 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);
} }
......
...@@ -212,6 +212,7 @@ void Player::reset () { ...@@ -212,6 +212,7 @@ void Player::reset () {
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);
...@@ -403,6 +404,8 @@ bool Player::takeEvent (unsigned char gridX, unsigned char gridY, unsigned int t ...@@ -403,6 +404,8 @@ bool Player::takeEvent (unsigned char gridX, unsigned char gridY, unsigned int t
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]);
......
...@@ -114,6 +114,10 @@ ...@@ -114,6 +114,10 @@
#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
#define PXA_STOP 1000 #define PXA_STOP 1000
...@@ -123,6 +127,10 @@ ...@@ -123,6 +127,10 @@
#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
#define PC_SGREEN 16 #define PC_SGREEN 16
...@@ -173,6 +181,7 @@ class Player : public Movable { ...@@ -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 */ 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) */
...@@ -222,12 +231,14 @@ class Player : public Movable { ...@@ -222,12 +231,14 @@ class Player : public Movable {
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);
......
...@@ -621,6 +621,63 @@ void Player::move (unsigned int ticks, int msps) { ...@@ -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) { void Player::view (unsigned int ticks, int mspf) {
int oldViewX, oldViewY, speed; int oldViewX, oldViewY, speed;
......
...@@ -67,7 +67,7 @@ class Font; ...@@ -67,7 +67,7 @@ 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;
......
...@@ -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