| 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" |
| 27 | |
| 28 | #include "io/controls.h" |
| 29 | #include "io/file.h" |
| 30 | #include "io/gfx/font.h" |
| 31 | #include "io/gfx/video.h" |
| 32 | #include "io/sound.h" |
| 33 | #include "loop.h" |
| 34 | #include "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 | JJ1Planet::JJ1Planet (char * fileName, int previous) { |
| 46 | |
| 47 | File *file; |
| 48 | unsigned char *pixels; |
| 49 | int count; |
| 50 | |
| 51 | try { |
| 52 | |
| 53 | file = new File(fileName, PATH_TYPE_GAME); |
| 54 | |
| 55 | } catch (int e) { |
| 56 | |
| 57 | throw; |
| 58 | |
| 59 | } |
| 60 | |
| 61 | id = file->loadShort(); |
| 62 | |
| 63 | if (id == previous) { |
| 64 | |
| 65 | // Not approaching a planet if already there |
| 66 | |
| 67 | delete file; |
| 68 | |
| 69 | throw E_NONE; |
| 70 | |
| 71 | } |
| 72 | |
| 73 | // Load planet name |
| 74 | name = file->loadTerminatedString(); |
| 75 | |
| 76 | // Lower-case the name |
| 77 | for (count = 0; name[count]; count++) { |
| 78 | |
| 79 | if ((name[count] >= 65) && (name[count] <= 90)) name[count] += 32; |
| 80 | |
| 81 | } |
| 82 | |
| 83 | // Load the palette |
| 84 | file->loadPalette(palette, false); |
| 85 | |
| 86 | // Load the planet image |
| 87 | pixels = file->loadBlock(64 * 55); |
| 88 | sprite.setPixels(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 | JJ1Planet::~JJ1Planet () { |
| 101 | |
| 102 | delete[] name; |
| 103 | |
| 104 | } |
| 105 | |
| 106 | |
| 107 | /** |
| 108 | * Get the ID of the planet approach squence. |
| 109 | * |
| 110 | * @return The ID |
| 111 | */ |
| 112 | int JJ1Planet::getId () { |
| 113 | |
| 114 | return id; |
| 115 | |
| 116 | } |
| 117 | |
| 118 | |
| 119 | /** |
| 120 | * Run the JJ1 planet approach sequence. |
| 121 | * |
| 122 | * @return Error code |
| 123 | */ |
| 124 | int JJ1Planet::play () { |
| 125 | |
| 126 | unsigned int tickOffset; |
| 127 | |
| 128 | tickOffset = globalTicks; |
| 129 | |
| 130 | stopMusic(); |
| 131 | |
| 132 | video.setPalette(palette); |
| 133 | |
| 134 | while (true) { |
| 135 | |
| 136 | if (loop(NORMAL_LOOP) == E_QUIT) return E_QUIT; |
| 137 | |
| 138 | if (controls.release(C_ESCAPE) || controls.wasCursorReleased()) return E_NONE; |
| 139 | |
| 140 | SDL_Delay(T_MENU_FRAME); |
| 141 | |
| 142 | video.clearScreen(0); |
| 143 | |
| 144 | if (globalTicks - tickOffset < F2) |
| 145 | sprite.drawScaled(canvasW >> 1, canvasH >> 1, globalTicks - tickOffset); |
| 146 | else if (globalTicks - tickOffset < F4) |
| 147 | sprite.drawScaled(canvasW >> 1, canvasH >> 1, F2); |
| 148 | else if (globalTicks - tickOffset < F4 + FQ) |
| 149 | sprite.drawScaled(canvasW >> 1, canvasH >> 1, (globalTicks - tickOffset - F4) * 32 + F2); |
| 150 | else return E_NONE; |
| 151 | |
| 152 | fontmn1->showString("now approaching", (canvasW >> 1), 2, alignX::Center); |
| 153 | fontmn1->showString(name, (canvasW >> 1), canvasH - 2, alignX::Center, alignY::Bottom); |
| 154 | |
| 155 | } |
| 156 | |
| 157 | return E_NONE; |
| 158 | |
| 159 | } |