| 1 | |
| 2 | /** |
| 3 | * |
| 4 | * @file jj1planet.cpp |
| 5 | * |
| 6 | * Part of the OpenJazz project |
| 7 | * |
| 8 | * @par History: |
| 9 | * - 23rd August 2005: Created planet.c |
| 10 | * - 3rd February 2009: Renamed planet.c to planet.cpp |
| 11 | * - 1st August 2012: Renamed planet.cpp to jj1planet.cpp |
| 12 | * |
| 13 | * @par Licence: |
| 14 | * Copyright (c) 2005-2017 AJ Thomson |
| 15 | * |
| 16 | * OpenJazz is distributed under the terms of |
| 17 | * the GNU General Public License, version 2.0 |
| 18 | * |
| 19 | * @par Description: |
| 20 | * Deals with the loading, displaying and freeing of the planet landing |
| 21 | * sequence. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | #include "jj1planet.h"cxx . . $ `<file>/src/jj1/planet/jj1planet.h`/ |
| 27 | |
| 28 | #include "io/controls.h"cxx . . $ `<file>/src/io/controls.h`/ |
| 29 | #include "io/file.h"cxx . . $ `<file>/src/io/file.h`/ |
| 30 | #include "io/gfx/font.h"cxx . . $ `<file>/src/io/gfx/font.h`/ |
| 31 | #include "io/gfx/video.h"cxx . . $ `<file>/src/io/gfx/video.h`/ |
| 32 | #include "io/sound.h"cxx . . $ `<file>/src/io/sound.h`/ |
| 33 | #include "loop.h"cxx . . $ `<file>/src/loop.h`/ |
| 34 | #include "util.h"cxx . . $ `<file>/src/util.h`/ |
| 35 | |
| 36 | #include <string.h> |
| 37 | |
| 38 | |
| 39 | /** |
| 40 | * Create a JJ1 planet approach sequence. |
| 41 | * |
| 42 | * @param fileName Name of the file containing the planet data |
| 43 | * @param previous The ID of the last planet approach sequence |
| 44 | */ |
| 45 | JJ1Planetcxx . . $ JJ1Planet#::JJ1Planetcxx . . $ JJ1Planet#JJ1Planet(a07d8cccb7673f5a). (char * fileName, int previous) { |
| 46 | |
| 47 | Filecxx . . $ File# *file; |
| 48 | unsigned char *pixels; |
| 49 | int count; |
| 50 | |
| 51 | try { |
| 52 | |
| 53 | file = new Filecxx . . $ File#File(e99a0a23efd851c6).(fileName, PATH_TYPE_GAMEcxx . . $ PATH_TYPE_GAME.); |
| 54 | |
| 55 | } catch (int e) { |
| 56 | |
| 57 | throw; |
| 58 | |
| 59 | } |
| 60 | |
| 61 | idcxx . . $ JJ1Planet#id. = file->loadShortcxx . . $ File#loadShort(32a7769d58713265).(); |
| 62 | |
| 63 | if (idcxx . . $ JJ1Planet#id. == previous) { |
| 64 | |
| 65 | // Not approaching a planet if already there |
| 66 | |
| 67 | delete file; |
| 68 | |
| 69 | throw E_NONEcxx . . $ `src/OpenJazz.h:69:9`!; |
| 70 | |
| 71 | } |
| 72 | |
| 73 | // Load planet name |
| 74 | namecxx . . $ JJ1Planet#name. = file->loadTerminatedStringcxx . . $ File#loadTerminatedString(ff224f080444ee45).(); |
| 75 | |
| 76 | // Lower-case the name |
| 77 | for (count = 0; namecxx . . $ JJ1Planet#name.[count]; count++) { |
| 78 | |
| 79 | if ((namecxx . . $ JJ1Planet#name.[count] >= 65) && (namecxx . . $ JJ1Planet#name.[count] <= 90)) namecxx . . $ JJ1Planet#name.[count] += 32; |
| 80 | |
| 81 | } |
| 82 | |
| 83 | // Load the palette |
| 84 | file->loadPalettecxx . . $ File#loadPalette(a8e7e0a5cf0a5bef).(palettecxx . . $ JJ1Planet#palette., false); |
| 85 | |
| 86 | // Load the planet image |
| 87 | pixels = file->loadBlockcxx . . $ File#loadBlock(f18dc31a6ecbac56).(64 * 55); |
| 88 | spritecxx . . $ JJ1Planet#sprite..setPixelscxx . . $ Sprite#setPixels(3f9b724c895640a0).(pixels, 64, 55, 0); |
| 89 | delete[] pixels; |
| 90 | |
| 91 | |
| 92 | delete file; |
| 93 | |
| 94 | } |
| 95 | |
| 96 | |
| 97 | /** |
| 98 | * Delete the JJ1 planet approach sequence. |
| 99 | */ |
| 100 | JJ1Planetcxx . . $ JJ1Planet#::~cxx . . $ JJ1Planet#`~JJ1Planet`(49f6e7a06ebc5aa8).JJ1Planetcxx . . $ JJ1Planet# () { |
| 101 | |
| 102 | delete[] namecxx . . $ JJ1Planet#name.; |
| 103 | |
| 104 | } |
| 105 | |
| 106 | |
| 107 | /** |
| 108 | * Get the ID of the planet approach squence. |
| 109 | * |
| 110 | * @return The ID |
| 111 | */ |
| 112 | int JJ1Planetcxx . . $ JJ1Planet#::getIdcxx . . $ JJ1Planet#getId(b126dc7c1de90089). () { |
| 113 | |
| 114 | return idcxx . . $ JJ1Planet#id.; |
| 115 | |
| 116 | } |
| 117 | |
| 118 | |
| 119 | /** |
| 120 | * Run the JJ1 planet approach sequence. |
| 121 | * |
| 122 | * @return Error code |
| 123 | */ |
| 124 | int JJ1Planetcxx . . $ JJ1Planet#::playcxx . . $ JJ1Planet#play(b126dc7c1de90089). () { |
| 125 | |
| 126 | unsigned int tickOffset; |
| 127 | |
| 128 | tickOffset = globalTickscxx . . $ globalTicks.; |
| 129 | |
| 130 | stopMusiccxx . . $ stopMusic(49f6e7a06ebc5aa8).(); |
| 131 | |
| 132 | videocxx . . $ video..setPalettecxx . . $ Video#setPalette(d5421d17e1a4b2b2).(palettecxx . . $ JJ1Planet#palette.); |
| 133 | |
| 134 | while (true) { |
| 135 | |
| 136 | if (loopcxx . . $ loop(fd873fd06cfe1135).(NORMAL_LOOPcxx . . $ NORMAL_LOOP.) == E_QUITcxx . . $ `src/OpenJazz.h:67:9`!) return E_QUITcxx . . $ `src/OpenJazz.h:67:9`!; |
| 137 | |
| 138 | if (controlscxx . . $ controls..releasecxx . . $ Controls#release(83c267b20bac841a).(C_ESCAPEcxx . . $ `src/io/controls.h:39:9`!) || controlscxx . . $ controls..wasCursorReleasedcxx . . $ Controls#wasCursorReleased(c9857a73d68e59ba).()) return E_NONEcxx . . $ `src/OpenJazz.h:69:9`!; |
| 139 | |
| 140 | SDL_Delay(T_MENU_FRAMEcxx . . $ `src/io/gfx/video.h:78:9`!); |
| 141 | |
| 142 | videocxx . . $ video..clearScreencxx . . $ Video#clearScreen(d4f767463ce0a6b3).(0); |
| 143 | |
| 144 | if (globalTickscxx . . $ globalTicks. - tickOffset < F2cxx . . $ `src/types.h:32:9`!) |
| 145 | spritecxx . . $ JJ1Planet#sprite..drawScaledcxx . . $ Sprite#drawScaled(b1146eedae1e1d0b).(canvasWcxx . . $ canvasW. >> 1, canvasHcxx . . $ canvasH. >> 1, globalTickscxx . . $ globalTicks. - tickOffset); |
| 146 | else if (globalTickscxx . . $ globalTicks. - tickOffset < F4cxx . . $ `src/types.h:33:9`!) |
| 147 | spritecxx . . $ JJ1Planet#sprite..drawScaledcxx . . $ Sprite#drawScaled(b1146eedae1e1d0b).(canvasWcxx . . $ canvasW. >> 1, canvasHcxx . . $ canvasH. >> 1, F2cxx . . $ `src/types.h:32:9`!); |
| 148 | else if (globalTickscxx . . $ globalTicks. - tickOffset < F4cxx . . $ `src/types.h:33:9`! + FQcxx . . $ `src/types.h:29:9`!) |
| 149 | spritecxx . . $ JJ1Planet#sprite..drawScaledcxx . . $ Sprite#drawScaled(b1146eedae1e1d0b).(canvasWcxx . . $ canvasW. >> 1, canvasHcxx . . $ canvasH. >> 1, (globalTickscxx . . $ globalTicks. - tickOffset - F4cxx . . $ `src/types.h:33:9`!) * 32 + F2cxx . . $ `src/types.h:32:9`!); |
| 150 | else return E_NONEcxx . . $ `src/OpenJazz.h:69:9`!; |
| 151 | |
| 152 | fontmn1cxx . . $ fontmn1.->showStringcxx . . $ Font#showString(7e50a619d5a117f1).("now approaching", (canvasWcxx . . $ canvasW. >> 1), 2, alignXcxx . . $ alignX#::Centercxx . . $ alignX#Center.); |
| 153 | fontmn1cxx . . $ fontmn1.->showStringcxx . . $ Font#showString(7e50a619d5a117f1).(namecxx . . $ JJ1Planet#name., (canvasWcxx . . $ canvasW. >> 1), canvasHcxx . . $ canvasH. - 2, alignXcxx . . $ alignX#::Centercxx . . $ alignX#Center., alignYcxx . . $ alignY#::Bottomcxx . . $ alignY#Bottom.); |
| 154 | |
| 155 | } |
| 156 | |
| 157 | return E_NONEcxx . . $ `src/OpenJazz.h:69:9`!; |
| 158 | |
| 159 | } |