Commit 1f982b3b authored by alistert's avatar alistert

Added backgrounds to bonus levels.

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