| 1 | |
| 2 | /** |
| 3 | * |
| 4 | * @file anim.cpp |
| 5 | * |
| 6 | * Part of the OpenJazz project |
| 7 | * |
| 8 | * @par History |
| 9 | * - 23rd August 2005: Created level.c |
| 10 | * - 1st January 2006: Created events.c from parts of level.c |
| 11 | * - 3rd February 2009: Renamed events.c to events.cpp and level.c to level.cpp, |
| 12 | * created player.cpp |
| 13 | * - 5th February 2009: Added parts of events.cpp and level.cpp to player.cpp |
| 14 | * - 19th March 2009: Created sprite.cpp from parts of event.cpp and player.cpp |
| 15 | * - 26th July 2009: Created anim.cpp from parts of sprite.cpp |
| 16 | * |
| 17 | * @par Licence |
| 18 | * Copyright (c) 2005-2013 AJ Thomson |
| 19 | * |
| 20 | * OpenJazz is distributed under the terms of |
| 21 | * the GNU General Public License, version 2.0 |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | |
| 26 | #include "anim.h"cxx . . $ `<file>/src/io/gfx/anim.h`/ |
| 27 | #include "sprite.h"cxx . . $ `<file>/src/io/gfx/sprite.h`/ |
| 28 | |
| 29 | #include "jj1/level/jj1level.h"cxx . . $ `<file>/src/jj1/level/jj1level.h`/ |
| 30 | |
| 31 | #ifdef OJ_SDL3 |
| 32 | #include <SDL3/SDL.h> |
| 33 | #else |
| 34 | #include <SDL.h> |
| 35 | #endif |
| 36 | |
| 37 | /** |
| 38 | * Create empty animation. |
| 39 | */ |
| 40 | Animcxx . . $ Anim#::Animcxx . . $ Anim#Anim(49f6e7a06ebc5aa8). () { |
| 41 | |
| 42 | spritescxx . . $ Anim#sprites. = new Spritecxx . . $ Sprite# *[19]; |
| 43 | xOffsetscxx . . $ Anim#xOffsets. = new signed char[19]; |
| 44 | yOffsetscxx . . $ Anim#yOffsets. = new signed char[19]; |
| 45 | |
| 46 | shootXcxx . . $ Anim#shootX. = shootYcxx . . $ Anim#shootY. = 0; |
| 47 | accessoryXcxx . . $ Anim#accessoryX. = accessoryYcxx . . $ Anim#accessoryY. = 0; |
| 48 | yOffsetcxx . . $ Anim#yOffset. = 0; |
| 49 | framescxx . . $ Anim#frames. = 19; |
| 50 | framecxx . . $ Anim#frame. = 0; |
| 51 | accessorycxx . . $ Anim#accessory. = 0; |
| 52 | |
| 53 | } |
| 54 | |
| 55 | |
| 56 | /** |
| 57 | * Delete animation. |
| 58 | */ |
| 59 | Animcxx . . $ Anim#::~cxx . . $ Anim#`~Anim`(49f6e7a06ebc5aa8).Animcxx . . $ Anim# () { |
| 60 | |
| 61 | delete[] spritescxx . . $ Anim#sprites.; |
| 62 | delete[] xOffsetscxx . . $ Anim#xOffsets.; |
| 63 | delete[] yOffsetscxx . . $ Anim#yOffsets.; |
| 64 | |
| 65 | } |
| 66 | |
| 67 | |
| 68 | /** |
| 69 | * Set overall animation data. |
| 70 | * |
| 71 | * @param length Number of frames |
| 72 | * @param sX Bullet generation x-coordinate |
| 73 | * @param sY Bullet generation y-coordinate |
| 74 | * @param aX Accessory animation x-coordinate |
| 75 | * @param aY Accessory animation y-coordinate |
| 76 | * @param a Accessory animation index |
| 77 | * @param y Vertical offset |
| 78 | */ |
| 79 | void Animcxx . . $ Anim#::setDatacxx . . $ Anim#setData(f6a7b8e80ccbdd28). (int length, signed char sX, signed char sY, signed char aX, signed char aY, unsigned char a, signed char y) { |
| 80 | |
| 81 | if (length > 19) { |
| 82 | |
| 83 | delete[] spritescxx . . $ Anim#sprites.; |
| 84 | delete[] xOffsetscxx . . $ Anim#xOffsets.; |
| 85 | delete[] yOffsetscxx . . $ Anim#yOffsets.; |
| 86 | |
| 87 | spritescxx . . $ Anim#sprites. = new Spritecxx . . $ Sprite# *[length]; |
| 88 | xOffsetscxx . . $ Anim#xOffsets. = new signed char[length]; |
| 89 | yOffsetscxx . . $ Anim#yOffsets. = new signed char[length]; |
| 90 | |
| 91 | } |
| 92 | |
| 93 | framescxx . . $ Anim#frames. = length; |
| 94 | shootXcxx . . $ Anim#shootX. = sX; |
| 95 | shootYcxx . . $ Anim#shootY. = sY; |
| 96 | accessoryXcxx . . $ Anim#accessoryX. = aX; |
| 97 | accessoryYcxx . . $ Anim#accessoryY. = aY; |
| 98 | accessorycxx . . $ Anim#accessory. = a; |
| 99 | yOffsetcxx . . $ Anim#yOffset. = y; |
| 100 | |
| 101 | } |
| 102 | |
| 103 | |
| 104 | /** |
| 105 | * Set current frame. |
| 106 | * |
| 107 | * @param nextFrame The frame to use |
| 108 | * @param looping Whether the animation should stop at the end or loop |
| 109 | */ |
| 110 | void Animcxx . . $ Anim#::setFramecxx . . $ Anim#setFrame(918ebd27a9ddbad3). (int nextFrame, bool looping) { |
| 111 | |
| 112 | if (looping) framecxx . . $ Anim#frame. = nextFrame % framescxx . . $ Anim#frames.; |
| 113 | else framecxx . . $ Anim#frame. = (nextFrame >= framescxx . . $ Anim#frames.)? framescxx . . $ Anim#frames. - 1: nextFrame; |
| 114 | |
| 115 | } |
| 116 | |
| 117 | |
| 118 | /** |
| 119 | * Set the data for the current frame. |
| 120 | * |
| 121 | * @param sprite Sprite to use |
| 122 | * @param x Horizontal offset |
| 123 | * @param y Vertical offset |
| 124 | */ |
| 125 | void Animcxx . . $ Anim#::setFrameDatacxx . . $ Anim#setFrameData(b004b9a6a91098d4). (Spritecxx . . $ Sprite# *sprite, signed char x, signed char y) { |
| 126 | |
| 127 | spritescxx . . $ Anim#sprites.[framecxx . . $ Anim#frame.] = sprite; |
| 128 | xOffsetscxx . . $ Anim#xOffsets.[framecxx . . $ Anim#frame.] = x; |
| 129 | yOffsetscxx . . $ Anim#yOffsets.[framecxx . . $ Anim#frame.] = y; |
| 130 | |
| 131 | } |
| 132 | |
| 133 | |
| 134 | /** |
| 135 | * Determine the width of the current frame. |
| 136 | * |
| 137 | * @return The width of the current frame |
| 138 | */ |
| 139 | int Animcxx . . $ Anim#::getWidthcxx . . $ Anim#getWidth(b126dc7c1de90089). () { |
| 140 | |
| 141 | return spritescxx . . $ Anim#sprites.[framecxx . . $ Anim#frame.]->getWidthcxx . . $ Sprite#getWidth(b126dc7c1de90089).(); |
| 142 | |
| 143 | } |
| 144 | |
| 145 | |
| 146 | /** |
| 147 | * Determine the height of the current frame. |
| 148 | * |
| 149 | * @return The height of the current frame |
| 150 | */ |
| 151 | int Animcxx . . $ Anim#::getHeightcxx . . $ Anim#getHeight(b126dc7c1de90089). () { |
| 152 | |
| 153 | return spritescxx . . $ Anim#sprites.[framecxx . . $ Anim#frame.]->getHeightcxx . . $ Sprite#getHeight(b126dc7c1de90089).(); |
| 154 | |
| 155 | } |
| 156 | |
| 157 | |
| 158 | /** |
| 159 | * Determine the length of the animation. |
| 160 | * |
| 161 | * @return The length of the animation |
| 162 | */ |
| 163 | int Animcxx . . $ Anim#::getLengthcxx . . $ Anim#getLength(b126dc7c1de90089). () { |
| 164 | |
| 165 | return framescxx . . $ Anim#frames.; |
| 166 | |
| 167 | } |
| 168 | |
| 169 | |
| 170 | /** |
| 171 | * Determine the bullet generation x-coordinate of the current frame. |
| 172 | * |
| 173 | * @return The bullet generation x-coordinate |
| 174 | */ |
| 175 | fixedcxx . . $ fixed# Animcxx . . $ Anim#::getShootXcxx . . $ Anim#getShootX(b126dc7c1de90089). () { |
| 176 | |
| 177 | return ITOFcxx . . $ `src/types.h:53:9`!(shootX + xOffsets[frame]) << 2; |
| 178 | |
| 179 | } |
| 180 | |
| 181 | |
| 182 | /** |
| 183 | * Determine the bullet generation y-coordinate of the current frame. |
| 184 | * |
| 185 | * @return The bullet generation y-coordinate |
| 186 | */ |
| 187 | fixedcxx . . $ fixed# Animcxx . . $ Anim#::getShootYcxx . . $ Anim#getShootY(b126dc7c1de90089). () { |
| 188 | |
| 189 | return ITOFcxx . . $ `src/types.h:53:9`!(shootY + yOffsets[frame]); |
| 190 | |
| 191 | } |
| 192 | |
| 193 | |
| 194 | /** |
| 195 | * Determine the accessory bullet generation x-coordinate of the current frame. |
| 196 | * |
| 197 | * @return The accessory bullet generation x-coordinate |
| 198 | */ |
| 199 | fixedcxx . . $ fixed# Animcxx . . $ Anim#::getAccessoryShootXcxx . . $ Anim#getAccessoryShootX(b126dc7c1de90089). () { |
| 200 | |
| 201 | return ITOFcxx . . $ `src/types.h:53:9`!(shootX + accessoryX + xOffsets[frame]) << 2; |
| 202 | |
| 203 | } |
| 204 | |
| 205 | |
| 206 | /** |
| 207 | * Determine the accessory bullet generation y-coordinate of the current frame. |
| 208 | * |
| 209 | * @return The accessory bullet generation y-coordinate |
| 210 | */ |
| 211 | fixedcxx . . $ fixed# Animcxx . . $ Anim#::getAccessoryShootYcxx . . $ Anim#getAccessoryShootY(b126dc7c1de90089). () { |
| 212 | |
| 213 | return ITOFcxx . . $ `src/types.h:53:9`!(shootY + accessoryY + yOffsets[frame]); |
| 214 | |
| 215 | } |
| 216 | |
| 217 | |
| 218 | /** |
| 219 | * Determine the vertical offset. |
| 220 | * |
| 221 | * @return The vertical offset |
| 222 | */ |
| 223 | fixedcxx . . $ fixed# Animcxx . . $ Anim#::getOffsetcxx . . $ Anim#getOffset(b126dc7c1de90089). () { |
| 224 | |
| 225 | return -ITOFcxx . . $ `src/types.h:53:9`!(yOffset); |
| 226 | |
| 227 | } |
| 228 | |
| 229 | |
| 230 | /** |
| 231 | * Determine the horizontal offset of the current frame. |
| 232 | * |
| 233 | * @return The horizontal offset |
| 234 | */ |
| 235 | fixedcxx . . $ fixed# Animcxx . . $ Anim#::getXOffsetcxx . . $ Anim#getXOffset(b126dc7c1de90089). () { |
| 236 | |
| 237 | return ITOFcxx . . $ `src/types.h:53:9`!(sprites[frame]->getXOffset() + (xOffsets[frame] << 2) + 1); |
| 238 | |
| 239 | } |
| 240 | |
| 241 | |
| 242 | /** |
| 243 | * Determine the vertical offset of the current frame. |
| 244 | * |
| 245 | * @return The vertical offset |
| 246 | */ |
| 247 | fixedcxx . . $ fixed# Animcxx . . $ Anim#::getYOffsetcxx . . $ Anim#getYOffset(b126dc7c1de90089). () { |
| 248 | |
| 249 | return ITOFcxx . . $ `src/types.h:53:9`!(sprites[frame]->getYOffset() + yOffsets[frame] + 1); |
| 250 | |
| 251 | } |
| 252 | |
| 253 | |
| 254 | /** |
| 255 | * Draw current frame. |
| 256 | * |
| 257 | * @param x X-coordinate at which to draw |
| 258 | * @param y Y-coordinate at which to draw |
| 259 | * @param accessories Number of accessory animations to draw |
| 260 | */ |
| 261 | void Animcxx . . $ Anim#::drawcxx . . $ Anim#draw(b1146eedae1e1d0b). (fixedcxx . . $ fixed# x, fixedcxx . . $ fixed# y, int accessories) { |
| 262 | |
| 263 | spritescxx . . $ Anim#sprites.[framecxx . . $ Anim#frame.]->drawcxx . . $ Sprite#draw(6908015b96d379c0).( |
| 264 | FTOIcxx . . $ `src/types.h:52:9`!(x) + (xOffsetscxx . . $ Anim#xOffsets.[framecxx . . $ Anim#frame.] << 2), |
| 265 | FTOIcxx . . $ `src/types.h:52:9`!(y) + yOffsetscxx . . $ Anim#yOffsets.[framecxx . . $ Anim#frame.] - yOffsetcxx . . $ Anim#yOffset.); |
| 266 | |
| 267 | |
| 268 | if (accessories && accessorycxx . . $ Anim#accessory.) { |
| 269 | |
| 270 | Animcxx . . $ Anim#* anim = levelcxx . . $ level.->getAnimcxx . . $ JJ1Level#getAnim(e50c847d642a1093).(accessorycxx . . $ Anim#accessory.); |
| 271 | anim->setFramecxx . . $ Anim#setFrame(918ebd27a9ddbad3).(framecxx . . $ Anim#frame., true); |
| 272 | anim->drawcxx . . $ Anim#draw(b1146eedae1e1d0b).( |
| 273 | x + ITOFcxx . . $ `src/types.h:53:9`!(accessoryX << 2), |
| 274 | y + ITOFcxx . . $ `src/types.h:53:9`!(accessoryY - yOffset) - anim->getOffsetcxx . . $ Anim#getOffset(b126dc7c1de90089).(), |
| 275 | accessories - 1); |
| 276 | |
| 277 | } |
| 278 | |
| 279 | } |
| 280 | |
| 281 | |
| 282 | /** |
| 283 | * Draw current frame scaled. |
| 284 | * |
| 285 | * @param x X-coordinate at which to draw |
| 286 | * @param y Y-coordinate at which to draw |
| 287 | * @param scale Scaling factor |
| 288 | */ |
| 289 | void Animcxx . . $ Anim#::drawScaledcxx . . $ Anim#drawScaled(b1146eedae1e1d0b). (fixedcxx . . $ fixed# x, fixedcxx . . $ fixed# y, fixedcxx . . $ fixed# scale) { |
| 290 | |
| 291 | // Used to draw bonus level player, so no offset |
| 292 | spritescxx . . $ Anim#sprites.[framecxx . . $ Anim#frame.]->drawScaledcxx . . $ Sprite#drawScaled(b1146eedae1e1d0b).(FTOIcxx . . $ `src/types.h:52:9`!(x), FTOIcxx . . $ `src/types.h:52:9`!(y), scale); |
| 293 | |
| 294 | } |
| 295 | |
| 296 | |
| 297 | /** |
| 298 | * Set the current frame's palette. |
| 299 | * |
| 300 | * @param palette The new palette to use |
| 301 | * @param start The first entry to use |
| 302 | * @param amount The number of entries to use |
| 303 | */ |
| 304 | void Animcxx . . $ Anim#::setPalettecxx . . $ Anim#setPalette(acbc52fef2632da7). (SDL_Color *palette, int start, int amount) { |
| 305 | |
| 306 | spritescxx . . $ Anim#sprites.[framecxx . . $ Anim#frame.]->setPalettecxx . . $ Sprite#setPalette(acbc52fef2632da7).(palette, start, amount); |
| 307 | |
| 308 | } |
| 309 | |
| 310 | |
| 311 | /** |
| 312 | * Turn the whole of the current frame a single colour. |
| 313 | * |
| 314 | * @param index The index of the colour to use |
| 315 | */ |
| 316 | void Animcxx . . $ Anim#::flashPalettecxx . . $ Anim#flashPalette(d4f767463ce0a6b3). (int index) { |
| 317 | |
| 318 | spritescxx . . $ Anim#sprites.[framecxx . . $ Anim#frame.]->flashPalettecxx . . $ Sprite#flashPalette(d4f767463ce0a6b3).(index); |
| 319 | |
| 320 | } |
| 321 | |
| 322 | |
| 323 | /** |
| 324 | * Restore the current frame's original palette. |
| 325 | */ |
| 326 | void Animcxx . . $ Anim#::restorePalettecxx . . $ Anim#restorePalette(49f6e7a06ebc5aa8). () { |
| 327 | |
| 328 | spritescxx . . $ Anim#sprites.[framecxx . . $ Anim#frame.]->restorePalettecxx . . $ Sprite#restorePalette(49f6e7a06ebc5aa8).(); |
| 329 | |
| 330 | } |