Commit c0b880a1 authored by alistert's avatar alistert

Made a start on bonus levels.

parent 411eaa5a
...@@ -14,7 +14,7 @@ objects = src/bonus/bonus.o \ ...@@ -14,7 +14,7 @@ objects = src/bonus/bonus.o \
src/menu/menuutil.o src/menu/setupmenu.o \ src/menu/menuutil.o src/menu/setupmenu.o \
src/player/bird.o src/player/player.o src/player/playerframe.o \ src/player/bird.o src/player/player.o src/player/playerframe.o \
src/scene/scene.o src/scene/sceneload.o \ src/scene/scene.o src/scene/sceneload.o \
src/main.o src/movable.o src/planet.o src/util.o \ src/baselevel.o src/main.o src/movable.o src/planet.o src/util.o \
src/io/gfx/scale2x/getopt.o src/io/gfx/scale2x/pixel.o \ src/io/gfx/scale2x/getopt.o src/io/gfx/scale2x/pixel.o \
src/io/gfx/scale2x/scale2x.o src/io/gfx/scale2x/scale3x.o \ src/io/gfx/scale2x/scale2x.o src/io/gfx/scale2x/scale3x.o \
src/io/gfx/scale2x/scalebit.o src/io/gfx/scale2x/simple2x.o src/io/gfx/scale2x/scalebit.o src/io/gfx/scale2x/simple2x.o
......
...@@ -38,7 +38,7 @@ OBJS = src/bonus/bonus.o \ ...@@ -38,7 +38,7 @@ OBJS = src/bonus/bonus.o \
src/menu/menuutil.o src/menu/setupmenu.o \ src/menu/menuutil.o src/menu/setupmenu.o \
src/player/bird.o src/player/player.o src/player/playerframe.o \ src/player/bird.o src/player/player.o src/player/playerframe.o \
src/scene/scene.o src/scene/sceneload.o \ src/scene/scene.o src/scene/sceneload.o \
src/main.o src/movable.o src/planet.o src/util.o \ src/baselevel.o src/main.o src/movable.o src/planet.o src/util.o \
src/io/gfx/scale2x/getopt.o src/io/gfx/scale2x/pixel.o \ src/io/gfx/scale2x/getopt.o src/io/gfx/scale2x/pixel.o \
src/io/gfx/scale2x/scale2x.o src/io/gfx/scale2x/scale3x.o \ src/io/gfx/scale2x/scale2x.o src/io/gfx/scale2x/scale3x.o \
src/io/gfx/scale2x/scalebit.o src/io/gfx/scale2x/simple2x.o src/io/gfx/scale2x/scalebit.o src/io/gfx/scale2x/simple2x.o
......
...@@ -14,7 +14,7 @@ objects = src/bonus/bonus.o \ ...@@ -14,7 +14,7 @@ objects = src/bonus/bonus.o \
src/menu/menuutil.o src/menu/setupmenu.o \ src/menu/menuutil.o src/menu/setupmenu.o \
src/player/bird.o src/player/player.o src/player/playerframe.o \ src/player/bird.o src/player/player.o src/player/playerframe.o \
src/scene/scene.o src/scene/sceneload.o \ src/scene/scene.o src/scene/sceneload.o \
src/main.o src/movable.o src/planet.o src/util.o \ src/baselevel.o src/main.o src/movable.o src/planet.o src/util.o \
src/io/gfx/scale2x/getopt.o src/io/gfx/scale2x/pixel.o \ src/io/gfx/scale2x/getopt.o src/io/gfx/scale2x/pixel.o \
src/io/gfx/scale2x/scale2x.o src/io/gfx/scale2x/scale3x.o \ src/io/gfx/scale2x/scale2x.o src/io/gfx/scale2x/scale3x.o \
src/io/gfx/scale2x/scalebit.o src/io/gfx/scale2x/simple2x.o src/io/gfx/scale2x/scalebit.o src/io/gfx/scale2x/simple2x.o
......
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
#define F_MENU "MENU.000" #define F_MENU "MENU.000"
#define F_PANEL "PANEL.000" #define F_PANEL "PANEL.000"
#define F_SOUNDS "SOUNDS.000" #define F_SOUNDS "SOUNDS.000"
#define F_BONUS "BONUS.000"
#define F_STARTUP_0SC "STARTUP.0SC" #define F_STARTUP_0SC "STARTUP.0SC"
#define F_END_0SC "END.0SC" #define F_END_0SC "END.0SC"
...@@ -82,6 +83,7 @@ ...@@ -82,6 +83,7 @@
// File path prefixes // File path prefixes
#define F_BLOCKS "BLOCKS" #define F_BLOCKS "BLOCKS"
#define F_BONUSMAP "BONUSMAP"
#define F_LEVEL "LEVEL" #define F_LEVEL "LEVEL"
#define F_PLANET "PLANET" #define F_PLANET "PLANET"
#define F_SPRITES "SPRITES" #define F_SPRITES "SPRITES"
...@@ -90,6 +92,7 @@ ...@@ -90,6 +92,7 @@
#define F_MENU "menu.000" #define F_MENU "menu.000"
#define F_PANEL "panel.000" #define F_PANEL "panel.000"
#define F_SOUNDS "sounds.000" #define F_SOUNDS "sounds.000"
#define F_BONUS "bonus.000"
#define F_STARTUP_0SC "startup.0sc" #define F_STARTUP_0SC "startup.0sc"
#define F_END_0SC "end.0sc" #define F_END_0SC "end.0sc"
...@@ -98,6 +101,7 @@ ...@@ -98,6 +101,7 @@
// File path prefixes // File path prefixes
#define F_BLOCKS "blocks" #define F_BLOCKS "blocks"
#define F_BONUSMAP "bonusmap"
#define F_LEVEL "level" #define F_LEVEL "level"
#define F_PLANET "planet" #define F_PLANET "planet"
#define F_SPRITES "sprites" #define F_SPRITES "sprites"
......
/*
*
* baselevel.cpp
*
* 30th March 2010: Created baselevel.cpp from parts of level.cpp and
* levelframe.cpp
*
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/*
* Deals with functionality common to ordinary levels and bonus levels.
*
*/
#include "io/gfx/font.h"
#include "io/gfx/video.h"
#include "player/player.h"
#include "baselevel.h"
BaseLevel::BaseLevel () {
// Arbitrary initial value
smoothfps = 50.0f;
return;
}
void BaseLevel::timeCalcs (bool paused) {
// Calculate smoothed fps
smoothfps = smoothfps + 1.0f -
(smoothfps * ((float)(ticks - prevTicks)) / 1000.0f);
/* This equation is a simplified version of
(fps * c) + (smoothfps * (1 - c))
where c = (1 / fps)
and fps = 1000 / (ticks - prevTicks)
In other words, the response of smoothFPS to changes in FPS decreases as the
framerate increases
The following version is for c = (1 / smoothfps)
*/
// smoothfps = (fps / smoothfps) + smoothfps - 1;
// Ignore outlandish values
if (smoothfps > 9999.0f) smoothfps = 9999.0f;
if (smoothfps < 1.0f) smoothfps = 1.0f;
// Track number of ticks of gameplay since the level started
if (paused) {
tickOffset = globalTicks - ticks;
} else if (globalTicks - tickOffset > ticks + 100) {
prevTicks = ticks;
ticks += 100;
tickOffset = globalTicks - ticks;
} else {
prevTicks = ticks;
ticks = globalTicks - tickOffset;
}
return;
}
void BaseLevel::drawStats (int stats) {
int count, width;
// Draw graphics statistics
if (stats & S_SCREEN) {
#ifdef SCALE
if (scaleFactor > 1)
drawRect(canvasW - 84, 11, 80, 37, BLACK);
else
#endif
drawRect(canvasW - 84, 11, 80, 25, BLACK);
panelBigFont->showNumber(screenW, canvasW - 52, 14);
panelBigFont->showString("x", canvasW - 48, 14);
panelBigFont->showNumber(screenH, canvasW - 12, 14);
panelBigFont->showString("fps", canvasW - 76, 26);
panelBigFont->showNumber((int)smoothfps, canvasW - 12, 26);
#ifdef SCALE
if (scaleFactor > 1) {
panelBigFont->showNumber(canvasW, canvasW - 52, 38);
panelBigFont->showString("x", canvasW - 48, 39);
panelBigFont->showNumber(canvasH, canvasW - 12, 38);
}
#endif
}
// Draw player list
if (stats & S_PLAYERS) {
width = 39;
for (count = 0; count < nPlayers; count++)
if (panelBigFont->getStringWidth(players[count].getName()) > width)
width = panelBigFont->getStringWidth(players[count].getName());
drawRect((canvasW >> 1) - 48, 11, width + 57, (nPlayers * 12) + 1, BLACK);
for (count = 0; count < nPlayers; count++) {
panelBigFont->showNumber(count + 1,
(canvasW >> 1) - 24, 14 + (count * 12));
panelBigFont->showString(players[count].getName(),
(canvasW >> 1) - 16, 14 + (count * 12));
panelBigFont->showNumber(players[count].teamScore,
(canvasW >> 1) + width + 1, 14 + (count * 12));
}
}
return;
}
/*
*
* baselevel.h
*
* 30th March 2010: Created baselevel.h from parts of level.h
*
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef _BASELEVEL_H
#define _BASELEVEL_H
#include "OpenJazz.h"
#include <SDL/SDL.h>
// Constants
// Displayed statistics
#define S_NONE 0
#define S_PLAYERS 1
#define S_SCREEN 2
// Macros
// For converting between tile positions and int/fixed values
#define FTOT(x) ((x) >> 15)
#define TTOF(x) ((x) << 15)
#define ITOT(x) ((x) >> 5)
#define TTOI(x) ((x) << 5)
// Classes
class BaseLevel {
protected:
SDL_Surface *tileSet;
SDL_Color palette[256];
unsigned int tickOffset, prevStepTicks, prevTicks, ticks;
unsigned int endTime;
float smoothfps;
int items;
void timeCalcs (bool paused);
void drawStats (int stats);
public:
BaseLevel ();
};
#endif
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,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
...@@ -27,13 +27,50 @@ ...@@ -27,13 +27,50 @@
#include "bonus.h" #include "bonus.h"
#include "game/gamemode.h"
#include "io/controls.h" #include "io/controls.h"
#include "io/file.h" #include "io/file.h"
#include "io/gfx/font.h"
#include "io/gfx/paletteeffects.h"
Bonus::Bonus (char * fileName) { #include "io/gfx/video.h"
#include "io/sound.h"
File *file; #include "menu/menu.h"
#include "player/player.h"
#include <math.h>
int Bonus::loadTiles (char *fileName) {
File *file;
try {
file = new File(fileName, false);
} catch (int e) {
return e;
}
file->skipRLE();
file->loadPalette(palette);
tileSet = file->loadSurface(32, 32 * 60);
delete file;
return E_NONE;
}
Bonus::Bonus (char * fileName, unsigned char diff) {
File *file;
unsigned char *buffer;
char *string, *fileString;
int x, y;
try { try {
...@@ -44,11 +81,97 @@ Bonus::Bonus (char * fileName) { ...@@ -44,11 +81,97 @@ Bonus::Bonus (char * fileName) {
throw e; throw e;
} }
// TODO: Load bonus level data
// Load tileset
file->seek(90, true);
string = file->loadString();
fileString = createFileName(string, 0);
x = loadTiles(fileString);
delete[] string;
delete[] fileString;
if (x != E_NONE) throw x;
// Load music
file->seek(121, true);
fileString = file->loadString();
playMusic(fileString);
delete[] fileString;
// Load tiles
file->seek(2694, true);
buffer = file->loadRLE(BLW * BLH);
for (y = 0; y < BLH; y++) {
for (x = 0; x < BLW; x++) {
tiles[y][x] = buffer[x + (y * BLW)];
if (tiles[y][x] > 59) tiles[y][x] = 59;
}
}
delete[] buffer;
file->skipRLE(); // Mysterious block
// Load events
buffer = file->loadRLE(BLW * BLH);
for (y = 0; y < BLW; y++) {
for (x = 0; x < BLH; x++) {
events[y][x] = buffer[x + (y * BLW)];
}
}
delete[] buffer;
delete file; delete file;
// Palette animations
// Free any existing palette effects
if (firstPE) delete firstPE;
// Spinny whirly thing
firstPE = new RotatePaletteEffect(112, 16, F32, NULL);
// Track sides
firstPE = new RotatePaletteEffect(192, 16, F32, firstPE);
// Bouncy things
firstPE = new RotatePaletteEffect(240, 16, -F32, firstPE);
// Apply the palette to surfaces that already exist, e.g. fonts
usePalette(palette);
// Adjust fontmn1 to use bonuslevel palette
fontmn1->mapPalette(224, 8, 0, 16);
// Set the tick at which the level will end
endTime = (5 - diff) * 30 * 1000;
return; return;
} }
...@@ -56,8 +179,18 @@ Bonus::Bonus (char * fileName) { ...@@ -56,8 +179,18 @@ Bonus::Bonus (char * fileName) {
Bonus::~Bonus () { Bonus::~Bonus () {
// Nothing to do // Free the palette effects
if (firstPE) {
delete firstPE;
firstPE = NULL;
}
SDL_FreeSurface(tileSet);
fontmn1->restorePalette();
return; return;
} }
...@@ -65,14 +198,234 @@ Bonus::~Bonus () { ...@@ -65,14 +198,234 @@ Bonus::~Bonus () {
int Bonus::play () { int Bonus::play () {
const char *options[3] = {"continue game", "setup options", "quit game"};
PaletteEffect *levelPE;
bool paused, pmenu;
int stats, option;
SDL_Rect src, dst;
int x, y;
fixed pX, pY, pDirection;
int mspf;
tickOffset = globalTicks;
ticks = 16;
prevStepTicks = 0;
pmenu = paused = false;
option = 0;
stats = S_NONE;
// Arbitrary position
localPlayer->setPosition(TTOF(32) + F16, TTOF(7) + F16);
pDirection = FQ;
while (true) { while (true) {
if (loop(NORMAL_LOOP) == E_QUIT) return E_QUIT; if (loop(NORMAL_LOOP) == E_QUIT) return E_QUIT;
if (controls.release(C_ESCAPE)) return E_NONE; if (controls.release(C_ESCAPE)) {
// TODO: Bonus levels if (!gameMode) paused = !paused;
pmenu = !pmenu;
}
if (controls.release(C_PAUSE) && !gameMode) paused = !paused;
if (controls.release(C_STATS)) {
if (!gameMode) stats ^= S_SCREEN;
else stats = (stats + 1) & 3;
}
if (pmenu) {
// Deal with menu controls
if (controls.release(C_UP)) option = (option + 2) % 3;
if (controls.release(C_DOWN)) option = (option + 1) % 3;
if (controls.release(C_ENTER)) {
switch (option) {
case 0: // Continue
paused = pmenu = false;
break;
case 1: // Setup
if (!gameMode) {
// Don't want palette effects in setup menu
levelPE = firstPE;
firstPE = NULL;
if (menu->setup() == E_QUIT) return E_QUIT;
// Restore level palette
usePalette(palette);
// Restore palette effects
firstPE = levelPE;
}
break;
case 2: // Quit game
return E_NONE;
}
}
}
timeCalcs(paused);
mspf = ticks - prevTicks;
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;
localPlayer->setPosition(pX, pY);
}
src.x = 0;
src.w = 32;
src.h = 32;
int vX = FTOI(pX) - (canvasW >> 1);
int vY = FTOI(pY) - (canvasH >> 1);
for (y = 0; y <= ITOT(canvasH - 1) + 1; y++) {
for (x = 0; x <= ITOT(canvasW - 1) + 1; x++) {
src.y = TTOI(tiles[(y + ITOT(vY) + BLH) % BLH][(x + ITOT(vX) + BLW) % BLW]);
dst.x = TTOI(x) - (vX & 31);
dst.y = TTOI(y) - (vY & 31);
SDL_BlitSurface(tileSet, &src, canvas, &dst);
dst.x = 12 + TTOI(x) - (vX & 31);
dst.y = 12 + TTOI(y) - (vY & 31);
switch (events[(y + ITOT(vY) + BLH) % BLH][(x + ITOT(vX) + BLW) % BLW]) {
case 0: // No event
break;
case 1: // Extra time
drawRect(dst.x, dst.y, 8, 8, 60);
break;
case 2: // Gem
drawRect(dst.x, dst.y, 8, 8, 67);
break;
case 3: // Hand
drawRect(dst.x, dst.y, 8, 8, 15);
break;
case 4: // Exit
drawRect(dst.x, dst.y, 8, 8, 45);
break;
default:
drawRect(dst.x, dst.y, 8, 8, 0);
break;
}
}
}
// 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);
drawRect((canvasW >> 1) - 4, (canvasH >> 1) - 4, 8, 8, 22);
// Show time remaining
if (endTime > ticks) x = endTime - ticks;
else x = 0;
y = x / (60 * 1000);
fontmn1->showNumber(y, 144, 8);
x -= (y * 60 * 1000);
y = x / 1000;
fontmn1->showNumber(y, 192, 8);
// If paused, draw "PAUSE"
if (paused && !pmenu)
fontmn1->showString("PAUSE", (canvasW >> 1) - 44, 32);
// Draw statistics
drawStats(stats);
// Draw the menu
if (pmenu) {
// Draw the menu
drawRect((canvasW >> 2) - 8, (canvasH >> 1) - 46, 144, 60, 0);
for (x = 0; x < 3; x++) {
if (x == option) fontmn2->mapPalette(240, 8, 31, 16);
else fontmn2->mapPalette(240, 8, 0, 16);
fontmn2->showString(options[x], canvasW >> 2, (canvasH >> 1) + (x << 4) - 38);
}
fontmn2->restorePalette();
}
} }
return E_NONE; return E_NONE;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* Part of the OpenJazz project * Part of the OpenJazz project
* *
* *
* Copyright (c) 2009 Alister Thomson * Copyright (c) 2009-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
...@@ -22,14 +22,31 @@ ...@@ -22,14 +22,31 @@
#ifndef _BONUS_H #ifndef _BONUS_H
#define _BONUS_H #define _BONUS_H
#include "baselevel.h"
#include <SDL/SDL.h>
// Constants
// General
#define BLW 256 /* Bonus level width */
#define BLH 256 /* Bonus level height */
// Class // Class
class Bonus { class Bonus : public BaseLevel {
private:
unsigned char tiles[BLH][BLW];
unsigned char events[BLH][BLW];
int loadTiles (char *fileName);
public: public:
Bonus (char * fileName); Bonus (char * fileName, unsigned char diff);
~Bonus (); ~Bonus ();
int play (); int play ();
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "game.h" #include "game.h"
#include "gamemode.h" #include "gamemode.h"
#include "bonus/bonus.h"
#include "io/controls.h" #include "io/controls.h"
#include "io/gfx/font.h" #include "io/gfx/font.h"
#include "io/gfx/video.h" #include "io/gfx/video.h"
...@@ -34,10 +35,13 @@ ...@@ -34,10 +35,13 @@
#include "player/player.h" #include "player/player.h"
#include "scene/scene.h" #include "scene/scene.h"
#include <string.h>
Game::Game () { Game::Game () {
levelFile = NULL; levelFile = NULL;
bonusFile = NULL;
players = NULL; players = NULL;
...@@ -47,8 +51,19 @@ Game::Game () { ...@@ -47,8 +51,19 @@ Game::Game () {
Game::Game (char *firstLevel, int gameDifficulty) { Game::Game (char *firstLevel, int gameDifficulty) {
levelFile = createString(firstLevel); if (!strncmp(firstLevel, F_BONUSMAP, 8)) {
levelFile = NULL;
bonusFile = createString(firstLevel);
} else {
levelFile = createString(firstLevel);
bonusFile = NULL;
}
difficulty = gameDifficulty; difficulty = gameDifficulty;
gameMode = NULL; gameMode = NULL;
...@@ -66,6 +81,7 @@ Game::Game (char *firstLevel, int gameDifficulty) { ...@@ -66,6 +81,7 @@ Game::Game (char *firstLevel, int gameDifficulty) {
Game::~Game () { Game::~Game () {
if (levelFile) delete[] levelFile; if (levelFile) delete[] levelFile;
if (bonusFile) delete[] levelFile;
if (players) delete[] players; if (players) delete[] players;
localPlayer = NULL; localPlayer = NULL;
...@@ -79,19 +95,32 @@ int Game::setLevel (char *fileName) { ...@@ -79,19 +95,32 @@ int Game::setLevel (char *fileName) {
if (levelFile) delete[] levelFile; if (levelFile) delete[] levelFile;
if (!fileName) levelFile = NULL; if (fileName) levelFile = createString(fileName);
else levelFile = createString(fileName); else levelFile = NULL;
return E_NONE; return E_NONE;
} }
int Game::setBonus (char *fileName) {
if (bonusFile) delete[] bonusFile;
if (fileName) bonusFile = createString(fileName);
else bonusFile = NULL;
return E_NONE;
}
int Game::play () { int Game::play () {
Scene * scene; Bonus *bonus;
Scene *scene;
bool checkpoint; bool checkpoint;
int ret; int levelRet, bonusRet;
checkpoint = false; checkpoint = false;
...@@ -99,22 +128,59 @@ int Game::play () { ...@@ -99,22 +128,59 @@ int Game::play () {
while (true) { while (true) {
sendTime = checkTime = 0; sendTime = checkTime = 0;
if (levelFile) {
// Load the level // Load and play the level
try {
level = new Level(levelFile, difficulty, checkpoint); try {
} catch (int e) { level = new Level(levelFile, difficulty, checkpoint);
return e; } catch (int e) {
} return e;
ret = level->play(); }
switch (ret) { levelRet = level->play();
}
if (bonusFile) {
// Load and play the bonus level
try {
bonus = new Bonus(bonusFile, difficulty);
} catch (int e) {
return e;
}
delete[] bonusFile;
bonusFile = NULL;
bonusRet = bonus->play();
delete bonus;
if (bonusRet == E_QUIT) return E_QUIT;
if (bonusRet == E_NONE) return E_NONE;
}
if (!levelFile) continue;
switch (levelRet) {
case E_NONE: // Quit game case E_NONE: // Quit game
...@@ -141,6 +207,8 @@ int Game::play () { ...@@ -141,6 +207,8 @@ int Game::play () {
} }
delete level;
// Do not use old level's checkpoint coordinates // Do not use old level's checkpoint coordinates
checkpoint = false; checkpoint = false;
...@@ -148,13 +216,9 @@ int Game::play () { ...@@ -148,13 +216,9 @@ int Game::play () {
case LOST: // Lost level case LOST: // Lost level
if (!localPlayer->getLives()) { delete level;
delete level; if (!localPlayer->getLives()) return E_NONE; // Not really a success...
return E_NONE; // Not really a success...
}
// Use checkpoint coordinates // Use checkpoint coordinates
checkpoint = true; checkpoint = true;
...@@ -165,13 +229,10 @@ int Game::play () { ...@@ -165,13 +229,10 @@ int Game::play () {
delete level; delete level;
return ret; return levelRet;
} }
// Unload the previous level
delete level;
} }
return E_NONE; return E_NONE;
......
...@@ -84,6 +84,7 @@ class Game { ...@@ -84,6 +84,7 @@ class Game {
protected: protected:
char *levelFile; char *levelFile;
char *bonusFile;
int difficulty; int difficulty;
unsigned int sendTime, checkTime; unsigned int sendTime, checkTime;
unsigned char checkX, checkY; unsigned char checkX, checkY;
...@@ -95,6 +96,7 @@ class Game { ...@@ -95,6 +96,7 @@ class Game {
virtual ~Game (); virtual ~Game ();
virtual int setLevel (char *fileName); virtual int setLevel (char *fileName);
int setBonus (char *fileName);
int play (); int play ();
void view (int change); void view (int change);
virtual void send (unsigned char *buffer); virtual void send (unsigned char *buffer);
......
...@@ -167,7 +167,8 @@ int DemoLevel::play () { ...@@ -167,7 +167,8 @@ int DemoLevel::play () {
// Draw the graphics // Draw the graphics
draw(stats); draw();
drawStats(stats);
fontmn1->showString("DEMO", (canvasW >> 1) - 36, 32); fontmn1->showString("DEMO", (canvasW >> 1) - 36, 32);
......
...@@ -12,7 +12,9 @@ ...@@ -12,7 +12,9 @@
* 18th July 2009: Created demolevel.cpp from parts of level.cpp and * 18th July 2009: Created demolevel.cpp from parts of level.cpp and
* levelload.cpp * levelload.cpp
* 19th July 2009: Created levelframe.cpp from parts of level.cpp * 19th July 2009: Created levelframe.cpp from parts of level.cpp
* 19th July 2009: Added parts of levelload.cpp to level.cpp * 19th July 2009: Added parts of levelload.cpp to level.cpp
* 30th March 2010: Created baselevel.cpp from parts of level.cpp and
* levelframe.cpp
* *
* Part of the OpenJazz project * Part of the OpenJazz project
* *
...@@ -54,16 +56,15 @@ ...@@ -54,16 +56,15 @@
#include <string.h> #include <string.h>
Level::Level () { Level::Level () {
// Arbitrary initial value // Do nothing
smoothfps = 50.0f;
return;
}
return;
}
Level::Level (char *fileName, unsigned char diff, bool checkpoint) { Level::Level (char *fileName, unsigned char diff, bool checkpoint) {
int ret; int ret;
...@@ -518,55 +519,10 @@ void Level::receive (unsigned char *buffer) { ...@@ -518,55 +519,10 @@ void Level::receive (unsigned char *buffer) {
} }
void Level::timeCalcs (bool paused) {
// Calculate smoothed fps
smoothfps = smoothfps + 1.0f -
(smoothfps * ((float)(ticks - prevTicks)) / 1000.0f);
/* This equation is a simplified version of
(fps * c) + (smoothfps * (1 - c))
where c = (1 / fps)
and fps = 1000 / (ticks - prevTicks)
In other words, the response of smoothFPS to changes in FPS decreases as the
framerate increases
The following version is for c = (1 / smoothfps)
*/
// smoothfps = (fps / smoothfps) + smoothfps - 1;
// Ignore outlandish values
if (smoothfps > 9999.0f) smoothfps = 9999.0f;
if (smoothfps < 1.0f) smoothfps = 1.0f;
// Track number of ticks of gameplay since the level started
if (paused) {
tickOffset = globalTicks - ticks;
} else if (globalTicks - tickOffset > ticks + 100) {
prevTicks = ticks;
ticks += 100;
tickOffset = globalTicks - ticks;
} else {
prevTicks = ticks;
ticks = globalTicks - tickOffset;
}
return;
}
int Level::play () { int Level::play () {
const char *options[5] = {"continue game", "save game", "load game", const char *options[5] =
"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 paused, pmenu;
...@@ -575,7 +531,6 @@ int Level::play () { ...@@ -575,7 +531,6 @@ int Level::play () {
int perfect; int perfect;
int timeBonus; int timeBonus;
int count; int count;
int width;
tickOffset = globalTicks; tickOffset = globalTicks;
...@@ -729,7 +684,7 @@ int Level::play () { ...@@ -729,7 +684,7 @@ int Level::play () {
// Draw the graphics // Draw the graphics
draw(stats); draw();
// If paused, draw "PAUSE" // If paused, draw "PAUSE"
...@@ -740,31 +695,9 @@ int Level::play () { ...@@ -740,31 +695,9 @@ int Level::play () {
// If this is a competitive game, draw the score // If this is a competitive game, draw the score
if (gameMode) gameMode->drawScore(); if (gameMode) gameMode->drawScore();
// Draw player list // Draw statistics
drawStats(stats);
if (stats & S_PLAYERS) {
width = 39;
for (count = 0; count < nPlayers; count++)
if (panelBigFont->getStringWidth(players[count].getName()) > width)
width = panelBigFont->getStringWidth(players[count].getName());
drawRect((viewW >> 1) - 48, 11, width + 57, (nPlayers * 12) + 1, BLACK);
for (count = 0; count < nPlayers; count++) {
panelBigFont->showNumber(count + 1,
(viewW >> 1) - 24, 14 + (count * 12));
panelBigFont->showString(players[count].getName(),
(viewW >> 1) - 16, 14 + (count * 12));
panelBigFont->showNumber(players[count].teamScore,
(viewW >> 1) + width + 1, 14 + (count * 12));
}
}
if (stage == LS_END) { if (stage == LS_END) {
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
* 31st January 2006: Created level.h from parts of OpenJazz.h * 31st January 2006: Created level.h from parts of OpenJazz.h
* 4th February 2009: Created events.h from parts of level.h * 4th February 2009: Created events.h from parts of level.h
* 19th March 2009: Created sprite.h from parts of level.h * 19th March 2009: Created sprite.h from parts of level.h
* 30th March 2010: Created baselevel.h from parts of level.h
* *
* Part of the OpenJazz project * Part of the OpenJazz project
* *
...@@ -31,6 +32,7 @@ ...@@ -31,6 +32,7 @@
#define _LEVEL_H #define _LEVEL_H
#include "baselevel.h"
#include "io/gfx/anim.h" #include "io/gfx/anim.h"
#include "OpenJazz.h" #include "OpenJazz.h"
...@@ -39,11 +41,6 @@ ...@@ -39,11 +41,6 @@
// Constants // Constants
// Displayed statistics
#define S_NONE 0
#define S_PLAYERS 1
#define S_SCREEN 2
// General // General
#define LW 256 /* Level width */ #define LW 256 /* Level width */
#define LH 64 /* Level height */ #define LH 64 /* Level height */
...@@ -65,15 +62,6 @@ ...@@ -65,15 +62,6 @@
#define T_END 1000 #define T_END 1000
// Macros
// For converting between tile positions and int/fixed values
#define FTOT(x) ((x) >> 15)
#define TTOF(x) ((x) << 15)
#define ITOT(x) ((x) >> 5)
#define TTOI(x) ((x) << 5)
// Datatypes // Datatypes
typedef struct { typedef struct {
...@@ -104,12 +92,11 @@ class Event; ...@@ -104,12 +92,11 @@ class Event;
class Player; class Player;
class Scene; class Scene;
class Level { class Level : public BaseLevel {
private: private:
char *sceneFile; char *sceneFile;
Sprite *spriteSet; // 208 of which are usually in mainchar.000 Sprite *spriteSet; // 208 of which are usually in mainchar.000
SDL_Surface *tileSet;
Anim animSet[ANIMS]; Anim animSet[ANIMS];
char miscAnims[4]; char miscAnims[4];
signed char bulletSet[BULLETS][BLENGTH]; signed char bulletSet[BULLETS][BLENGTH];
...@@ -117,32 +104,26 @@ class Level { ...@@ -117,32 +104,26 @@ class Level {
char mask[240][64]; // At most 240 tiles, all with 8 * 8 masks char mask[240][64]; // At most 240 tiles, all with 8 * 8 masks
GridElement grid[LH][LW]; // All levels are the same size GridElement grid[LH][LW]; // All levels are the same size
int soundMap[32]; int soundMap[32];
SDL_Color palette[256];
SDL_Color skyPalette[256]; SDL_Color skyPalette[256];
bool sky; bool sky;
unsigned char skyOrb; unsigned char skyOrb;
int sprites; int sprites;
int levelNum, worldNum, nextLevelNum, nextWorldNum; int levelNum, worldNum, nextLevelNum, nextWorldNum;
unsigned char difficulty; unsigned char difficulty;
unsigned int endTime; int enemies;
int enemies, items;
fixed waterLevel; fixed waterLevel;
fixed waterLevelTarget; fixed waterLevelTarget;
fixed waterLevelSpeed; fixed waterLevelSpeed;
fixed energyBar; fixed energyBar;
int stage; int stage;
float smoothfps;
int loadSprites (char *fileName); int loadSprites (char *fileName);
int loadTiles (char *fileName); int loadTiles (char *fileName);
protected: protected:
unsigned int tickOffset, prevStepTicks, prevTicks, ticks; int load (char *fileName, unsigned char diff, bool checkpoint);
int step ();
int load (char *fileName, unsigned char diff, bool checkpoint); void draw ();
int step ();
void draw (int stats);
void timeCalcs (bool paused);
public: public:
Event *firstEvent; Event *firstEvent;
...@@ -150,9 +131,9 @@ class Level { ...@@ -150,9 +131,9 @@ class Level {
EventPath path[PATHS]; EventPath path[PATHS];
Level (); Level ();
Level (char *fileName, unsigned char diff, Level (char *fileName, unsigned char diff, bool checkpoint);
bool checkpoint);
virtual ~Level (); virtual ~Level ();
bool checkMask (fixed x, fixed y); bool checkMask (fixed x, fixed y);
bool checkMaskDown (fixed x, fixed y); bool checkMaskDown (fixed x, fixed y);
bool checkSpikes (fixed x, fixed y); bool checkSpikes (fixed x, fixed y);
...@@ -189,6 +170,7 @@ class DemoLevel : public Level { ...@@ -189,6 +170,7 @@ class DemoLevel : public Level {
public: public:
DemoLevel (const char *fileName); DemoLevel (const char *fileName);
~DemoLevel (); ~DemoLevel ();
int play (); int play ();
}; };
...@@ -196,8 +178,8 @@ class DemoLevel : public Level { ...@@ -196,8 +178,8 @@ class DemoLevel : public Level {
// Variables // Variables
EXTERN Level *level; EXTERN Level *level;
EXTERN fixed viewX, viewY; EXTERN fixed viewX, viewY;
#endif #endif
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
* levelframe.cpp * levelframe.cpp
* *
* 19th July 2009: Created levelframe.cpp from parts of level.cpp * 19th July 2009: Created levelframe.cpp from parts of level.cpp
* 30th March 2010: Created baselevel.cpp from parts of level.cpp and
* levelframe.cpp
* *
* Part of the OpenJazz project * Part of the OpenJazz project
* *
...@@ -173,7 +175,7 @@ int Level::step () { ...@@ -173,7 +175,7 @@ int Level::step () {
void Level::draw (int stats) { void Level::draw () {
GridElement *ge; GridElement *ge;
Event *event; Event *event;
...@@ -438,36 +440,6 @@ void Level::draw (int stats) { ...@@ -438,36 +440,6 @@ void Level::draw (int stats) {
// Fill in remaining energy bar space with black // Fill in remaining energy bar space with black
drawRect(dst.x, canvasH - 13, dst.w, 7, BLACK); drawRect(dst.x, canvasH - 13, dst.w, 7, BLACK);
// Draw graphics statistics
if (stats & S_SCREEN) {
#ifdef SCALE
if (scaleFactor > 1)
drawRect(viewW - 84, 11, 80, 37, BLACK);
else
#endif
drawRect(viewW - 84, 11, 80, 25, BLACK);
panelBigFont->showNumber(screenW, viewW - 52, 14);
panelBigFont->showString("x", viewW - 48, 14);
panelBigFont->showNumber(screenH, viewW - 12, 14);
panelBigFont->showString("fps", viewW - 76, 26);
panelBigFont->showNumber((int)smoothfps, viewW - 12, 26);
#ifdef SCALE
if (scaleFactor > 1) {
panelBigFont->showNumber(canvasW, viewW - 52, 38);
panelBigFont->showString("x", viewW - 48, 39);
panelBigFont->showNumber(canvasH, viewW - 12, 38);
}
#endif
}
return; return;
......
...@@ -285,7 +285,7 @@ int loadMain (int argc, char *argv[]) { ...@@ -285,7 +285,7 @@ int loadMain (int argc, char *argv[]) {
logError("Could not set video mode", SDL_GetError()); logError("Could not set video mode", SDL_GetError());
delete characterName; delete[] characterName;
delete firstPath; delete firstPath;
...@@ -319,7 +319,7 @@ int loadMain (int argc, char *argv[]) { ...@@ -319,7 +319,7 @@ int loadMain (int argc, char *argv[]) {
closeAudio(); closeAudio();
delete characterName; delete[] characterName;
delete firstPath; delete firstPath;
......
...@@ -81,8 +81,9 @@ int Menu::newGameDifficulty (int mode, int levelNum, int worldNum) { ...@@ -81,8 +81,9 @@ int Menu::newGameDifficulty (int mode, int levelNum, int worldNum) {
if (controls.release(C_ENTER)) { if (controls.release(C_ENTER)) {
playSound(S_ORB); playSound(S_ORB);
firstLevel = createFileName(F_LEVEL, levelNum, worldNum); if (levelNum == -1) firstLevel = createFileName(F_BONUSMAP, worldNum);
else firstLevel = createFileName(F_LEVEL, levelNum, worldNum);
if (mode == M_SINGLE) { if (mode == M_SINGLE) {
...@@ -118,6 +119,8 @@ int Menu::newGameDifficulty (int mode, int levelNum, int worldNum) { ...@@ -118,6 +119,8 @@ int Menu::newGameDifficulty (int mode, int levelNum, int worldNum) {
} }
delete[] firstLevel;
// Play the level(s) // Play the level(s)
...@@ -126,7 +129,6 @@ int Menu::newGameDifficulty (int mode, int levelNum, int worldNum) { ...@@ -126,7 +129,6 @@ int Menu::newGameDifficulty (int mode, int levelNum, int worldNum) {
case E_QUIT: case E_QUIT:
delete game; delete game;
delete[] firstLevel;
return E_QUIT; return E_QUIT;
...@@ -139,7 +141,6 @@ int Menu::newGameDifficulty (int mode, int levelNum, int worldNum) { ...@@ -139,7 +141,6 @@ int Menu::newGameDifficulty (int mode, int levelNum, int worldNum) {
} }
delete game; delete game;
delete[] firstLevel;
return E_NONE; return E_NONE;
...@@ -178,7 +179,8 @@ int Menu::newGameLevel (int mode) { ...@@ -178,7 +179,8 @@ int Menu::newGameLevel (int mode) {
else fontmn2->mapPalette(240, 8, 114, 16); else fontmn2->mapPalette(240, 8, 114, 16);
fontmn2->showString("choose level:", 32, (canvasH << 1) / 3); fontmn2->showString("choose level:", 32, (canvasH << 1) / 3);
fontmn2->showNumber(levelNum, 208, (canvasH << 1) / 3); if (levelNum >= 0) fontmn2->showNumber(levelNum, 208, (canvasH << 1) / 3);
else fontmn2->showString("bonus", 172, (canvasH << 1) / 3);
if (option != 0) fontmn2->restorePalette(); if (option != 0) fontmn2->restorePalette();
...@@ -188,14 +190,14 @@ int Menu::newGameLevel (int mode) { ...@@ -188,14 +190,14 @@ int Menu::newGameLevel (int mode) {
if (controls.release(C_LEFT)) { if (controls.release(C_LEFT)) {
if (option) levelNum = (levelNum + 9) % 10; if (option) levelNum = ((levelNum + 11) % 11) - 1;
else worldNum = (worldNum + 999) % 1000; else worldNum = (worldNum + 999) % 1000;
} }
if (controls.release(C_RIGHT)) { if (controls.release(C_RIGHT)) {
if (option) levelNum = (levelNum + 1) % 10; if (option) levelNum = ((levelNum + 2) % 11) - 1;
else worldNum = (worldNum + 1) % 1000; else worldNum = (worldNum + 1) % 1000;
} }
...@@ -223,7 +225,7 @@ int Menu::newGameEpisode (int mode) { ...@@ -223,7 +225,7 @@ int Menu::newGameEpisode (int mode) {
const char *options[12] = {"episode 1", "episode 2", "episode 3", const char *options[12] = {"episode 1", "episode 2", "episode 3",
"episode 4", "episode 5", "episode 6", "episode a", "episode b", "episode 4", "episode 5", "episode 6", "episode a", "episode b",
"episode c", "episode x", "bonus stage", "specific level"}; "episode c", "episode x", "bonus stage", "specific level"};
bool exists[12]; bool exists[12];
char *check; char *check;
SDL_Rect dst; SDL_Rect dst;
int episode, count, worldNum; int episode, count, worldNum;
...@@ -246,7 +248,10 @@ int Menu::newGameEpisode (int mode) { ...@@ -246,7 +248,10 @@ int Menu::newGameEpisode (int mode) {
} }
exists[10] = false; check = createFileName(F_BONUSMAP, 0);
exists[10] = fileExists(check);
delete[] check;
exists[11] = true; exists[11] = true;
episode = 0; episode = 0;
...@@ -307,17 +312,15 @@ int Menu::newGameEpisode (int mode) { ...@@ -307,17 +312,15 @@ int Menu::newGameEpisode (int mode) {
if (episode < 10) { if (episode < 10) {
if (episode < 6) worldNum = episode * 3; if (episode < 6) worldNum = episode * 3;
else if ((episode >= 6) && (episode < 9)) else if ((episode >= 6) && (episode < 9)) worldNum = (episode + 4) * 3;
worldNum = (episode + 4) * 3;
else worldNum = 50; else worldNum = 50;
if (newGameDifficulty(mode, 0, worldNum) == E_QUIT) if (newGameDifficulty(mode, 0, worldNum) == E_QUIT) return E_QUIT;
return E_QUIT;
} else if (episode == 10) { } else if (episode == 10) {
// TODO: Loading and playing of bonus levels if (newGameDifficulty(mode, -1, 0) == E_QUIT) return E_QUIT;
} else { } else {
if (newGameLevel(mode) == E_QUIT) return E_QUIT; if (newGameLevel(mode) == E_QUIT) return E_QUIT;
......
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