| 1 | |
| 2 | /** |
| 3 | * |
| 4 | * @file jj1demolevel.cpp |
| 5 | * |
| 6 | * Part of the OpenJazz project |
| 7 | * |
| 8 | * @par History: |
| 9 | * - 23rd August 2005: Created level.c |
| 10 | * - 22nd July 2008: Created levelload.c from parts of level.c |
| 11 | * - 3rd February 2009: Renamed level.c to level.cpp and levelload.c to |
| 12 | * levelload.cpp |
| 13 | * - 18th July 2009: Created demolevel.cpp from parts of level.cpp and |
| 14 | * levelload.cpp |
| 15 | * - 1st August 2012: Renamed demolevel.cpp to jj1demolevel.cpp |
| 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 | * @par Description: |
| 24 | * Deals with the loading and playing of demo levels. |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | |
| 29 | #include "jj1level.h"cxx . . $ `<file>/src/jj1/level/jj1level.h`/ |
| 30 | #include "jj1levelplayer.h"cxx . . $ `<file>/src/jj1/level/jj1levelplayer.h`/ |
| 31 | |
| 32 | #include "game/game.h"cxx . . $ `<file>/src/game/game.h`/ |
| 33 | #include "game/gamemode.h"cxx . . $ `<file>/src/game/gamemode.h`/ |
| 34 | #include "io/controls.h"cxx . . $ `<file>/src/io/controls.h`/ |
| 35 | #include "io/file.h"cxx . . $ `<file>/src/io/file.h`/ |
| 36 | #include "io/gfx/font.h"cxx . . $ `<file>/src/io/gfx/font.h`/ |
| 37 | #include "io/gfx/video.h"cxx . . $ `<file>/src/io/gfx/video.h`/ |
| 38 | #include "io/sound.h"cxx . . $ `<file>/src/io/sound.h`/ |
| 39 | #include "loop.h"cxx . . $ `<file>/src/loop.h`/ |
| 40 | #include "util.h"cxx . . $ `<file>/src/util.h`/ |
| 41 | |
| 42 | |
| 43 | /** |
| 44 | * Create a JJ1 demo level. |
| 45 | * |
| 46 | * @param owner The current game |
| 47 | * @param fileName Name of the file containing the macro data. |
| 48 | */ |
| 49 | JJ1DemoLevelcxx . . $ JJ1DemoLevel#::JJ1DemoLevelcxx . . $ JJ1DemoLevel#JJ1DemoLevel(87f53f450eae2511). (Gamecxx . . $ Game#* owner, const char* fileName) : JJ1Levelcxx . . $ JJ1Level#(owner) { |
| 50 | |
| 51 | Filecxx . . $ File#* file; |
| 52 | char* levelFile; |
| 53 | int lNum, wNum, ret; |
| 54 | |
| 55 | multiplayercxx . . $ Level#multiplayer. = false; |
| 56 | |
| 57 | try { |
| 58 | |
| 59 | file = new Filecxx . . $ File#File(e99a0a23efd851c6).(fileName, PATH_TYPE_GAMEcxx . . $ PATH_TYPE_GAME.); |
| 60 | |
| 61 | } catch (int e) { |
| 62 | |
| 63 | throw; |
| 64 | |
| 65 | } |
| 66 | |
| 67 | // Check this is a normal level |
| 68 | if (file->loadShortcxx . . $ File#loadShort(32a7769d58713265).() == 0) { |
| 69 | |
| 70 | delete file; |
| 71 | throw E_DEMOTYPEcxx . . $ `src/OpenJazz.h:59:9`!; |
| 72 | |
| 73 | } |
| 74 | |
| 75 | // Level file to load |
| 76 | lNum = file->loadShortcxx . . $ File#loadShort(a18c05e4017afb3d).(9); |
| 77 | wNum = file->loadShortcxx . . $ File#loadShort(a18c05e4017afb3d).(999); |
| 78 | levelFile = createFileNamecxx . . $ createFileName(dc9afb5388f048cb).("LEVEL", lNum, wNum); |
| 79 | |
| 80 | // Difficulty |
| 81 | file->loadShortcxx . . $ File#loadShort(32a7769d58713265).(); |
| 82 | |
| 83 | macrocxx . . $ JJ1DemoLevel#macro. = file->loadBlockcxx . . $ File#loadBlock(f18dc31a6ecbac56).(1024); |
| 84 | |
| 85 | delete file; |
| 86 | |
| 87 | // Load level data |
| 88 | |
| 89 | ret = loadcxx . . $ JJ1Level#load(ef975b611725403e).(levelFile, false); |
| 90 | |
| 91 | delete[] levelFile; |
| 92 | |
| 93 | if (ret < 0) throw ret; |
| 94 | |
| 95 | } |
| 96 | |
| 97 | |
| 98 | /** |
| 99 | * Delete the JJ1 demo level. |
| 100 | */ |
| 101 | JJ1DemoLevelcxx . . $ JJ1DemoLevel#::~cxx . . $ JJ1DemoLevel#`~JJ1DemoLevel`(49f6e7a06ebc5aa8).JJ1DemoLevelcxx . . $ JJ1DemoLevel# () { |
| 102 | |
| 103 | delete[] macrocxx . . $ JJ1DemoLevel#macro.; |
| 104 | |
| 105 | } |
| 106 | |
| 107 | |
| 108 | /** |
| 109 | * Play the demo. |
| 110 | * |
| 111 | * @return Error code |
| 112 | */ |
| 113 | int JJ1DemoLevelcxx . . $ JJ1DemoLevel#::playcxx . . $ JJ1DemoLevel#play(b126dc7c1de90089). () { |
| 114 | |
| 115 | tickOffsetcxx . . $ Level#tickOffset. = globalTickscxx . . $ globalTicks.; |
| 116 | tickscxx . . $ Level#ticks. = 17; |
| 117 | stepscxx . . $ Level#steps. = 0; |
| 118 | |
| 119 | videocxx . . $ video..setPalettecxx . . $ Video#setPalette(d5421d17e1a4b2b2).(palettecxx . . $ Level#palette.); |
| 120 | |
| 121 | playMusiccxx . . $ playMusic(90ef5b561fbcb8de).(musicFilecxx . . $ JJ1Level#musicFile.); |
| 122 | |
| 123 | while (true) { |
| 124 | |
| 125 | // Do general processing |
| 126 | if (::loopcxx . . $ loop(fd873fd06cfe1135).(NORMAL_LOOPcxx . . $ NORMAL_LOOP., paletteEffectscxx . . $ Level#paletteEffects.) == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) return E_QUITcxx . . $ `src/OpenJazz.h:67:9`!; |
| 127 | |
| 128 | if (controlscxx . . $ controls..releasecxx . . $ Controls#release(83c267b20bac841a).(C_ESCAPEcxx . . $ `src/io/controls.h:39:9`!) || controlscxx . . $ controls..releasecxx . . $ Controls#release(83c267b20bac841a).(C_ENTERcxx . . $ `src/io/controls.h:38:9`!)) return E_NONEcxx . . $ `src/OpenJazz.h:69:9`!; |
| 129 | |
| 130 | if (controlscxx . . $ controls..releasecxx . . $ Controls#release(83c267b20bac841a).(C_STATScxx . . $ `src/io/controls.h:45:9`!)) statscxx . . $ Level#stats. ^= S_SCREENcxx . . $ S_SCREEN.; |
| 131 | |
| 132 | |
| 133 | timeCalcscxx . . $ Level#timeCalcs(49f6e7a06ebc5aa8).(); |
| 134 | |
| 135 | |
| 136 | |
| 137 | // Use macro |
| 138 | unsigned char macroPoint = macrocxx . . $ JJ1DemoLevel#macro.[(tickscxx . . $ Level#ticks. / 76) & 1023]; |
| 139 | |
| 140 | if (macroPoint & 128) return E_NONEcxx . . $ `src/OpenJazz.h:69:9`!; |
| 141 | |
| 142 | if (macroPoint & 1) { |
| 143 | |
| 144 | localPlayercxx . . $ localPlayer.->setControlcxx . . $ Player#setControl(918ebd27a9ddbad3).(C_LEFTcxx . . $ `src/io/controls.h:32:9`!, false); |
| 145 | localPlayercxx . . $ localPlayer.->setControlcxx . . $ Player#setControl(918ebd27a9ddbad3).(C_RIGHTcxx . . $ `src/io/controls.h:33:9`!, false); |
| 146 | localPlayercxx . . $ localPlayer.->setControlcxx . . $ Player#setControl(918ebd27a9ddbad3).(C_UPcxx . . $ `src/io/controls.h:30:9`!, !(macroPoint & 4)); |
| 147 | |
| 148 | } else { |
| 149 | |
| 150 | localPlayercxx . . $ localPlayer.->setControlcxx . . $ Player#setControl(918ebd27a9ddbad3).(C_LEFTcxx . . $ `src/io/controls.h:32:9`!, !(macroPoint & 2)); |
| 151 | localPlayercxx . . $ localPlayer.->setControlcxx . . $ Player#setControl(918ebd27a9ddbad3).(C_RIGHTcxx . . $ `src/io/controls.h:33:9`!, macroPoint & 2); |
| 152 | localPlayercxx . . $ localPlayer.->setControlcxx . . $ Player#setControl(918ebd27a9ddbad3).(C_UPcxx . . $ `src/io/controls.h:30:9`!, false); |
| 153 | |
| 154 | } |
| 155 | |
| 156 | localPlayercxx . . $ localPlayer.->setControlcxx . . $ Player#setControl(918ebd27a9ddbad3).(C_DOWNcxx . . $ `src/io/controls.h:31:9`!, macroPoint & 8); |
| 157 | localPlayercxx . . $ localPlayer.->setControlcxx . . $ Player#setControl(918ebd27a9ddbad3).(C_FIREcxx . . $ `src/io/controls.h:36:9`!, macroPoint & 16); |
| 158 | localPlayercxx . . $ localPlayer.->setControlcxx . . $ Player#setControl(918ebd27a9ddbad3).(C_CHANGEcxx . . $ `src/io/controls.h:37:9`!, macroPoint & 32); |
| 159 | localPlayercxx . . $ localPlayer.->setControlcxx . . $ Player#setControl(918ebd27a9ddbad3).(C_JUMPcxx . . $ `src/io/controls.h:34:9`!, macroPoint & 64); |
| 160 | localPlayercxx . . $ localPlayer.->setControlcxx . . $ Player#setControl(918ebd27a9ddbad3).(C_SWIMcxx . . $ `src/io/controls.h:35:9`!, macroPoint & 64); |
| 161 | |
| 162 | |
| 163 | |
| 164 | // Check if level has been won |
| 165 | if (getStagecxx . . $ Level#getStage(5189a4c765e66121).() == LS_ENDcxx . . $ LS_END.) return WONcxx . . $ `src/level/level.h:46:9`!; |
| 166 | |
| 167 | |
| 168 | // Process frame-by-frame activity |
| 169 | |
| 170 | // Process step |
| 171 | while (getTimeChangecxx . . $ Level#getTimeChange(b126dc7c1de90089).() >= T_STEPcxx . . $ `src/level/level.h:50:9`!) { |
| 172 | |
| 173 | int ret = stepcxx . . $ JJ1Level#step(b126dc7c1de90089).(); |
| 174 | stepscxx . . $ Level#steps.++; |
| 175 | |
| 176 | if (ret < 0) return ret; |
| 177 | |
| 178 | } |
| 179 | |
| 180 | |
| 181 | // Handle player reactions |
| 182 | if (localPlayercxx . . $ localPlayer.->getJJ1LevelPlayercxx . . $ Player#getJJ1LevelPlayer(cf23ec4c0d6db922).()->reactedcxx . . $ JJ1LevelPlayer#reacted(c1136c0fafdb757a).(tickscxx . . $ Level#ticks.) == PR_KILLEDcxx . . $ PR_KILLED.) return LOSTcxx . . $ `src/level/level.h:47:9`!; |
| 183 | |
| 184 | |
| 185 | // Draw the graphics |
| 186 | |
| 187 | drawcxx . . $ JJ1Level#draw(49f6e7a06ebc5aa8).(); |
| 188 | drawOverlaycxx . . $ Level#drawOverlay(ac8280b982de25d7).(LEVEL_BLACKcxx . . $ `src/jj1/level/jj1level.h:137:9`!, false, 0, 0, 0, 0); |
| 189 | |
| 190 | |
| 191 | fontcxx . . $ JJ1Level#font.->showStringcxx . . $ Font#showString(7e50a619d5a117f1).("demo", canvasWcxx . . $ canvasW. >> 1, 32, alignXcxx . . $ alignX#::Centercxx . . $ alignX#Center.); |
| 192 | |
| 193 | |
| 194 | } |
| 195 | |
| 196 | return E_NONEcxx . . $ `src/OpenJazz.h:69:9`!; |
| 197 | |
| 198 | } |
| 199 | |
| 200 |