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 @@
#include "io/gfx/video.h"
#include "io/sound.h"
#include "player/player.h"
#include "scene/scene.h"
#include "baselevel.h"
......@@ -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 () {
// Calculate smoothed fps
......
......@@ -72,6 +72,7 @@ class BaseLevel {
bool paused;
LevelStage stage;
int playScene (char* file);
void timeCalcs ();
void drawStats (int stats, unsigned char bg);
......
......@@ -254,6 +254,17 @@ Bonus::Bonus (char * fileName, unsigned char diff) {
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
file->seek(2694, true);
......@@ -726,7 +737,13 @@ int Bonus::play () {
// Check if level has been won
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;
......
......@@ -33,7 +33,6 @@
#include "io/sound.h"
#include "level/level.h"
#include "player/player.h"
#include "scene/scene.h"
#include <string.h>
......@@ -41,7 +40,6 @@
Game::Game () {
levelFile = NULL;
bonusFile = NULL;
players = NULL;
......@@ -52,17 +50,7 @@ Game::Game () {
Game::Game (char *firstLevel, int gameDifficulty) {
if (!strncmp(firstLevel, F_BONUSMAP, 8)) {
levelFile = NULL;
bonusFile = createString(firstLevel);
} else {
levelFile = createString(firstLevel);
bonusFile = NULL;
}
levelFile = createString(firstLevel);
difficulty = gameDifficulty;
......@@ -81,7 +69,6 @@ Game::Game (char *firstLevel, int gameDifficulty) {
Game::~Game () {
if (levelFile) delete[] levelFile;
if (bonusFile) delete[] levelFile;
if (players) delete[] players;
localPlayer = NULL;
......@@ -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 () {
Bonus *bonus;
Scene *scene;
Bonus* bonus;
char* bonusFile;
bool checkpoint;
int levelRet, bonusRet;
int ret;
checkpoint = false;
// Play the level(s)
while (true) {
if (!levelFile) return E_NONE;
sendTime = checkTime = 0;
level = NULL;
if (levelFile) {
// Load and play the level
// Load and play the level
if (!strncmp(levelFile, F_BONUSMAP, 8)) {
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 {
level = new Level(levelFile, difficulty, checkpoint);
} catch (int e) {
......@@ -146,149 +154,38 @@ int Game::play () {
}
levelRet = 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();
ret = level->play();
if (ret <= 0) {
delete level;
if (scene) {
if (scene->play() == E_QUIT) {
delete scene;
return E_QUIT;
}
delete scene;
}
return E_NONE;
if (ret == E_NONE) playMusic("menusng.psm");
return ret;
} else if (ret == WON) {
// Won the level
// Do not use old level's checkpoint coordinates
checkpoint = false;
} else {
// Lost the level
if (!localPlayer->getLives()) return E_NONE;
// Use checkpoint coordinates
checkpoint = true;
}
// Do not use old level's checkpoint coordinates
checkpoint = false;
} else {
// Lost the level
if (!localPlayer->getLives()) return E_NONE;
// Use checkpoint coordinates
checkpoint = true;
}
delete level;
delete level;
}
}
......
......@@ -85,8 +85,7 @@ class Player;
class Game {
protected:
char *levelFile;
char *bonusFile;
char *levelFile;
int difficulty;
unsigned int sendTime, checkTime;
unsigned char checkX, checkY;
......@@ -98,7 +97,6 @@ class Game {
virtual ~Game ();
virtual int setLevel (char *fileName);
int setBonus (int ext);
int play ();
void view (int change);
virtual void send (unsigned char *buffer);
......
......@@ -105,7 +105,8 @@ class Event : public Movable {
virtual bool overlap (fixed left, fixed top, fixed width, fixed height);
signed char getProperty (unsigned char property);
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) {
Anim* anim;
signed char* set;
int count;
if (next) next->draw(ticks, 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;
}
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) {
Anim* anim;
signed char* set;
int count;
if (next) next->draw(ticks, 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;
}
......
......@@ -39,7 +39,8 @@
#include "bullet.h"
#include "event/event.h"
#include "level.h"
#include "bonus/bonus.h"
#include "game/game.h"
#include "game/gamemode.h"
#include "io/controls.h"
......@@ -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) {
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) {
// Interpret data received from client/server
......@@ -590,9 +612,21 @@ int Level::play () {
// Check if level has been won
if (game && returnTime && (ticks > returnTime)) {
if (nextLevelNum == 99) count = game->setLevel(NULL);
else {
if (!gameMode) {
// 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);
count = game->setLevel(string);
......@@ -601,7 +635,7 @@ int Level::play () {
}
if (count < 0) return count;
return WON;
}
......
......@@ -92,7 +92,7 @@ class Scene;
class Level : public BaseLevel {
private:
char* sceneFile;
char* sceneFile;
Anim animSet[ANIMS];
char miscAnims[4];
signed char bulletSet[BULLETS][BLENGTH];
......@@ -109,11 +109,12 @@ class Level : public BaseLevel {
fixed waterLevel;
fixed waterLevelTarget;
fixed waterLevelSpeed;
fixed energyBar;
fixed energyBar;
void loadSprite (File* file, Sprite* sprite);
int loadSprites (char* fileName);
int loadTiles (char* fileName);
int loadTiles (char* fileName);
int playBonus ();
protected:
int load (char* fileName, unsigned char diff, bool checkpoint);
......@@ -148,8 +149,7 @@ class Level : public BaseLevel {
fixed getWaterLevel ();
void playSound (int sound);
void setStage (LevelStage stage);
LevelStage getStage ();
Scene* createScene ();
LevelStage getStage ();
void receive (unsigned char* buffer);
virtual int play ();
......
......@@ -325,12 +325,14 @@ void Level::draw () {
drawRect(0, FTOI(waterLevel - viewY) + 6, canvasW, 1, 24);
drawRect(0, FTOI(waterLevel - viewY) + 10, canvasW, 1, 24);
SDL_SetClipRect(canvas, NULL);
// Show active guardian's energy bar
if (events) events->drawEnergy(ticks);
// Show panel
SDL_SetClipRect(canvas, NULL);
// Change the ammo type display on the panel
dst.x = 250;
dst.y = 2;
......
......@@ -247,10 +247,14 @@ int Menu::newGameEpisode (GameModeType mode) {
SDL_SetPalette(screens[count + 3], SDL_LOGPAL, palettes[3], 0, 256);
}
check = createFileName(F_BONUSMAP, 0);
exists[10] = fileExists(check);
delete[] check;
if (mode == M_SINGLE) {
check = createFileName(F_BONUSMAP, 0);
exists[10] = fileExists(check);
delete[] check;
} else exists[10] = false;
exists[11] = true;
......
......@@ -77,9 +77,6 @@ void Player::init (char *playerName, unsigned char *playerCols, unsigned char ne
// Assign name
name = createString(playerName);
// Create default animation mappings
for (count = 0; count < PANIMS; count++) anims[count] = count & 31;
// Assign initial values
score = 0;
......@@ -224,6 +221,7 @@ void Player::reset () {
dx = 0;
dy = 0;
enemies = items = 0;
gem = false;
return;
......@@ -406,7 +404,7 @@ bool Player::takeEvent (unsigned char gridX, unsigned char gridY, unsigned int t
case 37: // Diamond
if (game) game->setBonus(0);
gem = true;
// Yellow flash
paletteEffects = new FlashPaletteEffect(255, 255, 0, 320, paletteEffects);
......@@ -736,6 +734,13 @@ unsigned char Player::getTeam () {
}
bool Player::hasGem () {
return gem;
}
void Player::setEvent (unsigned char gridX, unsigned char gridY) {
......
......@@ -207,6 +207,7 @@ class Player : public Movable {
unsigned int warpTime;
int enemies, items;
unsigned char team;
bool gem;
void addAmmo (int type, int amount);
......@@ -244,7 +245,8 @@ class Player : public Movable {
bool getFacing ();
fixed getDirection ();
unsigned char getAnim ();
unsigned char getTeam ();
unsigned char getTeam ();
bool hasGem ();
void send (unsigned char* data);
void receive (unsigned char* buffer);
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