| 1 | |
| 2 | /** |
| 3 | * |
| 4 | * @file jj1level.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 | * - 4th February 2009: Created events.h from parts of level.h |
| 12 | * - 19th March 2009: Created sprite.h from parts of level.h |
| 13 | * - 30th March 2010: Created baselevel.h from parts of level.h |
| 14 | * - 29th June 2010: Created jj2level.h from parts of level.h |
| 15 | * - 1st August 2012: Renamed level.h to jj1level.h |
| 16 | * |
| 17 | * @par Licence: |
| 18 | * Copyright (c) 2005-2017 AJ Thomson |
| 19 | * |
| 20 | * OpenJazz is distributed under the terms of |
| 21 | * the GNU General Public License, version 2.0 |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | /* "Tile" is a flexible term. Here it is used to refer specifically to the |
| 27 | individual elements of the tile set. |
| 28 | "Tiles" in the context of level units are referred to as grid elements. */ |
| 29 | |
| 30 | |
| 31 | #ifndef _LEVEL_H |
| 32 | #define _LEVEL_H |
| 33 | |
| 34 | |
| 35 | #include "level/level.h" |
| 36 | #include "io/gfx/anim.h" |
| 37 | #include "OpenJazz.h" |
| 38 | |
| 39 | |
| 40 | // Constants |
| 41 | |
| 42 | // General |
| 43 | #define LW 256 /* Level width */ |
| 44 | #define LH 64 /* Level height */ |
| 45 | #define EVENTS 127 |
| 46 | #define ELENGTH 32 /* Length of events, in bytes */ |
| 47 | #define BULLETS 32 |
| 48 | #define BLENGTH 20 /* Length of bullets, in bytes */ |
| 49 | #define ANIMS 128 |
| 50 | #define SOUNDS 32 |
| 51 | #define SHORTNAME 8 |
| 52 | #define LONGNAME 16 |
| 53 | #define PATHS 16 |
| 54 | #define TNUM 60 /* Number of tiles in tileset */ |
| 55 | #define TSETS 4 /* Maximum number of tilesets (each 60 entries) */ |
| 56 | #define TKEY 127 /* Tileset colour key */ |
| 57 | #define MASKS (TNUM * TSETS + 16) << 3 |
| 58 | |
| 59 | // Player animations |
| 60 | #define PA_LWALK 0 |
| 61 | #define PA_RWALK 1 |
| 62 | #define PA_LJUMP 2 |
| 63 | #define PA_RJUMP 3 |
| 64 | #define PA_LSPIN 4 |
| 65 | #define PA_RSPIN 5 |
| 66 | #define PA_LSHOOT 6 |
| 67 | #define PA_RSHOOT 7 |
| 68 | #define PA_LCROUCH 8 |
| 69 | #define PA_RCROUCH 9 |
| 70 | #define PA_LFALL 10 |
| 71 | #define PA_RFALL 11 |
| 72 | #define PA_LHURT 12 |
| 73 | #define PA_RHURT 13 |
| 74 | #define PA_LLEAN 14 |
| 75 | #define PA_RLEAN 15 |
| 76 | #define PA_LBOARD 16 |
| 77 | #define PA_RBOARD 17 |
| 78 | #define PA_LSTAND 18 |
| 79 | #define PA_RSTAND 19 |
| 80 | #define PA_LBORED 20 |
| 81 | #define PA_RBORED 21 |
| 82 | #define PA_LEDGE 22 |
| 83 | #define PA_REDGE 23 |
| 84 | #define PA_LOOKUP 24 |
| 85 | #define PA_LOOKDOWN 25 |
| 86 | #define PA_LSWIM 26 |
| 87 | #define PA_RSWIM 27 |
| 88 | #define PA_LRUN 28 |
| 89 | #define PA_RRUN 29 |
| 90 | #define PA_LDIE 30 |
| 91 | #define PA_RDIE 31 |
| 92 | #define PA_LSUCK 32 |
| 93 | #define PA_RSUCK 33 |
| 94 | #define PA_LSTOP 34 /* SUCK and STOP refer almost always to the same animation */ |
| 95 | #define PA_RSTOP 35 |
| 96 | #define PA_RSPRING 36 |
| 97 | #define PA_LSPRING 37 /* Surely these are the wrong way round? */ |
| 98 | |
| 99 | #define JJ1PANIMS 38 /* Number of player animations. May be higher. */ |
| 100 | |
| 101 | // Miscellaneous animations |
| 102 | #define MA_SPARKLE 0 |
| 103 | #define MA_DEVHEAD 1 |
| 104 | #define MA_EXPLOSION1 2 |
| 105 | #define MA_EXPLOSION2 3 |
| 106 | #define JJ1MANIMS 4 |
| 107 | |
| 108 | // Level Sounds |
| 109 | #define LSND_NOTHING1 0 // usually empty |
| 110 | #define LSND_JUMP 1 |
| 111 | #define LSND_HURT 2 |
| 112 | #define LSND_BORED1 3 |
| 113 | #define LSND_BORED2 4 |
| 114 | #define LSND_UNKNOWN6 5 |
| 115 | #define LSND_ENDCOUNT 6 |
| 116 | #define LSND_DONE 7 |
| 117 | #define LSND_UNKNOWN9 8 |
| 118 | #define LSND_LOOSEBIRD 9 |
| 119 | #define LSND_UPLOOP 10 |
| 120 | #define JJ1LSOUNDS 11 |
| 121 | |
| 122 | // Level animations |
| 123 | #define LA_NOTHING1 0 // usually empty |
| 124 | #define LA_NOTHING2 1 // usually empty |
| 125 | #define LA_NOTHING3 2 // usually empty |
| 126 | #define LA_4SHIELD 3 |
| 127 | #define LA_LBOARD 4 |
| 128 | #define LA_RBOARD 5 |
| 129 | #define LA_LBIRD 6 |
| 130 | #define LA_RBIRD 7 |
| 131 | #define LA_UNKNOWN9 8 // usually empty animation 31 |
| 132 | #define LA_ICY 9 // 0 = normal, 1 = shiver and slide, >1 only shiver |
| 133 | #define LA_1SHIELD 10 |
| 134 | #define JJ1LANIMS 11 |
| 135 | |
| 136 | // Black palette index |
| 137 | #define LEVEL_BLACK 31 |
| 138 | |
| 139 | // Fade delays |
| 140 | #define T_START 500 |
| 141 | #define T_END 1000 |
| 142 | |
| 143 | |
| 144 | // Datatypes |
| 145 | |
| 146 | /// JJ1 level grid element |
| 147 | typedef struct { |
| 148 | |
| 149 | unsigned char tile; ///< Indexes the tile set |
| 150 | unsigned char bg; ///< 0 = Effect background, 1 = Black background |
| 151 | unsigned char event; ///< Indexes the event set |
| 152 | unsigned char hits; ///< Number of times the event has been shot |
| 153 | int time; ///< Point at which the event will do something, e.g. terminate |
| 154 | |
| 155 | } GridElement; |
| 156 | |
| 157 | /// JJ1 level event type |
| 158 | typedef struct { |
| 159 | |
| 160 | unsigned char anims[6]; ///< Indices of animations |
| 161 | difficultyType difficulty; ///< The minimum difficulty level at which the event is used |
| 162 | signed char reflection; ///< Whether or not to show a reflection |
| 163 | signed char movement; ///< Movement type |
| 164 | signed char magnitude; ///< Usage depends on event type |
| 165 | signed char strength; ///< Number of hits required to destroy the event |
| 166 | signed char modifier; ///< Modifier |
| 167 | unsigned char points; ///< Points obtained by getting/destroying the event |
| 168 | unsigned char bullet; ///< Type of bullet the event fires |
| 169 | unsigned char bulletPeriod; ///< The time between successive bullet shots |
| 170 | unsigned char speed; ///< The speed at which the event moves |
| 171 | unsigned char animSpeed; ///< The speed of the event's animation |
| 172 | SE::Type sound; ///< The sound played on the appropriate trigger |
| 173 | signed char multiA; ///< Usage depends on event type |
| 174 | signed char multiB; ///< Usage depends on event type |
| 175 | signed char pieceSize; ///< Size of pieces in bridges, swinging balls chains, etc. |
| 176 | signed char pieces; ///< Number of pieces in bridges, swinging ball chains, etc. |
| 177 | signed char angle; ///< Initial angle of swinging balls, etc. |
| 178 | |
| 179 | } JJ1EventType; |
| 180 | |
| 181 | /// Pre-defined JJ1 event movement path |
| 182 | typedef struct { |
| 183 | |
| 184 | short int* x; ///< X-coordinates for each node |
| 185 | short int* y; ///< Y-coordinates for each node |
| 186 | unsigned char length; ///< Number of nodes |
| 187 | |
| 188 | } JJ1EventPath; |
| 189 | |
| 190 | |
| 191 | // Classes |
| 192 | |
| 193 | class Font; |
| 194 | class JJ1Bullet; |
| 195 | class JJ1Event; |
| 196 | class JJ1LevelPlayer; |
| 197 | |
| 198 | /// JJ1 level |
| 199 | class JJ1Level : public Level { |
| 200 | |
| 201 | private: |
| 202 | SDL_Surface* tileSet; ///< Tile images |
| 203 | SDL_Surface* panel; ///< HUD background image |
| 204 | SDL_Surface* panelBG[2]; ///< HUD background image borders |
| 205 | SDL_Surface* panelAmmo[6]; ///< HUD ammo type images |
| 206 | JJ1Event* events; ///< Active events |
| 207 | JJ1Bullet* bullets; ///< Active bullets |
| 208 | char* sceneFile; ///< File name of cutscene to play when level has been completed |
| 209 | Sprite* spriteSet; ///< Sprites |
| 210 | Anim animSet[ANIMS]; ///< Animations |
| 211 | char miscAnims[JJ1MANIMS]; ///< Further animations |
| 212 | char levelAnims[JJ1LANIMS]; ///< Level animations |
| 213 | char playerAnims[JJ1PANIMS]; ///< Default player animations |
| 214 | signed char bulletSet[BULLETS][BLENGTH]; ///< Bullet types |
| 215 | char levelSounds[JJ1LSOUNDS]; ///< Level sounds |
| 216 | JJ1EventType eventSet[EVENTS]; ///< Event types |
| 217 | char mask[240][64]; ///< Tile masks. At most 240 tiles, all with 8 * 8 masks |
| 218 | GridElement grid[LH][LW]; ///< Level grid. All levels are the same size |
| 219 | SDL_Color skyPalette[MAX_PALETTE_COLORS]; ///< Full palette for sky background |
| 220 | bool sky; ///< Whether or not to use sky background |
| 221 | unsigned char skyOrb; ///< The tile to use as the background sun/moon/etc. |
| 222 | int levelNum; ///< Number of current level |
| 223 | int worldNum; ///< Number of current world |
| 224 | int nextLevelNum; ///< Number of next level |
| 225 | int nextWorldNum; ///< Number of next world |
| 226 | int enemies; ///< Number of enemies to kill |
| 227 | fixed waterLevel; ///< Height of water |
| 228 | fixed waterLevelTarget; ///< Future height of water |
| 229 | fixed waterLevelSpeed; ///< Rate of water level change |
| 230 | fixed energyBar; ///< HUD energy bar fullness |
| 231 | int ammoType; ///< HUD ammo type |
| 232 | fixed ammoOffset; ///< HUD ammo offset |
| 233 | int nEnemies[4]; // Easy, Medium, Hard, Turbo |
| 234 | int nItems; |
| 235 | // FIXME: actually use these |
| 236 | int animSpeed, jumpHeight; |
| 237 | |
| 238 | void deletePanel (); |
| 239 | int loadPanel (); |
| 240 | void loadSprite (File* file, Sprite* sprite); |
| 241 | int loadSprites (char* fileName); |
| 242 | int loadTiles (char* fileName); |
| 243 | int playBonus (); |
| 244 | |
| 245 | protected: |
| 246 | Font* font; ///< On-screen message font |
| 247 | char* musicFile; ///< Music file name |
| 248 | |
| 249 | explicit JJ1Level(Game* owner); |
| 250 | |
| 251 | int load (char* fileName, bool checkpoint); |
| 252 | int step (); |
| 253 | void draw (); |
| 254 | |
| 255 | public: |
| 256 | JJ1EventPath path[PATHS]; ///< Pre-defined event movement paths |
| 257 | |
| 258 | JJ1Level (Game* owner, char* fileName, bool checkpoint, bool multi); |
| 259 | ~JJ1Level () override; |
| 260 | |
| 261 | bool checkMaskUp (fixed x, fixed y); |
| 262 | bool checkMaskDown (fixed x, fixed y); |
| 263 | bool checkSpikes (fixed x, fixed y); |
| 264 | int getWorld (); |
| 265 | void setNext (int nextLevel, int nextWorld); |
| 266 | void setTile (unsigned char gridX, unsigned char gridY, unsigned char tile); |
| 267 | difficultyType getDifficulty (); |
| 268 | JJ1Event* getEvents (); |
| 269 | JJ1EventType* getEvent (unsigned char gridX, unsigned char gridY); |
| 270 | unsigned char getEventHits (unsigned char gridX, unsigned char gridY); |
| 271 | unsigned int getEventTime (unsigned char gridX, unsigned char gridY); |
| 272 | void clearEvent (unsigned char gridX, unsigned char gridY); |
| 273 | int hitEvent (unsigned char gridX, unsigned char gridY, int hits, JJ1LevelPlayer* source, unsigned int time); |
| 274 | void setEventTime (unsigned char gridX, unsigned char gridY, unsigned int time); |
| 275 | Sprite* getSprite (unsigned char sprite); |
| 276 | Anim* getAnim (unsigned char anim); |
| 277 | Anim* getMiscAnim (unsigned char anim); |
| 278 | Anim* getPlayerAnim (unsigned char anim); |
| 279 | Anim* getLevelAnim (unsigned char anim); |
| 280 | SE::Type getLevelSound (unsigned char sound); |
| 281 | void createBullet (JJ1LevelPlayer* sourcePlayer, unsigned char gridX, unsigned char gridY, fixed startX, fixed startY, unsigned char bullet, bool facing, unsigned int time); |
| 282 | void setWaterLevel (unsigned char gridY); |
| 283 | fixed getWaterLevel (); |
| 284 | void flash (unsigned char red, unsigned char green, unsigned char blue, int duration); |
| 285 | void receive (unsigned char* buffer) override; |
| 286 | virtual int play (); |
| 287 | |
| 288 | }; |
| 289 | |
| 290 | /// JJ1 level played as a demo |
| 291 | class JJ1DemoLevel : public JJ1Level { |
| 292 | |
| 293 | private: |
| 294 | unsigned char* macro; ///< Sequence of player control codes |
| 295 | |
| 296 | public: |
| 297 | JJ1DemoLevel (Game* owner, const char* fileName); |
| 298 | ~JJ1DemoLevel () override; |
| 299 | |
| 300 | int play () override; |
| 301 | |
| 302 | }; |
| 303 | |
| 304 | |
| 305 | // Variables |
| 306 | |
| 307 | EXTERN JJ1Level* level; ///< JJ1 level |
| 308 | |
| 309 | #endif |
| 310 |