Commit 49cf32fa authored by newspaz's avatar newspaz

Tons of changes to correct the position of event animations in a slightly...

Tons of changes to correct the position of event animations in a slightly prettier way than the previous way.
This time the offsets within animations aren't changed. Instead the offsets are changed for each event.

bonus.cpp
*) Changed the method call that disables a default animation offset.

anim.cpp, anim.h
*) Removed method to copy offsets.
*) Refactored method name for the method that disables a default animation offset.

levelload.h
*) Changed the enemy path loading

bridge.cpp, event.cpp, eventframe.cpp, event.h
*) Changed method calls that happen with certain behaviors
*) Added an extra offset that can be set to correct positons.

playerframe.cpp
*) Changed code to understand the extra offset
parent 989fb4dd
......@@ -631,7 +631,7 @@ void Bonus::draw () {
// Show the player
anim = animSet + localPlayer->getAnim();
anim->disableYOffset();
anim->disableDefaultOffset();
anim->setFrame(ticks / 75, true);
anim->draw(ITOF((canvasW - anim->getWidth()) >> 1), ITOF(canvasH - anim->getHeight() - 28));
......
......@@ -107,6 +107,13 @@ fixed Anim::getShootY () {
}
fixed Anim::getOffset () {
return ITOF(yOffset);
}
void Anim::draw (fixed x, fixed y) {
// In case yOffset is zero, and the ignore default offset flag is set,
......@@ -134,20 +141,13 @@ void Anim::draw (fixed x, fixed y) {
}
void Anim::disableYOffset() {
void Anim::disableDefaultOffset() {
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);
......
......@@ -51,22 +51,22 @@ class Anim {
// Most of the time accessories are used with guardians.
public:
Anim ();
~Anim ();
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 ();
int getHeight ();
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 ();
Anim ();
~Anim ();
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 ();
int getHeight ();
fixed getShootX ();
fixed getShootY ();
fixed getOffset ();
void draw (fixed x, fixed y);
void disableDefaultOffset ();
void setPalette (SDL_Color *palette, int start, int amount);
void flashPalette (int index);
void restorePalette ();
};
......
......@@ -49,8 +49,7 @@ Bridge::Bridge (unsigned char gX, unsigned char gY) {
flashTime = 0;
// Bridges should ignore the default yOffsets
getAnim(E_LEFTANIM)->disableYOffset();
getAnim(E_RIGHTANIM)->disableYOffset();
noOffset(true);
// leftDipX and rightDipX used to store leftmost and rightmost player on bridge
// Start with minimum values
......@@ -155,11 +154,11 @@ void Bridge::draw (unsigned int ticks, int change) {
for (count = 0; count < bridgeLength; count += F4 * set[E_BRIDGELENGTH]) {
if (count < leftDipX)
anim->draw(getDrawX(change) + count, getDrawY(change) + (count * leftDipY / leftDipX));
anim->draw(getDrawX(change) + count, getDrawY(change) + TTOF(1) + (count * leftDipY / leftDipX));
else if (count < dy)
anim->draw(getDrawX(change) + count, getDrawY(change) + leftDipY + ((count - leftDipX) * (rightDipY - leftDipY) / (rightDipX - leftDipX)));
anim->draw(getDrawX(change) + count, getDrawY(change) + TTOF(1) + leftDipY + ((count - leftDipX) * (rightDipY - leftDipY) / (rightDipX - leftDipX)));
else
anim->draw(getDrawX(change) + count, getDrawY(change) + ((bridgeLength - count) * rightDipY / (bridgeLength - rightDipX)));
anim->draw(getDrawX(change) + count, getDrawY(change) + TTOF(1) + ((bridgeLength - count) * rightDipY / (bridgeLength - rightDipX)));
}
......@@ -176,9 +175,9 @@ void Bridge::draw (unsigned int ticks, int change) {
for (count = 0; count < bridgeLength; count += F4 * set[E_BRIDGELENGTH]) {
if (count < leftDipY)
anim->draw(getDrawX(change) + count, getDrawY(change) + (count * rightDipY / leftDipY));
anim->draw(getDrawX(change) + count, getDrawY(change) + TTOF(1) + (count * rightDipY / leftDipY));
else
anim->draw(getDrawX(change) + count, getDrawY(change) + ((bridgeLength - count) * rightDipY / (bridgeLength - leftDipY)));
anim->draw(getDrawX(change) + count, getDrawY(change) + TTOF(1) + ((bridgeLength - count) * rightDipY / (bridgeLength - leftDipY)));
}
......
......@@ -60,8 +60,10 @@ Event::Event (unsigned char gX, unsigned char gY) {
gridY = gY;
flashTime = 0;
Anim *leftAnim = getAnim(E_LEFTANIM);
Anim *rightAnim = getAnim(E_RIGHTANIM);
onlyLAnimOffset = false;
onlyRAnimOffset = false;
noAnimOffset = false;
extraOffset = 0;
switch (getProperty(E_BEHAVIOUR)) {
......@@ -69,7 +71,15 @@ Event::Event (unsigned char gX, unsigned char gY) {
case 4: // Walk from side to side and down hills
animType = E_LEFTANIM;
leftAnim->copyYOffset(rightAnim);
onlyRightAnimOffset(true);
break;
case 6: // Use the path from the level file
animType = E_LEFTANIM;
setExtraOffset(ITOF(40));
onlyLeftAnimOffset(true);
break;
......@@ -87,7 +97,7 @@ Event::Event (unsigned char gX, unsigned char gY) {
case 26: // Flip animation
animType = E_RIGHTANIM;
rightAnim->copyYOffset(leftAnim);
onlyLeftAnimOffset(true);
break;
......@@ -224,7 +234,8 @@ fixed Event::getHeight () {
bool Event::overlap (fixed left, fixed top, fixed width, fixed height) {
return (x + getWidth() >= left) && (x < left + width) &&
(y >= top) && (y - getHeight() < top + height);
(y + extraOffset >= top) &&
(y + extraOffset - getHeight() < top + height);
}
......@@ -242,7 +253,7 @@ signed char Event::getProperty (unsigned char property) {
}
Anim* Event::getAnim(unsigned char property) {
Anim* Event::getAnim (unsigned char property) {
switch (property) {
......@@ -263,3 +274,12 @@ Anim* Event::getAnim(unsigned char property) {
}
void Event::setExtraOffset (fixed offset) {
extraOffset = offset;
}
......@@ -86,29 +86,37 @@ class Event : public Movable {
unsigned char animType; // E_LEFTANIM, etc, or 0
unsigned char frame;
unsigned int flashTime;
bool onlyLAnimOffset;
bool onlyRAnimOffset;
bool noAnimOffset;
fixed extraOffset;
Event ();
Event* remove ();
void destroy (unsigned int ticks);
fixed getWidth ();
fixed getHeight ();
signed char* prepareStep (unsigned int ticks, int msps);
Event* remove ();
void destroy (unsigned int ticks);
fixed getWidth ();
fixed getHeight ();
signed char* prepareStep (unsigned int ticks, int msps);
void onlyLeftAnimOffset (bool enable);
void onlyRightAnimOffset (bool enable);
void noOffset (bool enable);
void setExtraOffset (fixed offset);
public:
Event (unsigned char gX, unsigned char gY);
virtual ~Event ();
Event* getNext ();
bool hit (Player *source, unsigned int ticks);
bool isEnemy ();
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);
Event* getNext ();
bool hit (Player *source, unsigned int ticks);
bool isEnemy ();
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);
};
......
......@@ -881,7 +881,7 @@ Event* Event::step (unsigned int ticks, int msps) {
if (set[E_MODIFIER] == 6) {
if (width && height &&
players[count].overlap(x, y - height, width - F8, F8) &&
players[count].overlap(x, y + extraOffset - height, width - F8, F8) &&
(players[count].getY() <= F8 + ((PYS_FALL * msps) >> 10) + y - height) &&
!level->checkMaskDown(players[count].getX() + PXO_MID, PYO_TOP + y - height)) {
......@@ -898,7 +898,7 @@ Event* Event::step (unsigned int ticks, int msps) {
// Check if the player is touching the event
if (width && height &&
players[count].overlap(x, y - height, width, height)) {
players[count].overlap(x, y + extraOffset - height, width, height)) {
// If the player picks up the event, destroy it
if (players[count].touchEvent(gridX, gridY, ticks, msps))
......@@ -953,11 +953,26 @@ void Event::draw (unsigned int ticks, int change) {
anim->setFrame(frame + gridX + gridY, true);
if (ticks < flashTime) anim->flashPalette(0);
// Draw the event
fixed changeX = getDrawX(change);
fixed changeY = getDrawY(change);
if (ticks < flashTime) anim->flashPalette(0);
// Correct the position without altering the animation
if (noAnimOffset)
changeY += anim->getOffset();
anim->draw(getDrawX(change), getDrawY(change));
if (onlyLAnimOffset && animType == E_RIGHTANIM) {
changeY += anim->getOffset();
changeY -= getAnim(E_LEFTANIM)->getOffset();
}
if (onlyRAnimOffset && animType == E_LEFTANIM) {
changeY += anim->getOffset();
changeY -= getAnim(E_RIGHTANIM)->getOffset();
}
anim->draw(changeX, changeY + extraOffset);
if (ticks < flashTime) anim->restorePalette();
......@@ -1017,6 +1032,33 @@ void Event::drawEnergy (unsigned int ticks) {
return;
}
void Event::onlyLeftAnimOffset(bool enable) {
onlyLAnimOffset = enable;
return;
}
void Event::onlyRightAnimOffset(bool enable) {
onlyRAnimOffset = enable;
return;
}
void Event::noOffset(bool enable) {
noAnimOffset = enable;
return;
}
......@@ -607,8 +607,8 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) {
for (count = 0; count < path[type].length; count++) {
path[type].x[count] = ((signed char *)buffer)[(type << 9) + (count << 1) + 3] << 2;
path[type].y[count] = ((signed char *)buffer)[(type << 9) + (count << 1) + 2] << 2;
path[type].x[count] = ((signed char *)buffer)[(type << 9) + (count << 1) + 3] << 3;
path[type].y[count] = ((signed char *)buffer)[(type << 9) + (count << 1) + 2];
}
......
......@@ -815,7 +815,7 @@ void Player::draw (unsigned int ticks, int change) {
yOffset = fCos(ticks * 2) * 12;
an = level->getMiscAnim(0);
an->disableYOffset();
an->disableDefaultOffset();
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