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
......@@ -234,9 +234,10 @@ Bonus::Bonus (char * fileName, unsigned char diff) {
// Create animation set based on that data
for (count = 0; count < BANIMS; count++) {
animSet[count].setData(buffer[(count << 6) + 6],
buffer[count << 6], buffer[(count << 6) + 1],
buffer[(count << 6) + 4], buffer[(count << 6) + 5]);
animSet[count].setData(buffer[(count << 6) + 6],
buffer[count << 6], buffer[(count << 6) + 1],
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++) {
......@@ -614,7 +615,8 @@ void Bonus::draw () {
// Show the player
anim = animSet + localPlayer->getAnim();
anim = animSet + localPlayer->getAnim();
anim->disableYOffset();
anim->setFrame(ticks / 75, true);
anim->draw(ITOF((canvasW - anim->getWidth()) >> 1), ITOF(canvasH - anim->getHeight() - 28));
......
......@@ -29,6 +29,7 @@
Anim::Anim () {
frame = 0;
ignoreDefaultYOffset = false;
return;
......@@ -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;
shootX = sX;
shootY = sY;
xOffset = x;
accessoryX = aX;
accessoryY = aY;
accessory = a;
yOffset = y;
return;
......@@ -92,7 +95,7 @@ int Anim::getHeight () {
fixed Anim::getShootX () {
return ITOF(shootX + xOffsets[frame] - xOffset);
return ITOF(shootX + xOffsets[frame]);
}
......@@ -106,14 +109,45 @@ fixed Anim::getShootY () {
void Anim::draw (fixed x, fixed y) {
sprites[frame]->draw(FTOI(x) + xOffsets[frame] - xOffset,
FTOI(y) + yOffsets[frame] - yOffset);
// In case yOffset is zero, and the ignore default offset flag is set,
// 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;
}
void Anim::disableYOffset() {
ignoreDefaultYOffset = true;
}
void Anim::copyYOffset(Anim *anim) {
yOffset = anim->yOffset;
}
void Anim::setPalette (SDL_Color *palette, int start, int amount) {
sprites[frame]->setPalette(palette, 0, 256);
......
......@@ -37,20 +37,24 @@ class Anim {
private:
Sprite *sprites[19];
bool ignoreDefaultYOffset;
signed char shootX;
signed char shootY;
signed char xOffset;
signed char accessoryX;
signed char accessoryY;
signed char yOffset;
signed char xOffsets[19];
signed char yOffsets[19];
unsigned char frames; // Number of frames
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:
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 setFrameData (Sprite *frameSprite, signed char x, signed char y);
int getWidth ();
......@@ -58,6 +62,8 @@ class Anim {
fixed getShootX ();
fixed getShootY ();
void draw (fixed x, fixed y);
void copyYOffset (Anim *anim);
void disableYOffset ();
void setPalette (SDL_Color *palette, int start, int amount);
void flashPalette (int index);
void restorePalette ();
......
......@@ -48,6 +48,10 @@ Bridge::Bridge (unsigned char gX, unsigned char gY) {
animType = E_LEFTANIM;
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
// Start with minimum values
leftDipX = set[E_MULTIPURPOSE] * set[E_BRIDGELENGTH] * F4;
......
......@@ -60,8 +60,19 @@ Event::Event (unsigned char gX, unsigned char gY) {
gridY = gY;
flashTime = 0;
Anim *leftAnim = getAnim(E_LEFTANIM);
Anim *rightAnim = getAnim(E_RIGHTANIM);
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 25: // Float up / Belt
case 37: // Sucker tubes
......@@ -76,6 +87,7 @@ Event::Event (unsigned char gX, unsigned char gY) {
case 26: // Flip animation
animType = E_RIGHTANIM;
rightAnim->copyYOffset(leftAnim);
break;
......@@ -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 @@
#include "movable.h"
#include "OpenJazz.h"
#include "../../io/gfx/anim.h"
// Constants
......@@ -104,6 +105,7 @@ class Event : public Movable {
bool isFrom (unsigned char gX, unsigned char gY);
virtual bool overlap (fixed left, fixed top, fixed width, fixed height);
signed char getProperty (unsigned char property);
Anim* getAnim (unsigned char property);
virtual Event* step (unsigned int ticks, int msps);
virtual void draw (unsigned int ticks, int change);
void drawEnergy (unsigned int ticks);
......
......@@ -656,7 +656,8 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) {
animSet[count].setData(buffer[(count << 6) + 6],
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++) {
......
......@@ -815,6 +815,7 @@ void Player::draw (unsigned int ticks, int change) {
yOffset = fCos(ticks * 2) * 12;
an = level->getMiscAnim(0);
an->disableYOffset();
an->setFrame(frame, true);
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