Commit 1383f928 authored by newspaz's avatar newspaz

Okay, with this update I am going to declare special behaviors fixed. Even...

Okay, with this update I am going to declare special behaviors fixed. Even though you might not believe me, because this is the fourth time I am making such a claim. This time I'm dangerously close to what the real game does ;-)

anim.cpp
*) Changed the getOffset accessor to add the default 32 pixel offset if it should be there.

bridge.cpp
*) Because of the change in anim.cpp I could remove the default 32 pixel offset I added earlier.

event.h, event.cpp
*) Changed the overlap method to include the offset if necessary.

eventframe.cpp
*) Changed the step method and removed the default 32 pixel offset I added earlier.
*) Changed the draw method slightly so when offsets should be ignored, that actually is the case.

parent eadb31ed
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
Anim::Anim () { Anim::Anim () {
frame = 0; frame = 0;
yOffset = 0;
ignoreDefaultYOffset = false; ignoreDefaultYOffset = false;
return; return;
...@@ -109,6 +110,9 @@ fixed Anim::getShootY () { ...@@ -109,6 +110,9 @@ fixed Anim::getShootY () {
fixed Anim::getOffset () { fixed Anim::getOffset () {
if (!ignoreDefaultYOffset && yOffset == 0)
return ITOF(yOffset) + TTOF(1);
return ITOF(yOffset); return ITOF(yOffset);
} }
......
...@@ -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
dontUseAnimOffset(true); dontUseAnimOffset();
// 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
......
...@@ -64,7 +64,7 @@ Event::Event (unsigned char gX, unsigned char gY) { ...@@ -64,7 +64,7 @@ Event::Event (unsigned char gX, unsigned char gY) {
onlyLAnimOffset = false; onlyLAnimOffset = false;
onlyRAnimOffset = false; onlyRAnimOffset = false;
disableAnimOffset = false; noAnimOffset = false;
switch (getProperty(E_BEHAVIOUR)) { switch (getProperty(E_BEHAVIOUR)) {
...@@ -72,7 +72,7 @@ Event::Event (unsigned char gX, unsigned char gY) { ...@@ -72,7 +72,7 @@ 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;
useRightAnimOffset(true); useRightAnimOffset();
break; break;
...@@ -80,7 +80,7 @@ Event::Event (unsigned char gX, unsigned char gY) { ...@@ -80,7 +80,7 @@ Event::Event (unsigned char gX, unsigned char gY) {
case 7: // Flying snake behavior case 7: // Flying snake behavior
animType = E_LEFTANIM; animType = E_LEFTANIM;
dontUseAnimOffset(true); dontUseAnimOffset();
break; break;
...@@ -98,7 +98,7 @@ Event::Event (unsigned char gX, unsigned char gY) { ...@@ -98,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;
useLeftAnimOffset(true); useLeftAnimOffset();
break; break;
...@@ -234,10 +234,14 @@ fixed Event::getHeight () { ...@@ -234,10 +234,14 @@ 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) {
fixed offset = 0;
if (getAnim(animType) && noAnimOffset)
offset = getAnim(animType)->getOffset();
return (x + getWidth() >= left) && return (x + getWidth() >= left) &&
(x < left + width) && (x < left + width) &&
(y >= top) && (y + offset >= top) &&
(y - getHeight() < top + height); (y + offset - getHeight() < top + height);
} }
......
...@@ -87,9 +87,9 @@ class Event : public Movable { ...@@ -87,9 +87,9 @@ 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 noAnimOffset;
bool onlyRAnimOffset; bool onlyLAnimOffset;
bool disableAnimOffset; bool onlyRAnimOffset;
Event (); Event ();
...@@ -98,9 +98,9 @@ class Event : public Movable { ...@@ -98,9 +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 useLeftAnimOffset (bool enable); void useLeftAnimOffset ();
void useRightAnimOffset (bool enable); void useRightAnimOffset ();
void dontUseAnimOffset (bool enable); void dontUseAnimOffset ();
public: public:
Event (unsigned char gX, unsigned char gY); Event (unsigned char gX, unsigned char gY);
......
...@@ -53,7 +53,6 @@ signed char* Event::prepareStep (unsigned int ticks, int msps) { ...@@ -53,7 +53,6 @@ signed char* Event::prepareStep (unsigned int ticks, int msps) {
// If the event has been removed from the grid, destroy it // If the event has been removed from the grid, destroy it
if (!set) return NULL; if (!set) return NULL;
// If the event and its origin are off-screen, the event is not in the // If the event and its origin are off-screen, the event is not in the
// process of self-destruction, remove it // process of self-destruction, remove it
if ((animType != E_LFINISHANIM) && (animType != E_RFINISHANIM) && if ((animType != E_LFINISHANIM) && (animType != E_RFINISHANIM) &&
...@@ -103,7 +102,6 @@ Event* Event::step (unsigned int ticks, int msps) { ...@@ -103,7 +102,6 @@ Event* Event::step (unsigned int ticks, int msps) {
width = getWidth(); width = getWidth();
height = getHeight(); height = getHeight();
// Handle behaviour // Handle behaviour
switch (set[E_BEHAVIOUR]) { switch (set[E_BEHAVIOUR]) {
...@@ -163,9 +161,11 @@ Event* Event::step (unsigned int ticks, int msps) { ...@@ -163,9 +161,11 @@ Event* Event::step (unsigned int ticks, int msps) {
case 6: case 6:
int count = level->path[set[E_MULTIPURPOSE]].node;
// Use the path from the level file // Use the path from the level file
dx = TTOF(gridX) + ITOF(level->path[set[E_MULTIPURPOSE]].x[level->path[set[E_MULTIPURPOSE]].node]) - x; dx = TTOF(gridX) + ITOF(level->path[set[E_MULTIPURPOSE]].x[count]) - x;
dy = TTOF(gridY) + ITOF(level->path[set[E_MULTIPURPOSE]].y[level->path[set[E_MULTIPURPOSE]].node]) - y + TTOF(1); dy = TTOF(gridY) + ITOF(level->path[set[E_MULTIPURPOSE]].y[count]) - y;
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];
...@@ -539,6 +539,7 @@ Event* Event::step (unsigned int ticks, int msps) { ...@@ -539,6 +539,7 @@ Event* Event::step (unsigned int ticks, int msps) {
} }
dx /= set[E_MOVEMENTSP]; dx /= set[E_MOVEMENTSP];
dy /= set[E_MOVEMENTSP]; dy /= set[E_MOVEMENTSP];
x += (dx * msps) >> 10; x += (dx * msps) >> 10;
...@@ -879,13 +880,19 @@ Event* Event::step (unsigned int ticks, int msps) { ...@@ -879,13 +880,19 @@ Event* Event::step (unsigned int ticks, int msps) {
for (count = 0; count < nPlayers; count++) { for (count = 0; count < nPlayers; count++) {
levelPlayer = players[count].getLevelPlayer(); levelPlayer = players[count].getLevelPlayer();
// Check if the player is touching the event // Check if the player is touching the event
fixed offset = 0;
if (getAnim(animType) && noAnimOffset)
offset = getAnim(animType)->getOffset();
if (set[E_MODIFIER] == 6) { if (set[E_MODIFIER] == 6) {
if (width && height && if (width && height &&
levelPlayer->overlap(x, y - height, width - F8, F8) && levelPlayer->overlap(x, y + offset - 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)) {
...@@ -900,7 +907,7 @@ Event* Event::step (unsigned int ticks, int msps) { ...@@ -900,7 +907,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 - height, width, height)) { levelPlayer->overlap(x, y + offset - 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))
...@@ -964,7 +971,7 @@ void Event::draw (unsigned int ticks, int change) { ...@@ -964,7 +971,7 @@ void Event::draw (unsigned int ticks, int change) {
anim = level->getAnim(set[animType] + 128); anim = level->getAnim(set[animType] + 128);
// Explosions may only occur with finish animations // Explosions may only occur with finish animations
if (animType == E_RFINISHANIM || animType == E_LFINISHANIM) drawExplosion = true; drawExplosion = (animType == E_RFINISHANIM || animType == E_LFINISHANIM);
} }
else { else {
...@@ -981,9 +988,9 @@ void Event::draw (unsigned int ticks, int change) { ...@@ -981,9 +988,9 @@ void Event::draw (unsigned int ticks, int change) {
// Correct the position without altering the animation // Correct the position without altering the animation
if (disableAnimOffset) { if (noAnimOffset) {
changeY -= anim->getOffset(); changeY += anim->getOffset();
} }
else if (onlyLAnimOffset && animType == E_RIGHTANIM) { else if (onlyLAnimOffset && animType == E_RIGHTANIM) {
...@@ -1090,27 +1097,27 @@ void Event::drawEnergy (unsigned int ticks) { ...@@ -1090,27 +1097,27 @@ void Event::drawEnergy (unsigned int ticks) {
} }
void Event::useLeftAnimOffset(bool enable) { void Event::useLeftAnimOffset() {
onlyLAnimOffset = enable; onlyLAnimOffset = true;
return; return;
} }
void Event::useRightAnimOffset(bool enable) { void Event::useRightAnimOffset() {
onlyRAnimOffset = enable; onlyRAnimOffset = true;
return; return;
} }
void Event::dontUseAnimOffset(bool enable) { void Event::dontUseAnimOffset() {
disableAnimOffset = enable; noAnimOffset = true;
return; return;
......
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