1 /* 2 * Holotz's Castle 3 * Copyright (C) 2004 Juan Carlos Seijo Pérez 4 * 5 * This program is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License as published by the Free 7 * Software Foundation; either version 2 of the License, or (at your option) 8 * any later version. 9 * 10 * This program is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 * more details. 14 * 15 * You should have received a copy of the GNU General Public License along 16 * with this program; if not, write to the Free Software Foundation, Inc., 59 17 * Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * 19 * Juan Carlos Seijo Pérez 20 * jacob@mainreactor.net 21 */ 22 23 /** The game of Holotz's Castle. 24 * @file HolotzCastle.h 25 * @author Juan Carlos Seijo Pérez 26 * @date 27/04/2004 27 * @version 0.0.1 - 27/04/2004 - First version. 28 */ 29 30 #ifndef _HOLOTZ_INCLUDED 31 #define _HOLOTZ_INCLUDED 32 33 #include <JLib/Util/JApp.h> 34 #include <JLib/Util/JTypes.h> 35 #include <JLib/Graphics/JTextMenu.h> 36 #include <HCLevel.h> 37 #include <HCScript.h> 38 #include <HCEnemyChaser.h> 39 #include <HCPreferences.h> 40 #include <HCPlaylist.h> 41 #include <HCLoadSaveSlot.h> 42 #include <HCUtil.h> 43 44 class HCScript; 45 class HCScriptAction; 46 class HCEnemy; 47 class HCEnemyChaser; 48 49 #define ACKNOWLEDGEMENTS \ 50 "Special thanks go to:\n"\ 51 " \n"\ 52 "Martinica (the best beta-tester mother),\n"\ 53 "Bebo, Ampis & Roberto & Oscar, Padre, Cris &\n"\ 54 "Rafa & Lucía & Paula & Rafael\n"\ 55 "Quique & Marga & Jorge & Javier,\n"\ 56 "Carlos & Julia & Jorge & Jose\n"\ 57 "Ana & Nathan & María & Marco,\n"\ 58 "Jorge & Amelia & Alejandro,\n"\ 59 "Carlos & Vero & Álvaro & Irene, Edu & Vero,\n"\ 60 "Alex, Chily, Santos & Rocío & África, Félix &\n"\ 61 "Carmen, Ossuna's, Jose & Gloria, Ori &\n"\ 62 "Loli, Diana & David, Luis,\n"\ 63 "Ángel, Celia, Íñigo,\n"\ 64 "Markus Rath/Ronny Standtke (German translation),\n"\ 65 "Milan Babuškov (Add-on levels),\n"\ 66 "Miriam Ruiz (Debian package),\n"\ 67 "Nicolas Elie (French translation),\n"\ 68 "Вячеслав Диконов \n(Vyacheslav Dikonov - Russian translation),\n"\ 69 "3ARRANO Euskalgintza (Euskara translation),\n"\ 70 "Andreas Jochens (AMD64 Patches),\n"\ 71 "Maksim Mokriyev (Ukranian translation)\n"\ 72 "Filip (Triple T) Bártek (Czech translation)\n"\ 73 "Pierre-Paul Lavoie (FreeBSD porting)\n"\ 74 "Filipe Silva (Portuguese translation)\n"\ 75 "Ben Wong (English translation, patches)\n"\ 76 "Federico 'hs1' Tolomei (Italian translation)\n"\ 77 "Jarno van der Kolk (Dutch translation/Joystick)\n"\ 78 "Jason Woofenden (PPC Patches)\n"\ 79 "Syltbullen (Swedish translation)\n"\ 80 "Nikola Smolenski (Serbian translation)\n"\ 81 "...and you for playing!" 82 83 /** Possible states of the game. 84 */ 85 typedef enum 86 { 87 HCS_MENU = 1, /**< Showing main menu. */ 88 HCS_PLAYING, /**< Playing. */ 89 HCS_PAUSED, /**< Paused. */ 90 HCS_INTRO, /**< Intro. */ 91 HCS_CREDITS, /**< Game Credits. */ 92 HCS_SCRIPT, /**< Scripted level. */ 93 HCS_ENDLEVEL, /**< Level ends. */ 94 HCS_GAMEOVER, /**< Game over. */ 95 HCS_HELP, /**< Help. */ 96 } HCState; 97 98 typedef enum 99 { 100 HCCREDITS_PROGRAMMING = 0, /**< Programming image. */ 101 HCCREDITS_STORY, /**< Story image. */ 102 HCCREDITS_DRAWING0, /**< Drawing 1st image. */ 103 HCCREDITS_DRAWING1, /**< Drawing 2nd image. */ 104 HCCREDITS_DRAWING2, /**< Drawing 3rd image. */ 105 HCCREDITS_ANIMATION0, /**< Animation 1st image. */ 106 HCCREDITS_ANIMATION1, /**< Animation 2nd image. */ 107 HCCREDITS_ANIMATION2, /**< Animation 3rd image. */ 108 HCCREDITS_ANIMATION3, /**< Animation 4th image. */ 109 HCCREDITS_MUSIC, /**< Music image. */ 110 HCCREDITS_HOLOTZCASTLE, /**< Holotz's castle image. */ 111 HCCREDITS_LOGO, /**< Mainrector image. */ 112 HCCREDITS_IMAGE_COUNT /**< Number of images. */ 113 } HCCreditsImageType; 114 115 typedef enum 116 { 117 HCCREDITS_PROGRAMMING_TEXT = 0, /**< Programming text. */ 118 HCCREDITS_STORY_TEXT, /**< Story text. */ 119 HCCREDITS_DRAWING_TEXT, /**< Drawing 1st text. */ 120 HCCREDITS_ANIMATION_TEXT, /**< Animation 1st text. */ 121 HCCREDITS_MUSIC_TEXT, /**< Music text. */ 122 HCCREDITS_HOLOTZCASTLE_TEXT, /**< Holotz's castle text. */ 123 HCCREDITS_LOGO_TEXT, /**< Holotz's castle text. */ 124 HCCREDITS_ACK_TEXT, /**< Acknowledgements text. */ 125 HCCREDITS_TEXT_COUNT /**< Number of texts. */ 126 } HCCreditsTextType; 127 128 #define HC_NUM_SLOTS 5 /**< Number of slots to save and load. */ 129 130 /** Application class. 131 */ 132 class HCApp : public JApp 133 { 134 protected: 135 HCState lastState; /**< Last state of the game. */ 136 HCState state; /**< Current state of the game. */ 137 138 JImage *imgMenu; /**< Main title background. */ 139 JTextMenu *menu; /**< Application menu. */ 140 141 JImage *imgCredits[HCCREDITS_IMAGE_COUNT]; /**< Credits images. */ 142 JImage *textCredits[HCCREDITS_TEXT_COUNT]; /**< Credits texts. */ 143 s32 inDrawing; /**< Current drawing fading in. */ 144 s32 outDrawing; /**< Current drawing fading out. */ 145 s32 inAnimation; /**< Current animation fading in. */ 146 s32 outAnimation; /**< Current animation fading out. */ 147 148 HCPreferences preferences; /**< Preferences for the game. */ 149 HCPlaylist playlist; /**< Playlist with the story order. */ 150 char *playlistName; /**< Name of the playlist. */ 151 152 JTimer timerGeneral; /**< Timer for general use. */ 153 JImage *imgIntro; /**< Intro image (MainReactor). */ 154 JImage *imgFatalFun; /**< Intro image (Fatalfun). */ 155 JImage *textIntro; /**< Intro text (Presents...). */ 156 157 HCLevel level; /**< Game level. */ 158 HCScript script; /**< Level script. */ 159 s32 levelNumber; /**< Current level within the current world. */ 160 161 JChunk musicMainTitle; /**< Main title screen music. */ 162 JChunk musicCredits; /**< Credits screen music. */ 163 JChunk musicGameOver; /**< Game over screen music. */ 164 JChunk musicBeginLevel; /**< Start-of-level music. */ 165 166 JFont fontSmall; /**< Small font. */ 167 JFont fontMedium; /**< Medium font. */ 168 JFont fontLarge; /**< Large font. */ 169 170 JImage *imgBack; /**< Image for background storing. */ 171 HCText *textBack; /**< General purpouse text message. */ 172 JImage *imgHelp; /**< Help text message. */ 173 174 HCLoadSaveSlot saveData[HC_NUM_SLOTS];/**< Slots for loading and saving. */ 175 176 bool stateChanged; /**< App state change flag */ 177 178 /** Initializes the menu state. 179 * @return <b>true</b> if initialization succeeded, <b>false</b> if not. 180 */ 181 bool InitMenu(); 182 183 /** Initializes the intro state. 184 * @return <b>true</b> if initialization succeeded, <b>false</b> if not. 185 */ 186 bool InitIntro(); 187 188 /** Initializes the paused state. 189 * @return <b>true</b> if initialization succeeded, <b>false</b> if not. 190 */ 191 bool InitPaused(); 192 193 /** Initializes the playing state. 194 * @return <b>true</b> if initialization succeeded, <b>false</b> if not. 195 */ 196 bool InitPlaying(); 197 198 /** Initializes the game over state. 199 * @return <b>true</b> if initialization succeeded, <b>false</b> if not. 200 */ 201 bool InitGameOver(); 202 203 /** Initializes the end level state. 204 * @return <b>true</b> if initialization succeeded, <b>false</b> if not. 205 */ 206 bool InitEndLevel(); 207 208 /** Initializes the credits state. 209 * @return <b>true</b> if initialization succeeded, <b>false</b> if not. 210 */ 211 bool InitCredits(); 212 213 /** Initializes the help text. 214 * @return <b>true</b> if initialization succeeded, <b>false</b> if not. 215 */ 216 bool InitHelp(); 217 218 /** Destroys the help text. 219 */ 220 void DestroyHelp(); 221 222 /** Initializes the data slot for loading and saving. 223 * @return <b>true</b> if initialization succeeded, <b>false</b> if not. 224 */ 225 bool InitSlots(); 226 227 /** Initializes the sound. 228 * @return <b>true</b> if initialization succeeded, <b>false</b> if not. 229 */ 230 bool InitSound(); 231 232 /** (Re)initializes the fonts. 233 * @return <b>true</b> if initialization succeeded, <b>false</b> if not. 234 */ 235 bool InitFonts(); 236 237 /** Callback: App exit. 238 * @param data App. 239 */ 240 static void OnExit(void *data); 241 242 /** Callback: Credits. 243 * @param data App. 244 */ 245 static void OnCredits(void *data); 246 247 /** Callback: Difficulty level select. 248 * @param data Value casted to s32, HCPREFERENCES_EASY or HCPREFERENCES_NORMAL or HCPREFERENCES_HARD. 249 */ 250 static void OnDifficulty(void *data); 251 252 /** Callback: Sound select. 253 * @param data Value casted to s32, 0 to turn off and 1 to turn on. 254 */ 255 static void OnSound(void *data); 256 257 /** Callback: New game. 258 */ 259 static void OnNew(void *data); 260 261 /** Callback: Continue game. 262 */ 263 static void OnContinue(void *data); 264 265 /** Callback: Help. 266 */ 267 static void OnHelp(void *data); 268 269 /** Callback: video mode select. 270 * @param data Mode number according to preferences casted to a s32. 271 */ 272 static void OnVideoMode(void *data); 273 274 /** Callback: Color depth select. 275 * @param data BPP casted to a s32. 276 */ 277 static void OnBPP(void *data); 278 279 /** Callback: Window mode select. 280 * @param data Window mode casted to s32. 281 */ 282 static void OnWindowMode(void *data); 283 284 /** Callback: Language select. 285 * @param data Language index according to preferences casted to a s32. 286 */ 287 static void OnLanguage(void *data); 288 289 /** Callback: Restore defaults. 290 * @param data Null. 291 */ 292 static void OnDefaults(void *data); 293 294 /** Callback: Load game. 295 * @param data Slot number to load from. 296 */ 297 static void OnLoad(void *data); 298 299 /** Callback: Save game. 300 * @param data Slot number to save to. 301 */ 302 static void OnSave(void *data); 303 304 /** Draws the menu. 305 * @return <b>true</b> if drawing succeeded, <b>false</b> if not. 306 */ 307 bool DrawMenu(); 308 309 /** Draws the game. 310 * @return <b>true</b> if drawing succeeded, <b>false</b> if not. 311 */ 312 bool DrawPlaying(); 313 314 /** Draws the game paused. 315 * @return <b>true</b> if drawing succeeded, <b>false</b> if not. 316 */ 317 bool DrawPaused(); 318 319 /** Draws the game in the ending level state. 320 * @return <b>true</b> if drawing succeeded, <b>false</b> if not. 321 */ 322 bool DrawEndLevel(); 323 324 /** Draws the game in the game over state. 325 * @return <b>true</b> if drawing succeeded, <b>false</b> if not. 326 */ 327 bool DrawGameOver(); 328 329 /** Draws the hall of fame. 330 * @return <b>true</b> if drawing succeeded, <b>false</b> if not. 331 */ 332 bool DrawIntro(); 333 334 /** Draws the credits. 335 * @return <b>true</b> if drawing succeeded, <b>false</b> if not. 336 */ 337 bool DrawCredits(); 338 339 /** Draws the load state. 340 * @return <b>true</b> if drawing succeeded, <b>false</b> if not. 341 */ 342 bool DrawLoad(); 343 344 /** Draws the save state. 345 * @return <b>true</b> if drawing succeeded, <b>false</b> if not. 346 */ 347 bool DrawSave(); 348 349 /** Draws the scripted level. 350 * @return <b>true</b> if drawing succeeded, <b>false</b> if not. 351 */ 352 bool DrawScript(); 353 354 /** Updates the menu. 355 * @return <b>true</b> if updating succeeded, <b>false</b> if not. 356 */ 357 bool UpdateMenu(); 358 359 /** Updates the game. 360 * @return <b>true</b> if updating succeeded, <b>false</b> if not. 361 */ 362 bool UpdatePlaying(); 363 364 /** Updates the game paused. 365 * @return <b>true</b> if updating succeeded, <b>false</b> if not. 366 */ 367 bool UpdatePaused(); 368 369 /** Updates the game in the ending level state. 370 * @return <b>true</b> if updateing succeeded, <b>false</b> if not. 371 */ 372 bool UpdateEndLevel(); 373 374 /** Updates the game in the game over state. 375 * @return <b>true</b> if updateing succeeded, <b>false</b> if not. 376 */ 377 bool UpdateGameOver(); 378 379 /** Updates the hall of fame. 380 * @return <b>true</b> if updating succeeded, <b>false</b> if not. 381 */ 382 bool UpdateIntro(); 383 384 /** Updates the credits. 385 * @return <b>true</b> if updating succeeded, <b>false</b> if not. 386 */ 387 bool UpdateCredits(); 388 389 /** Updates the load state. 390 * @return <b>true</b> if updating succeeded, <b>false</b> if not. 391 */ 392 bool UpdateLoad(); 393 394 /** Updates the save state. 395 * @return <b>true</b> if updating succeeded, <b>false</b> if not. 396 */ 397 bool UpdateSave(); 398 399 /** Updates the script. 400 * @return <b>true</b> if updating succeeded, <b>false</b> if not. 401 */ 402 bool UpdateScript(); 403 404 /** Loads the current world/level. 405 * @return 1 if loading succeeded, 0 if not, -1 if game ended. 406 */ 407 s32 LoadWorld(); 408 409 /** Process key up events. 410 */ 411 static void OnKeyUp(SDL_keysym key); 412 413 /** Process key down events. 414 */ 415 static void OnKeyDown(SDL_keysym key); 416 417 /** Process the state change of the app. 418 */ 419 void ProcessStateChange(); 420 421 public: 422 /** Creates the application object. 423 */ 424 HCApp(); 425 426 /** Initializes the application. 427 * @param argc Argument count from the command line, as in main(). 428 * @param argv Argument list from the command line, as in main(). 429 * @return <b>true</b> if initialization is ok, <b>false</b> if not. 430 */ 431 bool Init(s32 argc = 0, char **argv = 0); 432 433 /** Draws the application. 434 * @return <b>true</b> if drawing succeeded, <b>false</b> if not. 435 */ 436 bool Draw(); 437 438 /** Updates the application. 439 * @return <b>true</b> if update succeeded, <b>false</b> if not. 440 */ 441 bool Update(); 442 443 /** Returns the state of the app. 444 * @return State of the app. 445 */ 446 inline HCState State(); 447 448 /** Changes the state of the app. 449 * @param newState New state of the app. 450 */ 451 void State(HCState newState); 452 453 /** Process user input. 454 */ 455 void ProcessInput(); 456 457 /** Returns the current level. 458 * @return Current level. 459 */ Level()460 HCLevel *Level() {return &level;} 461 462 /** Returns the small font. 463 * @return Small font. 464 */ FontSmall()465 JFont *FontSmall() {return &fontSmall;} 466 467 /** Returns the medium font. 468 * @return Medium font. 469 */ FontMedium()470 JFont *FontMedium() {return &fontMedium;} 471 472 /** Returns the large font. 473 * @return Large font. 474 */ FontLarge()475 JFont *FontLarge() {return &fontLarge;} 476 477 /** Parses argument. 478 * @param args Command line arguments. 479 * @param argc Arguments left. 480 * @return Number of parameters used. 481 */ 482 virtual int ParseArg(char *args[], int argc); 483 484 /** Shows the usage string. 485 */ 486 virtual void PrintUsage(char *program); 487 488 /** Frees the allocated resources. 489 */ 490 void Destroy(); 491 492 /** Destroys the application object. 493 */ ~HCApp()494 virtual ~HCApp() {Destroy();} 495 496 friend void OnKeyUp(SDL_keysym key); 497 }; 498 499 #endif // _HOLOTZ_INCLUDED 500