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 () { ...@@ -631,7 +631,7 @@ void Bonus::draw () {
// Show the player // Show the player
anim = animSet + localPlayer->getAnim(); anim = animSet + localPlayer->getAnim();
anim->disableYOffset(); anim->disableDefaultOffset();
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));
......
...@@ -107,6 +107,13 @@ fixed Anim::getShootY () { ...@@ -107,6 +107,13 @@ fixed Anim::getShootY () {
} }
fixed Anim::getOffset () {
return ITOF(yOffset);
}
void Anim::draw (fixed x, fixed y) { void Anim::draw (fixed x, fixed y) {
// In case yOffset is zero, and the ignore default offset flag is set, // In case yOffset is zero, and the ignore default offset flag is set,
...@@ -134,20 +141,13 @@ void Anim::draw (fixed x, fixed y) { ...@@ -134,20 +141,13 @@ void Anim::draw (fixed x, fixed y) {
} }
void Anim::disableYOffset() { void Anim::disableDefaultOffset() {
ignoreDefaultYOffset = true; 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);
......
...@@ -61,9 +61,9 @@ class Anim { ...@@ -61,9 +61,9 @@ class Anim {
int getHeight (); int getHeight ();
fixed getShootX (); fixed getShootX ();
fixed getShootY (); fixed getShootY ();
fixed getOffset ();
void draw (fixed x, fixed y); void draw (fixed x, fixed y);
void copyYOffset (Anim *anim); void disableDefaultOffset ();
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 ();
......
...@@ -49,8 +49,7 @@ Bridge::Bridge (unsigned char gX, unsigned char gY) { ...@@ -49,8 +49,7 @@ Bridge::Bridge (unsigned char gX, unsigned char gY) {
flashTime = 0; flashTime = 0;
// Bridges should ignore the default yOffsets // Bridges should ignore the default yOffsets
getAnim(E_LEFTANIM)->disableYOffset(); noOffset(true);
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
...@@ -155,11 +154,11 @@ void Bridge::draw (unsigned int ticks, int change) { ...@@ -155,11 +154,11 @@ void Bridge::draw (unsigned int ticks, int change) {
for (count = 0; count < bridgeLength; count += F4 * set[E_BRIDGELENGTH]) { for (count = 0; count < bridgeLength; count += F4 * set[E_BRIDGELENGTH]) {
if (count < leftDipX) 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) 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 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) { ...@@ -176,9 +175,9 @@ void Bridge::draw (unsigned int ticks, int change) {
for (count = 0; count < bridgeLength; count += F4 * set[E_BRIDGELENGTH]) { for (count = 0; count < bridgeLength; count += F4 * set[E_BRIDGELENGTH]) {
if (count < leftDipY) 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 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) { ...@@ -60,8 +60,10 @@ Event::Event (unsigned char gX, unsigned char gY) {
gridY = gY; gridY = gY;
flashTime = 0; flashTime = 0;
Anim *leftAnim = getAnim(E_LEFTANIM); onlyLAnimOffset = false;
Anim *rightAnim = getAnim(E_RIGHTANIM); onlyRAnimOffset = false;
noAnimOffset = false;
extraOffset = 0;
switch (getProperty(E_BEHAVIOUR)) { switch (getProperty(E_BEHAVIOUR)) {
...@@ -69,7 +71,15 @@ Event::Event (unsigned char gX, unsigned char gY) { ...@@ -69,7 +71,15 @@ Event::Event (unsigned char gX, unsigned char gY) {
case 4: // Walk from side to side and down hills case 4: // Walk from side to side and down hills
animType = E_LEFTANIM; 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; break;
...@@ -87,7 +97,7 @@ Event::Event (unsigned char gX, unsigned char gY) { ...@@ -87,7 +97,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); onlyLeftAnimOffset(true);
break; break;
...@@ -224,7 +234,8 @@ fixed Event::getHeight () { ...@@ -224,7 +234,8 @@ fixed Event::getHeight () {
bool Event::overlap (fixed left, fixed top, fixed width, fixed height) { bool Event::overlap (fixed left, fixed top, fixed width, fixed height) {
return (x + getWidth() >= left) && (x < left + width) && 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) { ...@@ -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) { switch (property) {
...@@ -263,3 +274,12 @@ Anim* Event::getAnim(unsigned char property) { ...@@ -263,3 +274,12 @@ Anim* Event::getAnim(unsigned char property) {
} }
void Event::setExtraOffset (fixed offset) {
extraOffset = offset;
}
...@@ -86,6 +86,10 @@ class Event : public Movable { ...@@ -86,6 +86,10 @@ class Event : public Movable {
unsigned char animType; // E_LEFTANIM, etc, or 0 unsigned char animType; // E_LEFTANIM, etc, or 0
unsigned char frame; unsigned char frame;
unsigned int flashTime; unsigned int flashTime;
bool onlyLAnimOffset;
bool onlyRAnimOffset;
bool noAnimOffset;
fixed extraOffset;
Event (); Event ();
...@@ -94,6 +98,10 @@ class Event : public Movable { ...@@ -94,6 +98,10 @@ class Event : public Movable {
fixed getWidth (); fixed getWidth ();
fixed getHeight (); fixed getHeight ();
signed char* prepareStep (unsigned int ticks, int msps); 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: public:
Event (unsigned char gX, unsigned char gY); Event (unsigned char gX, unsigned char gY);
......
...@@ -881,7 +881,7 @@ Event* Event::step (unsigned int ticks, int msps) { ...@@ -881,7 +881,7 @@ Event* Event::step (unsigned int ticks, int msps) {
if (set[E_MODIFIER] == 6) { if (set[E_MODIFIER] == 6) {
if (width && height && 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) && (players[count].getY() <= F8 + ((PYS_FALL * msps) >> 10) + y - height) &&
!level->checkMaskDown(players[count].getX() + PXO_MID, PYO_TOP + 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) { ...@@ -898,7 +898,7 @@ Event* Event::step (unsigned int ticks, int msps) {
// Check if the player is touching the event // Check if the player is touching the event
if (width && height && 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 the player picks up the event, destroy it
if (players[count].touchEvent(gridX, gridY, ticks, msps)) if (players[count].touchEvent(gridX, gridY, ticks, msps))
...@@ -953,11 +953,26 @@ void Event::draw (unsigned int ticks, int change) { ...@@ -953,11 +953,26 @@ void Event::draw (unsigned int ticks, int change) {
anim->setFrame(frame + gridX + gridY, true); anim->setFrame(frame + gridX + gridY, true);
if (ticks < flashTime) anim->flashPalette(0);
// Draw the event // 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(); if (ticks < flashTime) anim->restorePalette();
...@@ -1020,3 +1035,30 @@ void Event::drawEnergy (unsigned int ticks) { ...@@ -1020,3 +1035,30 @@ void Event::drawEnergy (unsigned int ticks) {
} }
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) { ...@@ -607,8 +607,8 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) {
for (count = 0; count < path[type].length; count++) { for (count = 0; count < path[type].length; count++) {
path[type].x[count] = ((signed char *)buffer)[(type << 9) + (count << 1) + 3] << 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] << 2; path[type].y[count] = ((signed char *)buffer)[(type << 9) + (count << 1) + 2];
} }
......
...@@ -815,7 +815,7 @@ void Player::draw (unsigned int ticks, int change) { ...@@ -815,7 +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->disableDefaultOffset();
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