Commit fcd9bfa7 authored by newspaz's avatar newspaz

These changes correct the positioning of many in-game animations.

anim.h, anim.cpp
*) Frame by frame X-offsets are being shifted two bits up now.
*) The animation-wide X-offset has been removed because it does not exist.

levelload.cpp, bonus.cpp
*) Due to the changes in anim.cpp and anim.h the animation loading code had to be changed.

bridge.cpp
*) Bridges should ignore an animation's Y-offset if it is zero.

event.h, event.cpp
*) Added a getAnim method to make life easier.
*) Events with certain behaviors need some fiddling with Y-offsets so they can be drawn correctly.

playerframe.cpp
*) The invincibility animation should also ignore Y-offsets.
parent a5d608b7
...@@ -236,7 +236,8 @@ Bonus::Bonus (char * fileName, unsigned char diff) { ...@@ -236,7 +236,8 @@ Bonus::Bonus (char * fileName, unsigned char diff) {
animSet[count].setData(buffer[(count << 6) + 6], animSet[count].setData(buffer[(count << 6) + 6],
buffer[count << 6], buffer[(count << 6) + 1], buffer[count << 6], buffer[(count << 6) + 1],
buffer[(count << 6) + 4], buffer[(count << 6) + 5]); buffer[(count << 6) + 3], buffer[(count << 6) + 4],
buffer[(count << 6) + 2], buffer[(count << 6) + 5]);
for (y = 0; y < buffer[(count << 6) + 6]; y++) { for (y = 0; y < buffer[(count << 6) + 6]; y++) {
...@@ -615,6 +616,7 @@ void Bonus::draw () { ...@@ -615,6 +616,7 @@ void Bonus::draw () {
// Show the player // Show the player
anim = animSet + localPlayer->getAnim(); anim = animSet + localPlayer->getAnim();
anim->disableYOffset();
anim->setFrame(ticks / 75, true); anim->setFrame(ticks / 75, true);
anim->draw(ITOF((canvasW - anim->getWidth()) >> 1), ITOF(canvasH - anim->getHeight() - 28)); anim->draw(ITOF((canvasW - anim->getWidth()) >> 1), ITOF(canvasH - anim->getHeight() - 28));
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
Anim::Anim () { Anim::Anim () {
frame = 0; frame = 0;
ignoreDefaultYOffset = false;
return; return;
...@@ -42,12 +43,14 @@ Anim::~Anim () { ...@@ -42,12 +43,14 @@ Anim::~Anim () {
} }
void Anim::setData (int amount, signed char sX, signed char sY, signed char x, signed char y) { void Anim::setData (int amount, signed char sX, signed char sY, signed char aX, signed char aY, unsigned char a, signed char y) {
frames = amount; frames = amount;
shootX = sX; shootX = sX;
shootY = sY; shootY = sY;
xOffset = x; accessoryX = aX;
accessoryY = aY;
accessory = a;
yOffset = y; yOffset = y;
return; return;
...@@ -92,7 +95,7 @@ int Anim::getHeight () { ...@@ -92,7 +95,7 @@ int Anim::getHeight () {
fixed Anim::getShootX () { fixed Anim::getShootX () {
return ITOF(shootX + xOffsets[frame] - xOffset); return ITOF(shootX + xOffsets[frame]);
} }
...@@ -106,14 +109,45 @@ fixed Anim::getShootY () { ...@@ -106,14 +109,45 @@ fixed Anim::getShootY () {
void Anim::draw (fixed x, fixed y) { void Anim::draw (fixed x, fixed y) {
sprites[frame]->draw(FTOI(x) + xOffsets[frame] - xOffset, // In case yOffset is zero, and the ignore default offset flag is set,
FTOI(y) + yOffsets[frame] - yOffset); // draw the animation without any offset.
if (ignoreDefaultYOffset && yOffset == 0)
sprites[frame]->draw(FTOI(x) + (xOffsets[frame] << 2) + 1,
FTOI(y) + yOffsets[frame] + 1);
// In case yOffset is zero, most animations need a default offset
// of 1 tile (32 pixels).
else if (yOffset == 0)
sprites[frame]->draw(FTOI(x) + (xOffsets[frame] << 2) + 1,
FTOI(y) + yOffsets[frame] - TTOI(1) + 2);
// In all other cases drawing with the Y offset will do.
else
sprites[frame]->draw(FTOI(x) + (xOffsets[frame] << 2) + 1,
FTOI(y) + yOffsets[frame] - yOffset + 1);
return; return;
} }
void Anim::disableYOffset() {
ignoreDefaultYOffset = true;
}
void Anim::copyYOffset(Anim *anim) {
yOffset = anim->yOffset;
}
void Anim::setPalette (SDL_Color *palette, int start, int amount) { void Anim::setPalette (SDL_Color *palette, int start, int amount) {
sprites[frame]->setPalette(palette, 0, 256); sprites[frame]->setPalette(palette, 0, 256);
......
...@@ -37,20 +37,24 @@ class Anim { ...@@ -37,20 +37,24 @@ class Anim {
private: private:
Sprite *sprites[19]; Sprite *sprites[19];
bool ignoreDefaultYOffset;
signed char shootX; signed char shootX;
signed char shootY; signed char shootY;
signed char xOffset; signed char accessoryX;
signed char accessoryY;
signed char yOffset; signed char yOffset;
signed char xOffsets[19]; signed char xOffsets[19];
signed char yOffsets[19]; signed char yOffsets[19];
unsigned char frames; // Number of frames unsigned char frames; // Number of frames
unsigned char frame; // Current frame unsigned char frame; // Current frame
unsigned char accessory; // Number of an animation that is an accessory to this animation
// Most of the time accessories are used with guardians.
public: public:
Anim (); Anim ();
~Anim (); ~Anim ();
void setData (int amount, signed char sX, signed char sY, signed char x, signed char y); void setData (int amount, signed char sX, signed char sY, signed char aX, signed char aY, unsigned char a, signed char y);
void setFrame (int nextFrame, bool looping); void setFrame (int nextFrame, bool looping);
void setFrameData (Sprite *frameSprite, signed char x, signed char y); void setFrameData (Sprite *frameSprite, signed char x, signed char y);
int getWidth (); int getWidth ();
...@@ -58,6 +62,8 @@ class Anim { ...@@ -58,6 +62,8 @@ class Anim {
fixed getShootX (); fixed getShootX ();
fixed getShootY (); fixed getShootY ();
void draw (fixed x, fixed y); void draw (fixed x, fixed y);
void copyYOffset (Anim *anim);
void disableYOffset ();
void setPalette (SDL_Color *palette, int start, int amount); void setPalette (SDL_Color *palette, int start, int amount);
void flashPalette (int index); void flashPalette (int index);
void restorePalette (); void restorePalette ();
......
...@@ -48,6 +48,10 @@ Bridge::Bridge (unsigned char gX, unsigned char gY) { ...@@ -48,6 +48,10 @@ Bridge::Bridge (unsigned char gX, unsigned char gY) {
animType = E_LEFTANIM; animType = E_LEFTANIM;
flashTime = 0; flashTime = 0;
// Bridges should ignore the default yOffsets
getAnim(E_LEFTANIM)->disableYOffset();
getAnim(E_RIGHTANIM)->disableYOffset();
// leftDipX and rightDipX used to store leftmost and rightmost player on bridge // leftDipX and rightDipX used to store leftmost and rightmost player on bridge
// Start with minimum values // Start with minimum values
leftDipX = set[E_MULTIPURPOSE] * set[E_BRIDGELENGTH] * F4; leftDipX = set[E_MULTIPURPOSE] * set[E_BRIDGELENGTH] * F4;
......
...@@ -60,8 +60,19 @@ Event::Event (unsigned char gX, unsigned char gY) { ...@@ -60,8 +60,19 @@ Event::Event (unsigned char gX, unsigned char gY) {
gridY = gY; gridY = gY;
flashTime = 0; flashTime = 0;
Anim *leftAnim = getAnim(E_LEFTANIM);
Anim *rightAnim = getAnim(E_RIGHTANIM);
switch (getProperty(E_BEHAVIOUR)) { switch (getProperty(E_BEHAVIOUR)) {
case 2: // Walk from side to side
case 4: // Walk from side to side and down hills
animType = E_LEFTANIM;
leftAnim->copyYOffset(rightAnim);
break;
case 21: // Destructible block case 21: // Destructible block
case 25: // Float up / Belt case 25: // Float up / Belt
case 37: // Sucker tubes case 37: // Sucker tubes
...@@ -76,6 +87,7 @@ Event::Event (unsigned char gX, unsigned char gY) { ...@@ -76,6 +87,7 @@ Event::Event (unsigned char gX, unsigned char gY) {
case 26: // Flip animation case 26: // Flip animation
animType = E_RIGHTANIM; animType = E_RIGHTANIM;
rightAnim->copyYOffset(leftAnim);
break; break;
...@@ -230,3 +242,24 @@ signed char Event::getProperty (unsigned char property) { ...@@ -230,3 +242,24 @@ signed char Event::getProperty (unsigned char property) {
} }
Anim* Event::getAnim(unsigned char property) {
switch (property) {
case E_LEFTANIM:
case E_RIGHTANIM:
case E_LFINISHANIM:
case E_RFINISHANIM:
case E_LSHOOTANIM:
case E_RSHOOTANIM:
return level->getAnim(getProperty(property));
default:
return 0;
}
}
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include "movable.h" #include "movable.h"
#include "OpenJazz.h" #include "OpenJazz.h"
#include "../../io/gfx/anim.h"
// Constants // Constants
...@@ -104,6 +105,7 @@ class Event : public Movable { ...@@ -104,6 +105,7 @@ class Event : public Movable {
bool isFrom (unsigned char gX, unsigned char gY); bool isFrom (unsigned char gX, unsigned char gY);
virtual bool overlap (fixed left, fixed top, fixed width, fixed height); virtual bool overlap (fixed left, fixed top, fixed width, fixed height);
signed char getProperty (unsigned char property); signed char getProperty (unsigned char property);
Anim* getAnim (unsigned char property);
virtual Event* step (unsigned int ticks, int msps); virtual Event* step (unsigned int ticks, int msps);
virtual void draw (unsigned int ticks, int change); virtual void draw (unsigned int ticks, int change);
void drawEnergy (unsigned int ticks); void drawEnergy (unsigned int ticks);
......
...@@ -656,7 +656,8 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) { ...@@ -656,7 +656,8 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) {
animSet[count].setData(buffer[(count << 6) + 6], animSet[count].setData(buffer[(count << 6) + 6],
buffer[count << 6], buffer[(count << 6) + 1], buffer[count << 6], buffer[(count << 6) + 1],
buffer[(count << 6) + 4], buffer[(count << 6) + 5]); buffer[(count << 6) + 3], buffer[(count << 6) + 4],
buffer[(count << 6) + 2], buffer[(count << 6) + 5]);
for (y = 0; y < buffer[(count << 6) + 6]; y++) { for (y = 0; y < buffer[(count << 6) + 6]; y++) {
......
...@@ -815,6 +815,7 @@ void Player::draw (unsigned int ticks, int change) { ...@@ -815,6 +815,7 @@ void Player::draw (unsigned int ticks, int change) {
yOffset = fCos(ticks * 2) * 12; yOffset = fCos(ticks * 2) * 12;
an = level->getMiscAnim(0); an = level->getMiscAnim(0);
an->disableYOffset();
an->setFrame(frame, true); an->setFrame(frame, true);
an->draw(drawX + PXO_MID + xOffset, drawY + PYO_MID + yOffset); an->draw(drawX + PXO_MID + xOffset, drawY + PYO_MID + yOffset);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment