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