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) {
flashTime = 0;
// Bridges should ignore the default yOffsets
noOffset(true);
dontUseAnimOffset(true);
// leftDipX and rightDipX used to store leftmost and rightmost player on bridge
// Start with minimum values
......
......@@ -40,6 +40,8 @@
#include "io/sound.h"
#include "player/player.h"
#include "util.h"
Event::Event () {
......@@ -62,8 +64,7 @@ Event::Event (unsigned char gX, unsigned char gY) {
onlyLAnimOffset = false;
onlyRAnimOffset = false;
noAnimOffset = false;
extraOffset = 0;
disableAnimOffset = false;
switch (getProperty(E_BEHAVIOUR)) {
......@@ -71,15 +72,15 @@ Event::Event (unsigned char gX, unsigned char gY) {
case 4: // Walk from side to side and down hills
animType = E_LEFTANIM;
onlyRightAnimOffset(true);
useRightAnimOffset(true);
break;
case 6: // Use the path from the level file
case 7: // Flying snake behavior
animType = E_LEFTANIM;
setExtraOffset(ITOF(40));
onlyLeftAnimOffset(true);
dontUseAnimOffset(true);
break;
......@@ -97,7 +98,7 @@ Event::Event (unsigned char gX, unsigned char gY) {
case 26: // Flip animation
animType = E_RIGHTANIM;
onlyLeftAnimOffset(true);
useLeftAnimOffset(true);
break;
......@@ -233,9 +234,10 @@ fixed Event::getHeight () {
bool Event::overlap (fixed left, fixed top, fixed width, fixed height) {
return (x + getWidth() >= left) && (x < left + width) &&
(y + extraOffset >= top) &&
(y + extraOffset - getHeight() < top + height);
return (x + getWidth() >= left) &&
(x < left + width) &&
(y >= top) &&
(y - getHeight() < top + height);
}
......@@ -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 {
unsigned int flashTime;
bool onlyLAnimOffset;
bool onlyRAnimOffset;
bool noAnimOffset;
fixed extraOffset;
bool disableAnimOffset;
Event ();
......@@ -99,10 +98,9 @@ class Event : public Movable {
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);
void useLeftAnimOffset (bool enable);
void useRightAnimOffset (bool enable);
void dontUseAnimOffset (bool enable);
public:
Event (unsigned char gX, unsigned char gY);
......
......@@ -164,8 +164,9 @@ Event* Event::step (unsigned int ticks, int msps) {
case 6:
// 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;
dy = TTOF(gridY) + (level->path[set[E_MULTIPURPOSE]].y[level->path[set[E_MULTIPURPOSE]].node] << 9) - y;
dx = TTOF(gridX) + ITOF(level->path[set[E_MULTIPURPOSE]].x[level->path[set[E_MULTIPURPOSE]].node]) - x;
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];
dy = ((dy << 10) / msps) * set[E_MOVEMENTSP];
......@@ -543,7 +544,6 @@ Event* Event::step (unsigned int ticks, int msps) {
x += (dx * msps) >> 10;
y += (dy * msps) >> 10;
// Choose animation and direction
if ((animType == E_LEFTANIM) || (animType == E_RIGHTANIM)) {
......@@ -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
// reaction time
if (set[E_HITSTOKILL] &&
......@@ -886,7 +885,7 @@ Event* Event::step (unsigned int ticks, int msps) {
if (set[E_MODIFIER] == 6) {
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) &&
!level->checkMaskDown(levelPlayer->getX() + PXO_MID, PYO_TOP + y - height)) {
......@@ -901,7 +900,7 @@ Event* Event::step (unsigned int ticks, int msps) {
// Check if the player is touching the event
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 (levelPlayer->touchEvent(gridX, gridY, ticks, msps))
......@@ -958,12 +957,11 @@ void Event::draw (unsigned int ticks, int change) {
if (ticks < flashTime) anim->flashPalette(0);
// Draw the event
// Correct the position without altering the animation
fixed changeX = getDrawX(change);
fixed changeY = getDrawY(change);
// Correct the position without altering the animation
if (noAnimOffset)
if (disableAnimOffset)
changeY += anim->getOffset();
if (onlyLAnimOffset && animType == E_RIGHTANIM) {
......@@ -975,7 +973,9 @@ void Event::draw (unsigned int ticks, int change) {
changeY -= getAnim(E_RIGHTANIM)->getOffset();
}
anim->draw(changeX, changeY + extraOffset);
// Draw the event
anim->draw(changeX, changeY);
if (ticks < flashTime) anim->restorePalette();
......@@ -986,7 +986,7 @@ void Event::draw (unsigned int ticks, int change) {
anim = level->getMiscAnim(2);
anim->setFrame(frame, false);
anim->draw(getDrawX(change), getDrawY(change));
anim->draw(changeX, changeY);
}
......@@ -1038,7 +1038,7 @@ void Event::drawEnergy (unsigned int ticks) {
}
void Event::onlyLeftAnimOffset(bool enable) {
void Event::useLeftAnimOffset(bool enable) {
onlyLAnimOffset = enable;
......@@ -1047,7 +1047,7 @@ void Event::onlyLeftAnimOffset(bool enable) {
}
void Event::onlyRightAnimOffset(bool enable) {
void Event::useRightAnimOffset(bool enable) {
onlyRAnimOffset = 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;
}
......@@ -608,7 +608,7 @@ 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] << 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];
}
......
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