Commit dddcca49 authored by alistert's avatar alistert

Moved guardian energy bars to the foreground. Changed the way post-level bonus...

Moved guardian energy bars to the foreground. Changed the way post-level bonus levels and cutscenes are launched. Disabled bonus levels in multiplayer.
parent 9c407701
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "io/gfx/video.h" #include "io/gfx/video.h"
#include "io/sound.h" #include "io/sound.h"
#include "player/player.h" #include "player/player.h"
#include "scene/scene.h"
#include "baselevel.h" #include "baselevel.h"
...@@ -72,6 +73,33 @@ BaseLevel::~BaseLevel () { ...@@ -72,6 +73,33 @@ BaseLevel::~BaseLevel () {
} }
int BaseLevel::playScene (char* file) {
Scene* scene;
int ret;
delete paletteEffects;
paletteEffects = NULL;
try {
scene = new Scene(file);
} catch (int e) {
return e;
}
ret = scene->play();
delete scene;
return ret;
}
void BaseLevel::timeCalcs () { void BaseLevel::timeCalcs () {
// Calculate smoothed fps // Calculate smoothed fps
......
...@@ -72,6 +72,7 @@ class BaseLevel { ...@@ -72,6 +72,7 @@ class BaseLevel {
bool paused; bool paused;
LevelStage stage; LevelStage stage;
int playScene (char* file);
void timeCalcs (); void timeCalcs ();
void drawStats (int stats, unsigned char bg); void drawStats (int stats, unsigned char bg);
......
...@@ -254,6 +254,17 @@ Bonus::Bonus (char * fileName, unsigned char diff) { ...@@ -254,6 +254,17 @@ Bonus::Bonus (char * fileName, unsigned char diff) {
delete[] buffer; delete[] buffer;
// Generate player's animation set references
string = new char[PANIMS];
for (count = 0; count < PANIMS; count++) string[count] = count & 31;
for (count = 0; count < nPlayers; count++) players[count].setAnims(string);
delete[] string;
// Load tiles // Load tiles
file->seek(2694, true); file->seek(2694, true);
...@@ -726,7 +737,13 @@ int Bonus::play () { ...@@ -726,7 +737,13 @@ int Bonus::play () {
// Check if level has been won // Check if level has been won
if (returnTime && (ticks > returnTime)) { if (returnTime && (ticks > returnTime)) {
if (localPlayer->getItems() >= items) return WON; if (localPlayer->getItems() >= items) {
if (playScene(F_BONUS_0SC) == E_QUIT) return E_QUIT;
return WON;
}
return LOST; return LOST;
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include "io/sound.h" #include "io/sound.h"
#include "level/level.h" #include "level/level.h"
#include "player/player.h" #include "player/player.h"
#include "scene/scene.h"
#include <string.h> #include <string.h>
...@@ -41,7 +40,6 @@ ...@@ -41,7 +40,6 @@
Game::Game () { Game::Game () {
levelFile = NULL; levelFile = NULL;
bonusFile = NULL;
players = NULL; players = NULL;
...@@ -52,17 +50,7 @@ Game::Game () { ...@@ -52,17 +50,7 @@ Game::Game () {
Game::Game (char *firstLevel, int gameDifficulty) { Game::Game (char *firstLevel, int gameDifficulty) {
if (!strncmp(firstLevel, F_BONUSMAP, 8)) { levelFile = createString(firstLevel);
levelFile = NULL;
bonusFile = createString(firstLevel);
} else {
levelFile = createString(firstLevel);
bonusFile = NULL;
}
difficulty = gameDifficulty; difficulty = gameDifficulty;
...@@ -81,7 +69,6 @@ Game::Game (char *firstLevel, int gameDifficulty) { ...@@ -81,7 +69,6 @@ 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;
...@@ -103,41 +90,62 @@ int Game::setLevel (char *fileName) { ...@@ -103,41 +90,62 @@ int Game::setLevel (char *fileName) {
} }
int Game::setBonus (int ext) {
if (bonusFile) delete[] bonusFile;
if (ext >= 0) bonusFile = createFileName(F_BONUSMAP, ext);
else bonusFile = NULL;
return E_NONE;
}
int Game::play () { int Game::play () {
Bonus *bonus; Bonus* bonus;
Scene *scene; char* bonusFile;
bool checkpoint; bool checkpoint;
int levelRet, bonusRet; int ret;
checkpoint = false; checkpoint = false;
// Play the level(s) // Play the level(s)
while (true) { while (true) {
if (!levelFile) return E_NONE;
sendTime = checkTime = 0; sendTime = checkTime = 0;
level = NULL; // Load and play the level
if (levelFile) { if (!strncmp(levelFile, F_BONUSMAP, 8)) {
// Load and play the level try {
bonus = new Bonus(levelFile, difficulty);
} catch (int e) {
return e;
}
ret = bonus->play();
if (ret <= 0) {
delete bonus;
if (ret == E_NONE) playMusic("menusng.psm");
return ret;
} else if (ret == WON) {
// Go to next level
bonusFile = createFileName(F_BONUSMAP, (levelFile[10] * 10) + levelFile[11] - 527);
setLevel(bonusFile);
delete[] bonusFile;
}
delete bonus;
} else {
try { try {
level = new Level(levelFile, difficulty, checkpoint); level = new Level(levelFile, difficulty, checkpoint);
} catch (int e) { } catch (int e) {
...@@ -146,149 +154,38 @@ int Game::play () { ...@@ -146,149 +154,38 @@ int Game::play () {
} }
levelRet = level->play(); ret = level->play();
if (levelRet < 0) {
delete level;
return levelRet;
} else if (levelRet == E_NONE) {
delete level;
playMusic("menusng.psm");
return E_NONE;
}
} else levelRet = WON;
if (bonusFile && (levelRet == WON)) {
// Load and play the bonus level
try {
bonus = new Bonus(bonusFile, difficulty);
} catch (int e) {
return e;
}
if (levelFile) {
delete[] bonusFile;
bonusFile = NULL;
}
bonusRet = bonus->play();
delete bonus;
if (bonusRet == E_QUIT) {
if (level) delete level;
return E_QUIT;
} else if (bonusRet == E_NONE) {
if (level) delete level;
playMusic("menusng.psm");
return E_NONE;
} else if (bonusRet == WON) {
try {
scene = new Scene(F_BONUS_0SC);
} catch (int e) {
scene = NULL;
}
if (scene) {
if (scene->play() == E_QUIT) {
delete scene;
if (level) delete level;
return E_QUIT;
}
delete scene;
}
// If part of a bonus-only game, go to next level
if (!level) setBonus((bonusFile[10] * 10) + bonusFile[11] - 527);
}
}
if (!level) continue;
if (levelRet == WON) {
// Won the level
// If there is no next level, load and play the cutscene
if (!levelFile) {
scene = level->createScene();
if (ret <= 0) {
delete level; delete level;
if (scene) { if (ret == E_NONE) playMusic("menusng.psm");
if (scene->play() == E_QUIT) { return ret;
delete scene; } else if (ret == WON) {
return E_QUIT; // Won the level
} // Do not use old level's checkpoint coordinates
checkpoint = false;
delete scene;
} else {
}
// Lost the level
return E_NONE;
if (!localPlayer->getLives()) return E_NONE;
// Use checkpoint coordinates
checkpoint = true;
} }
// Do not use old level's checkpoint coordinates delete level;
checkpoint = false;
}
} else {
// Lost the level
if (!localPlayer->getLives()) return E_NONE;
// Use checkpoint coordinates
checkpoint = true;
}
delete level;
} }
......
...@@ -85,8 +85,7 @@ class Player; ...@@ -85,8 +85,7 @@ class Player;
class Game { 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;
...@@ -98,7 +97,6 @@ class Game { ...@@ -98,7 +97,6 @@ class Game {
virtual ~Game (); virtual ~Game ();
virtual int setLevel (char *fileName); virtual int setLevel (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);
......
...@@ -105,7 +105,8 @@ class Event : public Movable { ...@@ -105,7 +105,8 @@ class Event : public Movable {
virtual bool overlap (fixed left, fixed top, fixed width, fixed height); virtual bool overlap (fixed left, fixed top, fixed width, fixed height);
signed char getProperty (unsigned char property); signed char getProperty (unsigned char property);
virtual Event* step (unsigned int ticks, int msps); virtual Event* step (unsigned int ticks, int msps);
virtual void draw (unsigned int ticks, int change); virtual void draw (unsigned int ticks, int change);
void drawEnergy (unsigned int ticks);
}; };
......
...@@ -919,7 +919,6 @@ void Event::draw (unsigned int ticks, int change) { ...@@ -919,7 +919,6 @@ void Event::draw (unsigned int ticks, int change) {
Anim* anim; Anim* anim;
signed char* set; signed char* set;
int count;
if (next) next->draw(ticks, change); if (next) next->draw(ticks, change);
...@@ -972,34 +971,51 @@ void Event::draw (unsigned int ticks, int change) { ...@@ -972,34 +971,51 @@ void Event::draw (unsigned int ticks, int change) {
} }
if ((set[E_MODIFIER] == 8) && set[E_HITSTOKILL]) {
// Draw boss energy bar
count = level->getEventHits(gridX, gridY) * 100 / set[E_HITSTOKILL];
// Devan head
anim = level->getMiscAnim(1);
anim->setFrame(0, true);
if (ticks < flashTime) anim->flashPalette(0);
anim->draw(ITOF(viewW - 44), ITOF(count + 48));
if (ticks < flashTime) anim->restorePalette();
// Bar
drawRect(viewW - 40, count + 40, 12, 100 - count,
(ticks < flashTime)? 0: 32);
}
return; return;
} }
void Event::drawEnergy (unsigned int ticks) {
Anim* anim;
signed char* set;
int hits;
// Get the event properties
set = level->getEvent(gridX, gridY);
if (set[E_MODIFIER] != 8) {
if (next) next->drawEnergy(ticks);
} else if (set[E_HITSTOKILL]) {
// Draw boss energy bar
hits = level->getEventHits(gridX, gridY) * 100 / set[E_HITSTOKILL];
// Devan head
anim = level->getMiscAnim(1);
anim->setFrame(0, true);
if (ticks < flashTime) anim->flashPalette(0);
anim->draw(ITOF(viewW - 44), ITOF(hits + 48));
if (ticks < flashTime) anim->restorePalette();
// Bar
drawRect(viewW - 40, hits + 40, 12, 100 - hits, (ticks < flashTime)? 0: 32);
}
return;
}
...@@ -131,7 +131,6 @@ void DeckGuardian::draw (unsigned int ticks, int change) { ...@@ -131,7 +131,6 @@ void DeckGuardian::draw (unsigned int ticks, int change) {
Anim* anim; Anim* anim;
signed char* set; signed char* set;
int count;
if (next) next->draw(ticks, change); if (next) next->draw(ticks, change);
...@@ -163,32 +162,6 @@ void DeckGuardian::draw (unsigned int ticks, int change) { ...@@ -163,32 +162,6 @@ void DeckGuardian::draw (unsigned int ticks, int change) {
} }
if (set[E_HITSTOKILL]) {
// Draw boss energy bar
count = level->getEventHits(gridX, gridY) * 100 / set[E_HITSTOKILL];
// Devan head
anim = level->getMiscAnim(1);
anim->setFrame(0, true);
if (ticks < flashTime) anim->flashPalette(0);
anim->draw(ITOF(viewW - 44), ITOF(count + 48));
if (ticks < flashTime) anim->restorePalette();
// Bar
drawRect(viewW - 40, count + 40, 12, 100 - count,
(ticks < flashTime)? 0: 32);
}
return; return;
} }
......
...@@ -39,7 +39,8 @@ ...@@ -39,7 +39,8 @@
#include "bullet.h" #include "bullet.h"
#include "event/event.h" #include "event/event.h"
#include "level.h" #include "level.h"
#include "bonus/bonus.h"
#include "game/game.h" #include "game/game.h"
#include "game/gamemode.h" #include "game/gamemode.h"
#include "io/controls.h" #include "io/controls.h"
...@@ -414,22 +415,43 @@ LevelStage Level::getStage () { ...@@ -414,22 +415,43 @@ LevelStage Level::getStage () {
} }
Scene* Level::createScene () {
try { int Level::playBonus () {
Bonus *bonus;
char *bonusFile;
int ret;
if (!localPlayer->hasGem()) return E_NONE;
delete paletteEffects;
paletteEffects = NULL;
bonusFile = createFileName(F_BONUSMAP, 0);
try {
return new Scene(sceneFile); bonus = new Bonus(bonusFile, difficulty);
} catch (int e) { } catch (int e) {
return NULL; return e;
}
delete[] bonusFile;
ret = bonus->play();
delete bonus;
if (ret == E_NONE) playMusic("menusng.psm");
return ret;
}
}
}
void Level::receive (unsigned char* buffer) { void Level::receive (unsigned char* buffer) {
// Interpret data received from client/server // Interpret data received from client/server
...@@ -590,9 +612,21 @@ int Level::play () { ...@@ -590,9 +612,21 @@ int Level::play () {
// Check if level has been won // Check if level has been won
if (game && returnTime && (ticks > returnTime)) { if (game && returnTime && (ticks > returnTime)) {
if (nextLevelNum == 99) count = game->setLevel(NULL); if (!gameMode) {
else {
// If the gem has been collected, play the bonus level
if (playBonus() == E_QUIT) return E_QUIT;
}
if (nextLevelNum == 99) {
if (playScene(sceneFile) == E_QUIT) return E_QUIT;
count = game->setLevel(NULL);
} else {
string = createFileName(F_LEVEL, nextLevelNum, nextWorldNum); string = createFileName(F_LEVEL, nextLevelNum, nextWorldNum);
count = game->setLevel(string); count = game->setLevel(string);
...@@ -601,7 +635,7 @@ int Level::play () { ...@@ -601,7 +635,7 @@ int Level::play () {
} }
if (count < 0) return count; if (count < 0) return count;
return WON; return WON;
} }
......
...@@ -92,7 +92,7 @@ class Scene; ...@@ -92,7 +92,7 @@ class Scene;
class Level : public BaseLevel { class Level : public BaseLevel {
private: private:
char* sceneFile; char* sceneFile;
Anim animSet[ANIMS]; Anim animSet[ANIMS];
char miscAnims[4]; char miscAnims[4];
signed char bulletSet[BULLETS][BLENGTH]; signed char bulletSet[BULLETS][BLENGTH];
...@@ -109,11 +109,12 @@ class Level : public BaseLevel { ...@@ -109,11 +109,12 @@ class Level : public BaseLevel {
fixed waterLevel; fixed waterLevel;
fixed waterLevelTarget; fixed waterLevelTarget;
fixed waterLevelSpeed; fixed waterLevelSpeed;
fixed energyBar; fixed energyBar;
void loadSprite (File* file, Sprite* sprite); void loadSprite (File* file, Sprite* sprite);
int loadSprites (char* fileName); int loadSprites (char* fileName);
int loadTiles (char* fileName); int loadTiles (char* fileName);
int playBonus ();
protected: protected:
int load (char* fileName, unsigned char diff, bool checkpoint); int load (char* fileName, unsigned char diff, bool checkpoint);
...@@ -148,8 +149,7 @@ class Level : public BaseLevel { ...@@ -148,8 +149,7 @@ class Level : public BaseLevel {
fixed getWaterLevel (); fixed getWaterLevel ();
void playSound (int sound); void playSound (int sound);
void setStage (LevelStage stage); void setStage (LevelStage stage);
LevelStage getStage (); LevelStage getStage ();
Scene* createScene ();
void receive (unsigned char* buffer); void receive (unsigned char* buffer);
virtual int play (); virtual int play ();
......
...@@ -325,12 +325,14 @@ void Level::draw () { ...@@ -325,12 +325,14 @@ void Level::draw () {
drawRect(0, FTOI(waterLevel - viewY) + 6, canvasW, 1, 24); drawRect(0, FTOI(waterLevel - viewY) + 6, canvasW, 1, 24);
drawRect(0, FTOI(waterLevel - viewY) + 10, canvasW, 1, 24); drawRect(0, FTOI(waterLevel - viewY) + 10, canvasW, 1, 24);
// Show active guardian's energy bar
SDL_SetClipRect(canvas, NULL); if (events) events->drawEnergy(ticks);
// Show panel // Show panel
SDL_SetClipRect(canvas, NULL);
// Change the ammo type display on the panel // Change the ammo type display on the panel
dst.x = 250; dst.x = 250;
dst.y = 2; dst.y = 2;
......
...@@ -247,10 +247,14 @@ int Menu::newGameEpisode (GameModeType mode) { ...@@ -247,10 +247,14 @@ int Menu::newGameEpisode (GameModeType mode) {
SDL_SetPalette(screens[count + 3], SDL_LOGPAL, palettes[3], 0, 256); SDL_SetPalette(screens[count + 3], SDL_LOGPAL, palettes[3], 0, 256);
} }
check = createFileName(F_BONUSMAP, 0); if (mode == M_SINGLE) {
exists[10] = fileExists(check);
delete[] check; check = createFileName(F_BONUSMAP, 0);
exists[10] = fileExists(check);
delete[] check;
} else exists[10] = false;
exists[11] = true; exists[11] = true;
......
...@@ -77,9 +77,6 @@ void Player::init (char *playerName, unsigned char *playerCols, unsigned char ne ...@@ -77,9 +77,6 @@ void Player::init (char *playerName, unsigned char *playerCols, unsigned char ne
// Assign name // Assign name
name = createString(playerName); name = createString(playerName);
// Create default animation mappings
for (count = 0; count < PANIMS; count++) anims[count] = count & 31;
// Assign initial values // Assign initial values
score = 0; score = 0;
...@@ -224,6 +221,7 @@ void Player::reset () { ...@@ -224,6 +221,7 @@ void Player::reset () {
dx = 0; dx = 0;
dy = 0; dy = 0;
enemies = items = 0; enemies = items = 0;
gem = false;
return; return;
...@@ -406,7 +404,7 @@ bool Player::takeEvent (unsigned char gridX, unsigned char gridY, unsigned int t ...@@ -406,7 +404,7 @@ bool Player::takeEvent (unsigned char gridX, unsigned char gridY, unsigned int t
case 37: // Diamond case 37: // Diamond
if (game) game->setBonus(0); gem = true;
// Yellow flash // Yellow flash
paletteEffects = new FlashPaletteEffect(255, 255, 0, 320, paletteEffects); paletteEffects = new FlashPaletteEffect(255, 255, 0, 320, paletteEffects);
...@@ -736,6 +734,13 @@ unsigned char Player::getTeam () { ...@@ -736,6 +734,13 @@ unsigned char Player::getTeam () {
} }
bool Player::hasGem () {
return gem;
}
void Player::setEvent (unsigned char gridX, unsigned char gridY) { void Player::setEvent (unsigned char gridX, unsigned char gridY) {
......
...@@ -207,6 +207,7 @@ class Player : public Movable { ...@@ -207,6 +207,7 @@ class Player : public Movable {
unsigned int warpTime; unsigned int warpTime;
int enemies, items; int enemies, items;
unsigned char team; unsigned char team;
bool gem;
void addAmmo (int type, int amount); void addAmmo (int type, int amount);
...@@ -244,7 +245,8 @@ class Player : public Movable { ...@@ -244,7 +245,8 @@ class Player : public Movable {
bool getFacing (); bool getFacing ();
fixed getDirection (); fixed getDirection ();
unsigned char getAnim (); unsigned char getAnim ();
unsigned char getTeam (); unsigned char getTeam ();
bool hasGem ();
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);
......
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