Commit 1f982b3b authored by alistert's avatar alistert

Added backgrounds to bonus levels.

parent 40768f56
...@@ -39,11 +39,15 @@ ...@@ -39,11 +39,15 @@
#include "player/player.h" #include "player/player.h"
#include <math.h> #include <math.h>
#include <string.h>
int Bonus::loadTiles (char *fileName) { int Bonus::loadTiles (char *fileName) {
File *file; File *file;
unsigned char *pixels;
unsigned char *sorted;
int count;
try { try {
...@@ -55,7 +59,16 @@ int Bonus::loadTiles (char *fileName) { ...@@ -55,7 +59,16 @@ int Bonus::loadTiles (char *fileName) {
} }
file->skipRLE(); // Load background
pixels = file->loadRLE(832 * 20);
sorted = new unsigned char[512 * 20];
for (count = 0; count < 20; count++) memcpy(sorted + (count * 512), pixels + (count * 832), 512);
background = createSurface(sorted, 512, 20);
delete[] sorted;
delete[] pixels;
// Load palette // Load palette
file->loadPalette(palette); file->loadPalette(palette);
...@@ -196,11 +209,8 @@ Bonus::Bonus (char * fileName, unsigned char diff) { ...@@ -196,11 +209,8 @@ Bonus::Bonus (char * fileName, unsigned char diff) {
firstPE = new RotatePaletteEffect(240, 16, -F32, firstPE); firstPE = new RotatePaletteEffect(240, 16, -F32, firstPE);
// Apply the palette to surfaces that already exist, e.g. fonts // Adjust fontsFont to use bonus level palette
usePalette(palette); fontsFont->mapPalette(0, 32, 15, -16);
// Adjust fontmn1 to use bonus level palette
fontsFont->mapPalette(0, 16, 15, -16);
return; return;
...@@ -278,7 +288,13 @@ int Bonus::step () { ...@@ -278,7 +288,13 @@ int Bonus::step () {
players[count].addItem(); players[count].addItem();
events[gridY][gridX] = 0; events[gridY][gridX] = 0;
if (players[count].getItems() >= items) return WON; if (players[count].getItems() >= items) {
players[count].addLife();
return WON;
}
break; break;
...@@ -314,25 +330,27 @@ void Bonus::draw () { ...@@ -314,25 +330,27 @@ void Bonus::draw () {
SDL_Rect src, dst; SDL_Rect src, dst;
int x, y; int x, y;
// Draw the ground
src.x = 0; src.x = 0;
src.w = 32; src.w = 32;
src.h = 32; src.h = 32;
int vX = FTOI(localPlayer->getX()) - (canvasW >> 1); int vX = FTOI(localPlayer->getX()) - (canvasW >> 1);
int vY = FTOI(localPlayer->getY()) - (canvasH >> 1); int vY = FTOI(localPlayer->getY()) - (canvasH >> 2);
for (y = 0; y <= ITOT(canvasH - 1) + 1; y++) { for (y = 0; y <= ITOT((canvasH >> 1) - 1) + 1; y++) {
for (x = 0; x <= ITOT(canvasW - 1) + 1; x++) { for (x = 0; x <= ITOT(canvasW - 1) + 1; x++) {
src.y = TTOI(tiles[(y + ITOT(vY) + BLH) % BLH][(x + ITOT(vX) + BLW) % BLW]); src.y = TTOI(tiles[(y + ITOT(vY) + BLH) % BLH][(x + ITOT(vX) + BLW) % BLW]);
dst.x = TTOI(x) - (vX & 31); dst.x = TTOI(x) - (vX & 31);
dst.y = TTOI(y) - (vY & 31); dst.y = (canvasH >> 1) + TTOI(y) - (vY & 31);
SDL_BlitSurface(tileSet, &src, canvas, &dst); SDL_BlitSurface(tileSet, &src, canvas, &dst);
dst.x = 12 + TTOI(x) - (vX & 31); dst.x = 12 + TTOI(x) - (vX & 31);
dst.y = 12 + TTOI(y) - (vY & 31); dst.y = (canvasH >> 1) + 12 + TTOI(y) - (vY & 31);
switch (events[(y + ITOT(vY) + BLH) % BLH][(x + ITOT(vX) + BLW) % BLW]) { switch (events[(y + ITOT(vY) + BLH) % BLH][(x + ITOT(vX) + BLW) % BLW]) {
...@@ -376,11 +394,29 @@ void Bonus::draw () { ...@@ -376,11 +394,29 @@ void Bonus::draw () {
} }
// Draw the background
for (x = -(localPlayer->getDirection() & 1023); x < canvasW; x += background->w) {
dst.x = x;
dst.y = (canvasH >> 1) - 4;
SDL_BlitSurface(background, NULL, canvas, &dst);
}
x = 171;
for (y = (canvasH >> 1) - 5; (y >= 0) && (x > 128); y--) drawRect(0, y, canvasW, 1, x--);
if (y > 0) drawRect(0, 0, canvasW, y + 1, 128);
// Draw the "player" // Draw the "player"
drawRect( drawRect(
(canvasW >> 1) + fixed(sin(localPlayer->getDirection() * 6.283185 / 1024.0) * 3) - 4, (canvasW >> 1) + fixed(sin(localPlayer->getDirection() * 6.283185 / 1024.0) * 3) - 4,
(canvasH >> 1) - fixed(cos(localPlayer->getDirection() * 6.283185 / 1024.0) * 3) - 4, 8, 8, 0); ((canvasH * 3) >> 2) - 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 * 3) >> 2) - 4, 8, 8, 22);
// Show gem count // Show gem count
...@@ -419,6 +455,10 @@ int Bonus::play () { ...@@ -419,6 +455,10 @@ int Bonus::play () {
option = 0; option = 0;
stats = S_NONE; stats = S_NONE;
returnTime = 0;
usePalette(palette);
while (true) { while (true) {
if (loop(NORMAL_LOOP) == E_QUIT) return E_QUIT; if (loop(NORMAL_LOOP) == E_QUIT) return E_QUIT;
......
...@@ -42,8 +42,9 @@ ...@@ -42,8 +42,9 @@
class Bonus : public BaseLevel { class Bonus : public BaseLevel {
private: private:
unsigned char tiles[BLH][BLW]; SDL_Surface *background;
unsigned char events[BLH][BLW]; unsigned char tiles[BLH][BLW];
unsigned char events[BLH][BLW];
int loadTiles (char *fileName); int loadTiles (char *fileName);
int step (); int step ();
......
...@@ -55,7 +55,8 @@ ...@@ -55,7 +55,8 @@
// Variables // Variables
EXTERN SDL_Surface *screen, *canvas; EXTERN SDL_Surface *screen, *canvas;
EXTERN int viewW, viewH, canvasW, canvasH, screenW, screenH; EXTERN int viewH, canvasW, canvasH, screenW, screenH;
#define viewW canvasW
#ifdef SCALE #ifdef SCALE
EXTERN int scaleFactor; EXTERN int scaleFactor;
#endif #endif
......
...@@ -103,6 +103,8 @@ int DemoLevel::play () { ...@@ -103,6 +103,8 @@ int DemoLevel::play () {
stats = S_NONE; stats = S_NONE;
usePalette(palette);
while (true) { while (true) {
// Do general processing // Do general processing
......
...@@ -527,6 +527,8 @@ int Level::play () { ...@@ -527,6 +527,8 @@ int Level::play () {
timeBonus = -1; timeBonus = -1;
perfect = 0; perfect = 0;
usePalette(palette);
while (true) { while (true) {
if (loop(NORMAL_LOOP) == E_QUIT) return E_QUIT; if (loop(NORMAL_LOOP) == E_QUIT) return E_QUIT;
......
...@@ -219,8 +219,6 @@ void Level::draw () { ...@@ -219,8 +219,6 @@ void Level::draw () {
dst.w = viewW; dst.w = viewW;
dst.h = viewH; dst.h = viewH;
SDL_SetClipRect(canvas, &dst); SDL_SetClipRect(canvas, &dst);
if ((viewW < canvasW) || (viewH < canvasH)) clearScreen(15);
// Set tile drawing dimensions // Set tile drawing dimensions
......
...@@ -996,10 +996,6 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) { ...@@ -996,10 +996,6 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) {
delete file; delete file;
// Apply the palette to surfaces that already exist, e.g. fonts
usePalette(palette);
// Set the tick at which the level will end // Set the tick at which the level will end
endTime = (5 - difficulty) * 2 * 60 * 1000; endTime = (5 - difficulty) * 2 * 60 * 1000;
......
...@@ -288,7 +288,7 @@ bool Player::takeEvent (unsigned char gridX, unsigned char gridY, unsigned int t ...@@ -288,7 +288,7 @@ bool Player::takeEvent (unsigned char gridX, unsigned char gridY, unsigned int t
case 4: // Extra life case 4: // Extra life
if (lives < 99) lives++; addLife();
break; break;
...@@ -633,6 +633,15 @@ int Player::getEnergy () { ...@@ -633,6 +633,15 @@ int Player::getEnergy () {
} }
void Player::addLife () {
if (lives < 99) lives++;
return;
}
int Player::getLives () { int Player::getLives () {
return lives; return lives;
......
...@@ -220,7 +220,8 @@ class Player : public Movable { ...@@ -220,7 +220,8 @@ class Player : public Movable {
bool hit (Player *source, unsigned int ticks); bool hit (Player *source, unsigned int ticks);
void kill (Player *source, unsigned int ticks); void kill (Player *source, unsigned int ticks);
void addItem (); void addItem ();
void addScore (int addedScore); void addLife ();
void addScore (int addedScore);
int getScore (); int getScore ();
int getEnergy (); int getEnergy ();
int getLives (); int getLives ();
......
...@@ -689,8 +689,7 @@ void Player::view (unsigned int ticks, int mspf) { ...@@ -689,8 +689,7 @@ void Player::view (unsigned int ticks, int mspf) {
oldViewY = viewY; oldViewY = viewY;
// Can we see below the panel? // Can we see below the panel?
viewW = canvasW; if (canvasW > SW) viewH = canvasH;
if (viewW > panel->w) viewH = canvasH;
else viewH = canvasH - 33; else viewH = canvasH - 33;
// Find new position // Find new position
......
...@@ -242,8 +242,7 @@ int Scene::play () { ...@@ -242,8 +242,7 @@ int Scene::play () {
if (palette) { if (palette) {
// usePalette(palette); usePalette(palette->palette);
currentPalette = palette->palette;
// Fade in from black // Fade in from black
firstPE = new FadeInPaletteEffect(250, firstPE); firstPE = new FadeInPaletteEffect(250, firstPE);
......
...@@ -117,8 +117,7 @@ void Scene::loadAni (File *f, int dataIndex) { ...@@ -117,8 +117,7 @@ void Scene::loadAni (File *f, int dataIndex) {
if (!background) background = f->loadSurface(SW, SH); if (!background) background = f->loadSurface(SW, SH);
// Use the most recently loaded palette // Use the most recently loaded palette
SDL_SetPalette(screen, SDL_PHYSPAL, palettes->palette, 0, 256); usePalette(palettes->palette);
currentPalette = palettes->palette;
break; break;
......
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