Commit ebae1e52 authored by newspaz's avatar newspaz

Various changes to correct the positioning of special behaviors. This time the...

Various changes to correct the positioning of special behaviors. This time the fix is actually performed properly ;-).

levelload.cpp
*) Undid a change I made earlier. I changed << 2 into << 3, but it turns out I was wrong. This seemed to work due to a bug in eventframe.cpp.

bridge.cpp
*) Removed one tile from the default offset value for bridges

event.h, event.cpp, event.cpp
*) Removed the extraOffset variable I added earlier. It turned out this was totally unneeded.
*) Fixed the way X and Y positions in the viewport were determined. It's a lot simpler now, and I wonder why the previous version was so complicated.
*) More changes to get rid of the extraOffset variable.
parent 44f0912e
...@@ -49,7 +49,7 @@ Bridge::Bridge (unsigned char gX, unsigned char gY) { ...@@ -49,7 +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
noOffset(true); dontUseAnimOffset(true);
// 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
......
...@@ -40,6 +40,8 @@ ...@@ -40,6 +40,8 @@
#include "io/sound.h" #include "io/sound.h"
#include "player/player.h" #include "player/player.h"
#include "util.h"
Event::Event () { Event::Event () {
...@@ -62,8 +64,7 @@ Event::Event (unsigned char gX, unsigned char gY) { ...@@ -62,8 +64,7 @@ Event::Event (unsigned char gX, unsigned char gY) {
onlyLAnimOffset = false; onlyLAnimOffset = false;
onlyRAnimOffset = false; onlyRAnimOffset = false;
noAnimOffset = false; disableAnimOffset = false;
extraOffset = 0;
switch (getProperty(E_BEHAVIOUR)) { switch (getProperty(E_BEHAVIOUR)) {
...@@ -71,15 +72,15 @@ Event::Event (unsigned char gX, unsigned char gY) { ...@@ -71,15 +72,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;
onlyRightAnimOffset(true); useRightAnimOffset(true);
break; break;
case 6: // Use the path from the level file case 6: // Use the path from the level file
case 7: // Flying snake behavior
animType = E_LEFTANIM; animType = E_LEFTANIM;
setExtraOffset(ITOF(40)); dontUseAnimOffset(true);
onlyLeftAnimOffset(true);
break; break;
...@@ -97,7 +98,7 @@ Event::Event (unsigned char gX, unsigned char gY) { ...@@ -97,7 +98,7 @@ Event::Event (unsigned char gX, unsigned char gY) {
case 26: // Flip animation case 26: // Flip animation
animType = E_RIGHTANIM; animType = E_RIGHTANIM;
onlyLeftAnimOffset(true); useLeftAnimOffset(true);
break; break;
...@@ -233,9 +234,10 @@ fixed Event::getHeight () { ...@@ -233,9 +234,10 @@ 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) &&
(y + extraOffset >= top) && (x < left + width) &&
(y + extraOffset - getHeight() < top + height); (y >= top) &&
(y - getHeight() < top + height);
} }
...@@ -275,11 +277,4 @@ Anim* Event::getAnim (unsigned char property) { ...@@ -275,11 +277,4 @@ Anim* Event::getAnim (unsigned char property) {
} }
void Event::setExtraOffset (fixed offset) {
extraOffset = offset;
}
...@@ -89,8 +89,7 @@ class Event : public Movable { ...@@ -89,8 +89,7 @@ class Event : public Movable {
unsigned int flashTime; unsigned int flashTime;
bool onlyLAnimOffset; bool onlyLAnimOffset;
bool onlyRAnimOffset; bool onlyRAnimOffset;
bool noAnimOffset; bool disableAnimOffset;
fixed extraOffset;
Event (); Event ();
...@@ -99,10 +98,9 @@ class Event : public Movable { ...@@ -99,10 +98,9 @@ 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 useLeftAnimOffset (bool enable);
void onlyRightAnimOffset (bool enable); void useRightAnimOffset (bool enable);
void noOffset (bool enable); void dontUseAnimOffset (bool enable);
void setExtraOffset (fixed offset);
public: public:
Event (unsigned char gX, unsigned char gY); Event (unsigned char gX, unsigned char gY);
......
...@@ -164,8 +164,9 @@ Event* Event::step (unsigned int ticks, int msps) { ...@@ -164,8 +164,9 @@ Event* Event::step (unsigned int ticks, int msps) {
case 6: case 6:
// Use the path from the level file // Use the path from the level file
dx = TTOF(gridX) + F16 + (level->path[set[E_MULTIPURPOSE]].x[level->path[set[E_MULTIPURPOSE]].node] << 9) - x; dx = TTOF(gridX) + ITOF(level->path[set[E_MULTIPURPOSE]].x[level->path[set[E_MULTIPURPOSE]].node]) - x;
dy = TTOF(gridY) + (level->path[set[E_MULTIPURPOSE]].y[level->path[set[E_MULTIPURPOSE]].node] << 9) - y; dy = TTOF(gridY) + ITOF(level->path[set[E_MULTIPURPOSE]].y[level->path[set[E_MULTIPURPOSE]].node]) - y + TTOF(1);
dx = ((dx << 10) / msps) * set[E_MOVEMENTSP]; dx = ((dx << 10) / msps) * set[E_MOVEMENTSP];
dy = ((dy << 10) / msps) * set[E_MOVEMENTSP]; dy = ((dy << 10) / msps) * set[E_MOVEMENTSP];
...@@ -543,7 +544,6 @@ Event* Event::step (unsigned int ticks, int msps) { ...@@ -543,7 +544,6 @@ Event* Event::step (unsigned int ticks, int msps) {
x += (dx * msps) >> 10; x += (dx * msps) >> 10;
y += (dy * msps) >> 10; y += (dy * msps) >> 10;
// Choose animation and direction // Choose animation and direction
if ((animType == E_LEFTANIM) || (animType == E_RIGHTANIM)) { if ((animType == E_LEFTANIM) || (animType == E_RIGHTANIM)) {
...@@ -806,7 +806,6 @@ Event* Event::step (unsigned int ticks, int msps) { ...@@ -806,7 +806,6 @@ Event* Event::step (unsigned int ticks, int msps) {
} }
// If the event has been destroyed, play its finishing animation and set its // If the event has been destroyed, play its finishing animation and set its
// reaction time // reaction time
if (set[E_HITSTOKILL] && if (set[E_HITSTOKILL] &&
...@@ -886,7 +885,7 @@ Event* Event::step (unsigned int ticks, int msps) { ...@@ -886,7 +885,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 &&
levelPlayer->overlap(x, y + extraOffset - height, width - F8, F8) && levelPlayer->overlap(x, y - height, width - F8, F8) &&
(levelPlayer->getY() <= F8 + ((PYS_FALL * msps) >> 10) + y - height) && (levelPlayer->getY() <= F8 + ((PYS_FALL * msps) >> 10) + y - height) &&
!level->checkMaskDown(levelPlayer->getX() + PXO_MID, PYO_TOP + y - height)) { !level->checkMaskDown(levelPlayer->getX() + PXO_MID, PYO_TOP + y - height)) {
...@@ -901,7 +900,7 @@ Event* Event::step (unsigned int ticks, int msps) { ...@@ -901,7 +900,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 &&
levelPlayer->overlap(x, y + extraOffset - height, width, height)) { levelPlayer->overlap(x, y - height, width, height)) {
// If the player picks up the event, destroy it // If the player picks up the event, destroy it
if (levelPlayer->touchEvent(gridX, gridY, ticks, msps)) if (levelPlayer->touchEvent(gridX, gridY, ticks, msps))
...@@ -958,12 +957,11 @@ void Event::draw (unsigned int ticks, int change) { ...@@ -958,12 +957,11 @@ void Event::draw (unsigned int ticks, int change) {
if (ticks < flashTime) anim->flashPalette(0); if (ticks < flashTime) anim->flashPalette(0);
// Draw the event // Correct the position without altering the animation
fixed changeX = getDrawX(change); fixed changeX = getDrawX(change);
fixed changeY = getDrawY(change); fixed changeY = getDrawY(change);
// Correct the position without altering the animation if (disableAnimOffset)
if (noAnimOffset)
changeY += anim->getOffset(); changeY += anim->getOffset();
if (onlyLAnimOffset && animType == E_RIGHTANIM) { if (onlyLAnimOffset && animType == E_RIGHTANIM) {
...@@ -975,7 +973,9 @@ void Event::draw (unsigned int ticks, int change) { ...@@ -975,7 +973,9 @@ void Event::draw (unsigned int ticks, int change) {
changeY -= getAnim(E_RIGHTANIM)->getOffset(); changeY -= getAnim(E_RIGHTANIM)->getOffset();
} }
anim->draw(changeX, changeY + extraOffset); // Draw the event
anim->draw(changeX, changeY);
if (ticks < flashTime) anim->restorePalette(); if (ticks < flashTime) anim->restorePalette();
...@@ -986,7 +986,7 @@ void Event::draw (unsigned int ticks, int change) { ...@@ -986,7 +986,7 @@ void Event::draw (unsigned int ticks, int change) {
anim = level->getMiscAnim(2); anim = level->getMiscAnim(2);
anim->setFrame(frame, false); anim->setFrame(frame, false);
anim->draw(getDrawX(change), getDrawY(change)); anim->draw(changeX, changeY);
} }
...@@ -1038,7 +1038,7 @@ void Event::drawEnergy (unsigned int ticks) { ...@@ -1038,7 +1038,7 @@ void Event::drawEnergy (unsigned int ticks) {
} }
void Event::onlyLeftAnimOffset(bool enable) { void Event::useLeftAnimOffset(bool enable) {
onlyLAnimOffset = enable; onlyLAnimOffset = enable;
...@@ -1047,7 +1047,7 @@ void Event::onlyLeftAnimOffset(bool enable) { ...@@ -1047,7 +1047,7 @@ void Event::onlyLeftAnimOffset(bool enable) {
} }
void Event::onlyRightAnimOffset(bool enable) { void Event::useRightAnimOffset(bool enable) {
onlyRAnimOffset = enable; onlyRAnimOffset = enable;
...@@ -1056,12 +1056,10 @@ void Event::onlyRightAnimOffset(bool enable) { ...@@ -1056,12 +1056,10 @@ void Event::onlyRightAnimOffset(bool enable) {
} }
void Event::noOffset(bool enable) { void Event::dontUseAnimOffset(bool enable) {
noAnimOffset = enable; disableAnimOffset = enable;
return; return;
} }
...@@ -608,7 +608,7 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) { ...@@ -608,7 +608,7 @@ 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] << 3; 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]; path[type].y[count] = ((signed char *)buffer)[(type << 9) + (count << 1) + 2];
} }
......
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