| 1 | |
| 2 | /** |
| 3 | * |
| 4 | * @file level.h |
| 5 | * |
| 6 | * Part of the OpenJazz project |
| 7 | * |
| 8 | * @par History: |
| 9 | * - 23rd August 2005: Created OpenJazz.h |
| 10 | * - 31st January 2006: Created level.h from parts of OpenJazz.h |
| 11 | * - 30th March 2010: Created baselevel.h from parts of level.h |
| 12 | * - 1st August 2012: Renamed baselevel.h to level.h |
| 13 | * |
| 14 | * @par Licence: |
| 15 | * Copyright (c) 2005-2017 AJ Thomson |
| 16 | * |
| 17 | * OpenJazz is distributed under the terms of |
| 18 | * the GNU General Public License, version 2.0 |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | |
| 23 | #ifndef _BASELEVEL_H |
| 24 | #define _BASELEVEL_H |
| 25 | |
| 26 | #include "menu/menu.h" |
| 27 | |
| 28 | #ifdef OJ_SDL3 |
| 29 | #include <SDL3/SDL.h> |
| 30 | #else |
| 31 | #include <SDL.h> |
| 32 | #endif |
| 33 | |
| 34 | // Macros |
| 35 | |
| 36 | // For converting between tile positions and int/fixed values |
| 37 | #define FTOT(x) ((x) >> 15) ///< Fixed to Tile |
| 38 | #define TTOF(x) ((x) << 15) ///< Tile to Fixed |
| 39 | #define ITOT(x) ((x) >> 5) ///< Int to Tile |
| 40 | #define TTOI(x) ((x) << 5) ///< Tile to Int |
| 41 | |
| 42 | |
| 43 | // Constants |
| 44 | |
| 45 | // Return values |
| 46 | #define WON 1 |
| 47 | #define LOST 2 |
| 48 | |
| 49 | // Time interval |
| 50 | #define T_STEP 16 |
| 51 | |
| 52 | |
| 53 | // Enums |
| 54 | |
| 55 | /// Level type |
| 56 | enum LevelType { |
| 57 | |
| 58 | LT_JJ1 = 0, ///< JJ1 level |
| 59 | LT_JJ1BONUS = 1, ///< JJ1 bonus level |
| 60 | #ifdef ENABLE_JJ2 |
| 61 | LT_JJ2 = 2 ///< JJ2 level |
| 62 | #endif |
| 63 | |
| 64 | }; |
| 65 | |
| 66 | /// Which stats to display on-screen |
| 67 | enum LevelStats { |
| 68 | |
| 69 | S_PLAYERS = 1, ///< Display player list |
| 70 | S_SCREEN = 2 ///< Display video statisitics |
| 71 | |
| 72 | }; |
| 73 | |
| 74 | /// Level stage |
| 75 | enum LevelStage { |
| 76 | |
| 77 | LS_NORMAL = 0, ///< Normal gameplay |
| 78 | LS_SUDDENDEATH = 1, ///< Sudden death |
| 79 | LS_END = 2 ///< Ending sequence |
| 80 | |
| 81 | }; |
| 82 | |
| 83 | |
| 84 | // Classes |
| 85 | |
| 86 | class Anim; |
| 87 | class File; |
| 88 | class Game; |
| 89 | class PaletteEffect; |
| 90 | class Sprite; |
| 91 | |
| 92 | /// Base class for all level classes |
| 93 | class Level { |
| 94 | |
| 95 | private: |
| 96 | const char* menuOptions[6]; |
| 97 | SetupMenu setupMenu; ///< Setup menu to run on the player's command |
| 98 | FileMenu fileMenu; ///< Save and Load menus to run on the player's command |
| 99 | |
| 100 | int select (bool& menu, int option); |
| 101 | |
| 102 | protected: |
| 103 | Game* game; |
| 104 | PaletteEffect* paletteEffects; ///< Palette effects in use while playing the level |
| 105 | SDL_Color palette[MAX_PALETTE_COLORS]; ///< Palette in use while playing the level |
| 106 | int sprites; ///< The number of sprite that have been loaded |
| 107 | unsigned int tickOffset; ///< Level time offset from system time |
| 108 | unsigned int steps; ///< Number of steps taken |
| 109 | unsigned int prevTicks; ///< Time the last visual update started |
| 110 | unsigned int ticks; ///< Current time |
| 111 | unsigned int endTime; ///< Tick at which the level will end |
| 112 | float smoothfps; ///< Smoothed FPS counter |
| 113 | int items; ///< Number of items to be collected |
| 114 | bool multiplayer; ///< Whether or not this is a multiplayer game |
| 115 | bool paused; ///< Whether or not the level is paused |
| 116 | LevelStage stage; ///< Level stage |
| 117 | int stats; ///< Which statistics to display on-screen, see #LevelStats |
| 118 | |
| 119 | void createLevelPlayers (LevelType levelType, Anim** anims, Anim** flippedAnims, bool checkpoint, unsigned char x, unsigned char y); |
| 120 | |
| 121 | int playScene (const char* file); |
| 122 | void timeCalcs (); |
| 123 | int getTimeChange (); |
| 124 | void drawOverlay (unsigned char bg, bool menu, int option, |
| 125 | unsigned char textPalIndex, unsigned char selectedTextPalIndex, |
| 126 | int textPalSpan); |
| 127 | int loop (bool& menu, int& option, bool& message); |
| 128 | |
| 129 | public: |
| 130 | explicit Level(Game* owner); |
| 131 | virtual ~Level(); |
| 132 | |
| 133 | void addTimer (int seconds); |
| 134 | LevelStage getStage (); |
| 135 | void setStage (LevelStage stage); |
| 136 | virtual void receive (unsigned char* buffer) = 0; |
| 137 | |
| 138 | }; |
| 139 | |
| 140 | |
| 141 | // Variables |
| 142 | |
| 143 | EXTERN fixed viewX, viewY; ///< Level viewing co-ordinates |
| 144 | |
| 145 | #endif |
| 146 |