Commit 6e631c48 authored by AlisterT's avatar AlisterT

Bug fixes.

parent 5421b4d6
......@@ -46,7 +46,7 @@
#define CONTROLS 11
// Time interval
#define T_KEY 500
#define T_KEY 200
// Class
......
......@@ -9,7 +9,7 @@
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2009 Alister Thomson
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
......@@ -537,7 +537,7 @@ void WaterPaletteEffect::apply (SDL_Color *shownPalette, bool direct,
if (next) next->apply(shownPalette, direct, mspf);
position = localPlayer->getY() - level->getWaterLevel(0);
position = localPlayer->getY() - level->getWaterLevel();
if (position <= 0) return;
......
......@@ -9,7 +9,7 @@
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2009 Alister Thomson
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
......@@ -63,7 +63,7 @@ void audioCallback (void * userdata, unsigned char * stream, int len) {
SDL_MixAudio(stream,
sounds[count].data + sounds[count].position, len,
SDL_MIX_MAXVOLUME >> 1);
SDL_MIX_MAXVOLUME >> 2);
sounds[count].position += len;
......@@ -74,7 +74,7 @@ void audioCallback (void * userdata, unsigned char * stream, int len) {
SDL_MixAudio(stream,
sounds[count].data + sounds[count].position,
sounds[count].length - sounds[count].position,
SDL_MIX_MAXVOLUME >> 1);
SDL_MIX_MAXVOLUME >> 2);
sounds[count].position = -1;
......
......@@ -8,7 +8,7 @@
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2009 Alister Thomson
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
......@@ -202,7 +202,7 @@ bool Bullet::step (unsigned int ticks, int msps) {
// If the event is within range, hit it
if (event->overlap(x - F160, y - F100, 2 * F160, 2 * F100))
event->hit(source, ticks);
event->hit(source, true, ticks);
event = event->getNext();
......@@ -245,7 +245,7 @@ bool Bullet::step (unsigned int ticks, int msps) {
if (event->overlap(x, y, 0, 0)) {
// If the event is hittable, hit it and destroy the bullet
if (event->hit(source, ticks)) return true;
if (event->hit(source, false, ticks)) return true;
}
......
......@@ -15,7 +15,7 @@
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2009 Alister Thomson
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
......@@ -43,11 +43,14 @@
Event::Event (unsigned char gX, unsigned char gY, Event *nextEvent) {
x = TTOF(gX);
y = TTOF(gY + 1);
dx = 0;
dy = 0;
next = nextEvent;
gridX = gX;
gridY = gY;
x = TTOF(gX);
y = TTOF(gY + 1);
flashTime = 0;
// Choose initial settings
......@@ -56,6 +59,7 @@ Event::Event (unsigned char gX, unsigned char gY, Event *nextEvent) {
case 21: // Destructible block
case 25: // Float up / Belt
case 37: // Sucker tubes
case 38: // Sucker tubes
case 40: // Monochrome
case 57: // Bubbles
......@@ -141,15 +145,17 @@ void Event::destroy (unsigned int ticks) {
}
bool Event::hit (Player *source, unsigned int ticks) {
bool Event::hit (Player *source, bool TNT, unsigned int ticks) {
int hitsRemaining;
// Deal with bullet collisions
// Check if event has already been destroyed
if ((animType == E_LFINISHANIM) || (animType == E_RFINISHANIM) ||
(ticks < flashTime)) return false;
hitsRemaining = level->hitEvent(source, gridX, gridY);
hitsRemaining = level->hitEvent(gridX, gridY, source, TNT);
// If the event cannot be hit, do not register hit
if (hitsRemaining < 0) return false;
......@@ -177,28 +183,27 @@ fixed Event::getWidth () {
fixed width;
if (animType && (getProperty(animType) >= 0)) {
width = ITOF(level->getAnim(getProperty(animType))->getWidth());
if (!animType) return F32;
// Blank sprites for e.g. invisible springs
if ((width == F1) && (getHeight() == F1)) return F32;
if (getProperty(animType) <= 0) return 0;
return width;
width = ITOF(level->getAnim(getProperty(animType))->getWidth());
}
// Blank sprites for e.g. invisible springs
if ((width == F1) && (getHeight() == F1)) return F32;
return F32;
return width;
}
fixed Event::getHeight () {
if (animType && (getProperty(animType) >= 0))
return ITOF(level->getAnim(getProperty(animType))->getHeight());
if (!animType) return F32;
if (getProperty(animType) <= 0) return 0;
return F32;
return ITOF(level->getAnim(getProperty(animType))->getHeight());
}
......
......@@ -94,7 +94,7 @@ class Event : public Movable {
Event * getNext ();
void removeNext ();
bool hit (Player *source, unsigned int ticks);
bool hit (Player *source, bool TNT, unsigned int ticks);
bool isFrom (unsigned char gX, unsigned char gY);
fixed getWidth ();
fixed getHeight ();
......
......@@ -87,15 +87,6 @@ bool Event::step (unsigned int ticks, int msps) {
height = getHeight();
if (set[E_BEHAVIOUR] != 28) {
// Pre-movement position
dx = x;
dy = y;
}
// Handle behaviour
switch (set[E_BEHAVIOUR]) {
......@@ -103,16 +94,18 @@ bool Event::step (unsigned int ticks, int msps) {
case 1:
// Sink down
y += ES_FAST * msps / set[E_MOVEMENTSP];
dy = ES_FAST * msps / set[E_MOVEMENTSP];
break;
case 2:
// Walk from side to side
if (animType == E_LEFTANIM) x -= ES_FAST * msps / set[E_MOVEMENTSP];
if (animType == E_LEFTANIM)
dx = -ES_FAST * msps / set[E_MOVEMENTSP];
else if (animType == E_RIGHTANIM)
x += ES_FAST * msps / set[E_MOVEMENTSP];
dx = ES_FAST * msps / set[E_MOVEMENTSP];
else dx = 0;
break;
......@@ -120,9 +113,10 @@ bool Event::step (unsigned int ticks, int msps) {
// Seek jazz
if (localPlayer->getX() + PXO_R < x)
x -= ES_FAST * msps / set[E_MOVEMENTSP];
dx = -ES_FAST * msps / set[E_MOVEMENTSP];
else if (localPlayer->getX() + PXO_L > x + width)
x += ES_FAST * msps / set[E_MOVEMENTSP];
dx = ES_FAST * msps / set[E_MOVEMENTSP];
else dx = 0;
break;
......@@ -133,15 +127,18 @@ bool Event::step (unsigned int ticks, int msps) {
if (!level->checkMaskDown(x + (width >> 1), y)) {
// Fall downwards
y += ES_FAST * msps / set[E_MOVEMENTSP];
dx = 0;
dy = ES_FAST * msps / set[E_MOVEMENTSP];
} else {
// Walk from side to side
if (animType == E_LEFTANIM)
x -= ES_FAST * msps / set[E_MOVEMENTSP];
dx = -ES_FAST * msps / set[E_MOVEMENTSP];
else if (animType == E_RIGHTANIM)
x += ES_FAST * msps / set[E_MOVEMENTSP];
dx = ES_FAST * msps / set[E_MOVEMENTSP];
dy = 0;
}
......@@ -156,17 +153,18 @@ bool Event::step (unsigned int ticks, int msps) {
case 6:
// Use the path from the level file
x = TTOF(gridX) + F16 + (level->pathX[level->pathNode] << 9);
y = TTOF(gridY) + (level->pathY[level->pathNode] << 9);
dx = TTOF(gridX) + F16 + (level->pathX[level->pathNode] << 9) - x;
dy = TTOF(gridY) + (level->pathY[level->pathNode] << 9) - y;
break;
case 7:
// Move back and forth horizontally with tail
if (animType == E_LEFTANIM) x -= ES_SLOW * msps / set[E_MOVEMENTSP];
if (animType == E_LEFTANIM)
dx = -ES_SLOW * msps / set[E_MOVEMENTSP];
else if (animType == E_RIGHTANIM)
x += ES_SLOW * msps / set[E_MOVEMENTSP];
dx = ES_SLOW * msps / set[E_MOVEMENTSP];
break;
......@@ -192,25 +190,30 @@ bool Event::step (unsigned int ticks, int msps) {
// Sink to ground
if (!level->checkMaskDown(x + (width >> 1), y))
y += ES_FAST * msps / set[E_MOVEMENTSP];
dy = ES_FAST * msps / set[E_MOVEMENTSP];
else dy = 0;
break;
case 12:
// Move back and forth horizontally
if (animType == E_LEFTANIM) x -= ES_SLOW * msps / set[E_MOVEMENTSP];
if (animType == E_LEFTANIM)
dx = -ES_SLOW * msps / set[E_MOVEMENTSP];
else if (animType == E_RIGHTANIM)
x += ES_SLOW * msps / set[E_MOVEMENTSP];
dx = ES_SLOW * msps / set[E_MOVEMENTSP];
else dx = 0;
break;
case 13:
// Move up and down
if (animType == E_LEFTANIM) y -= ES_SLOW * msps / set[E_MOVEMENTSP];
if (animType == E_LEFTANIM)
dy = -ES_SLOW * msps / set[E_MOVEMENTSP];
else if (animType == E_RIGHTANIM)
y += ES_SLOW * msps / set[E_MOVEMENTSP];
dy = ES_SLOW * msps / set[E_MOVEMENTSP];
else dy = 0;
break;
......@@ -229,7 +232,8 @@ bool Event::step (unsigned int ticks, int msps) {
case 16:
// Move across level to the left or right
x += set[E_MAGNITUDE] * ES_SLOW * msps / set[E_MOVEMENTSP];
if (set[E_MAGNITUDE] == 0) dx = -ES_SLOW * msps / set[E_MOVEMENTSP];
else dx = set[E_MAGNITUDE] * ES_SLOW * msps / set[E_MOVEMENTSP];
break;
......@@ -361,13 +365,12 @@ bool Event::step (unsigned int ticks, int msps) {
case 29:
// Rotate
// TODO: Verify the direction of rotation
offset = ITOF(set[E_BRIDGELENGTH] * set[E_CHAINLENGTH]);
angle = set[E_MAGNITUDE] * ticks / 2048.0f;
x = TTOF(gridX) + (int)(sin(angle) * offset);
y = TTOF(gridY) + (int)(cos(angle) * offset);
dx = TTOF(gridX) + (int)(sin(angle) * offset) - x;
dy = TTOF(gridY) + (int)((cos(angle) + 1.0f) * offset) - y;
break;
......@@ -379,24 +382,24 @@ bool Event::step (unsigned int ticks, int msps) {
angle = (set[E_CHAINANGLE] * 3.141592f / 128.0f) +
(set[E_MAGNITUDE] * ticks / 2048.0f);
x = TTOF(gridX) + (int)(sin(angle) * offset);
y = TTOF(gridY) + (int)fabs(cos(angle) * offset);
dx = TTOF(gridX) + (int)(sin(angle) * offset) - x;
dy = TTOF(gridY) + (int)fabs((cos(angle) + 1.0f) * offset) - y;
break;
case 31:
// Move horizontally
if (animType == E_LEFTANIM) x -= ES_FAST * msps / set[E_MOVEMENTSP];
else x += ES_FAST * msps / set[E_MOVEMENTSP];
if (animType == E_LEFTANIM) dx = -ES_FAST * msps / set[E_MOVEMENTSP];
else dx = ES_FAST * msps / set[E_MOVEMENTSP];
break;
case 32:
// Move horizontally
if (animType == E_LEFTANIM) x -= ES_FAST * msps / set[E_MOVEMENTSP];
else x += ES_FAST * msps / set[E_MOVEMENTSP];
if (animType == E_LEFTANIM) dx = -ES_FAST * msps / set[E_MOVEMENTSP];
else dx = ES_FAST * msps / set[E_MOVEMENTSP];
break;
......@@ -406,22 +409,29 @@ bool Event::step (unsigned int ticks, int msps) {
if (localPlayer->getFacing() && (x + width < localPlayer->getX())) {
x += ES_FAST * msps / set[E_MOVEMENTSP];
dx = ES_FAST * msps / set[E_MOVEMENTSP];
if (y + height < localPlayer->getY() + PYO_TOP)
y += ES_SLOW * msps / set[E_MOVEMENTSP];
dy = ES_SLOW * msps / set[E_MOVEMENTSP];
else if (y > localPlayer->getY())
y -= ES_SLOW * msps / set[E_MOVEMENTSP];
dy = -ES_SLOW * msps / set[E_MOVEMENTSP];
else dy = 0;
} else if (!localPlayer->getFacing() &&
(x > localPlayer->getX() + F32)) {
x -= ES_FAST * msps / set[E_MOVEMENTSP];
dx = -ES_FAST * msps / set[E_MOVEMENTSP];
if (y + height < localPlayer->getY() + PYO_TOP)
y += ES_SLOW * msps / set[E_MOVEMENTSP];
dy = ES_SLOW * msps / set[E_MOVEMENTSP];
else if (y > localPlayer->getY())
y -= ES_SLOW * msps / set[E_MOVEMENTSP];
dy = -ES_SLOW * msps / set[E_MOVEMENTSP];
else dy = 0;
} else {
dx = 0;
dy = 0;
}
......@@ -433,17 +443,17 @@ bool Event::step (unsigned int ticks, int msps) {
if (ticks > level->getEventTime(gridX, gridY)) {
if (y <= TTOF(gridY) + F16 - (set[E_YAXIS] * F2))
level->setEventTime(gridX, gridY,
ticks + (set[E_MODIFIER] * 500));
else
y -= (y + (set[E_YAXIS] * F2) - TTOF(gridY)) * msps / 320;
if (y <= TTOF(gridY) + F16 - (set[E_YAXIS] * F2)) {
level->setEventTime(gridX, gridY, ticks + (set[E_MOVEMENTSP] * 1000));
dy = 0;
} else dy = -(y + (set[E_YAXIS] * F2) - TTOF(gridY)) * msps / 320;
} else {
if (y < TTOF(gridY) + F16)
y += (y + (set[E_YAXIS] * F2) - TTOF(gridY)) * msps / 320;
else y = TTOF(gridY) + F16;
if (y < TTOF(gridY) + F16) dy = (y + (set[E_YAXIS] * F2) - TTOF(gridY)) * msps / 320;
else dy = (TTOF(gridY) + F16) - y;
}
......@@ -451,7 +461,23 @@ bool Event::step (unsigned int ticks, int msps) {
case 35:
// TODO: Find out what this is
// Non-floating Sparks-esque following
if (localPlayer->getFacing() && (x + width < localPlayer->getX() + PXO_L - F4)) {
if (level->checkMaskDown(x + width, y + F4) &&
!level->checkMaskDown(x + width + F4, y - (height >> 1)))
dx = ES_FAST * msps / set[E_MOVEMENTSP];
else dx = 0;
} else if (!localPlayer->getFacing() && (x > localPlayer->getX() + PXO_R + F4)) {
if (level->checkMaskDown(x, y + F4) &&
!level->checkMaskDown(x - F4, y - (height >> 1)))
dx = -ES_FAST * msps / set[E_MOVEMENTSP];
else dx = 0;
} else dx = 0;
break;
......@@ -462,36 +488,35 @@ bool Event::step (unsigned int ticks, int msps) {
if (!level->checkMaskDown(x + (width >> 1), y)) {
// Fall downwards
y += ES_FAST * msps / set[E_MOVEMENTSP];
dx = 0;
dy = ES_FAST * msps / set[E_MOVEMENTSP];
} else {
// Walk from side to side, staying on-screen
if (animType == E_LEFTANIM)
x -= ES_FAST * msps / set[E_MOVEMENTSP];
dx = -ES_FAST * msps / set[E_MOVEMENTSP];
else if (animType == E_RIGHTANIM)
x += ES_FAST * msps / set[E_MOVEMENTSP];
dx = ES_FAST * msps / set[E_MOVEMENTSP];
else dx = 0;
dy = 0;
}
break;
case 37:
// TODO: Find out what this is
break;
case 38:
// Sucker tubes
for (count = 0; count < nPlayers; count++) {
if (players[count].overlap(x + F8, y - height, width - F16,
height)) {
if (players[count].overlap(x + F8, y + F4 - height, width - F16,
height - F8)) {
players[count].setSpeed(set[E_MAGNITUDE] * F40,
players[count].setSpeed(set[E_YAXIS]? set[E_MAGNITUDE] * F4: set[E_MAGNITUDE] * F40,
set[E_YAXIS]? set[E_MULTIPURPOSE] * -F20: 0);
}
......@@ -552,14 +577,15 @@ bool Event::step (unsigned int ticks, int msps) {
// Dreempipes turtles
if (y > level->getWaterLevel(0)) {
if (y > level->getWaterLevel()) {
if (animType == E_LEFTANIM)
x -= ES_SLOW * msps / set[E_MOVEMENTSP];
dx = -ES_SLOW * msps / set[E_MOVEMENTSP];
else if (animType == E_RIGHTANIM)
x += ES_SLOW * msps / set[E_MOVEMENTSP];
dx = ES_SLOW * msps / set[E_MOVEMENTSP];
else dx = 0;
}
} else dx = 0;
break;
......@@ -572,6 +598,15 @@ bool Event::step (unsigned int ticks, int msps) {
}
// Apply movement
if (set[E_BEHAVIOUR] != 28) {
x += dx;
y += dy;
}
// Choose animation and direction
if ((animType == E_LEFTANIM) || (animType == E_RIGHTANIM)) {
......@@ -708,12 +743,12 @@ bool Event::step (unsigned int ticks, int msps) {
if (animType == E_LEFTANIM) {
if (level->checkMaskDown(x - F4, y - (height >> 1)))
if (level->checkMaskDown(x, y - (height >> 1)))
animType = E_RIGHTANIM;
} else if (animType == E_RIGHTANIM) {
if (level->checkMaskDown(x + width + F4, y - (height >> 1)))
if (level->checkMaskDown(x + width, y - (height >> 1)))
animType = E_LEFTANIM;
}
......@@ -780,7 +815,7 @@ bool Event::step (unsigned int ticks, int msps) {
// Dreempipes turtles
if (y > level->getWaterLevel(0)) {
if (y > level->getWaterLevel()) {
if (animType == E_LEFTANIM) {
......@@ -845,6 +880,9 @@ bool Event::step (unsigned int ticks, int msps) {
if ((animType == E_LFINISHANIM) || (animType == E_RFINISHANIM)) {
// Change the water level
if (set[E_MODIFIER] == 31) level->setWaterLevel(gridY);
// The event has been destroyed, so remove it
level->clearEvent(gridX, gridY);
......@@ -868,9 +906,6 @@ bool Event::step (unsigned int ticks, int msps) {
} else {
// Change the water level
if (set[E_MODIFIER] == 31) level->setWaterLevel(gridY);
level->setEventTime(gridX, gridY, 0);
}
......@@ -889,7 +924,8 @@ bool Event::step (unsigned int ticks, int msps) {
// Check if the player is touching the event
if (players[count].overlap(x, y - height, width, height)) {
if (width && height &&
players[count].overlap(x, y - height, width, height)) {
if (set[E_MODIFIER] == 6) {
......@@ -902,7 +938,7 @@ bool Event::step (unsigned int ticks, int msps) {
players[count].setEvent(set);
players[count].setPosition(players[count].getX() +
x - dx, y - height);
dx, y - height);
} else players[count].clearEvent(set, E_MODIFIER);
......@@ -919,15 +955,6 @@ bool Event::step (unsigned int ticks, int msps) {
}
if (set[E_BEHAVIOUR] != 28) {
// Store change in position
dx = x - dx;
dy = y - dy;
}
return false;
}
......
......@@ -17,7 +17,7 @@
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2009 Alister Thomson
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
......@@ -272,7 +272,7 @@ void Level::clearEvent (unsigned char gridX, unsigned char gridY) {
}
int Level::hitEvent (Player *source, unsigned char gridX, unsigned char gridY) {
int Level::hitEvent (unsigned char gridX, unsigned char gridY, Player *source, bool TNT) {
GridElement *ge;
unsigned char buffer[MTL_L_GRID];
......@@ -286,7 +286,8 @@ int Level::hitEvent (Player *source, unsigned char gridX, unsigned char gridY) {
if (!hitsToKill) return -1;
// Increase the hit count
ge->hits++;
if (TNT) ge->hits = hitsToKill;
else ge->hits++;
// Check if the event has been killed
if (ge->hits == hitsToKill) {
......@@ -389,7 +390,7 @@ void Level::setWaterLevel (unsigned char gridY) {
unsigned char buffer[MTL_L_PROP];
waterLevel = TTOF(gridY);
waterLevelTarget = TTOF(gridY);
if (gameMode) {
......@@ -407,10 +408,9 @@ void Level::setWaterLevel (unsigned char gridY) {
}
fixed Level::getWaterLevel (int phase) {
fixed Level::getWaterLevel () {
if (phase & 1024) return waterLevel - ((phase & 1023) * 32);
return waterLevel - ((1024 - (phase & 1023)) * 32);
return waterLevel;
}
......@@ -475,7 +475,7 @@ void Level::receive (unsigned char *buffer) {
} else if (buffer[2] == 1) {
waterLevel = TTOF(buffer[3]);
waterLevelTarget = TTOF(buffer[3]);
} else if (buffer[2] == 2) {
......
......@@ -10,7 +10,7 @@
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2009 Alister Thomson
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
......@@ -118,6 +118,8 @@ class Level {
unsigned int endTime;
int enemies, items;
fixed waterLevel;
fixed waterLevelTarget;
fixed waterLevelSpeed;
fixed energyBar;
int stage;
......@@ -148,23 +150,20 @@ class Level {
bool checkMaskDown (fixed x, fixed y);
bool checkSpikes (fixed x, fixed y);
void setNext (int nextLevel, int nextWorld);
void setTile (unsigned char gridX, unsigned char gridY,
unsigned char tile);
void setTile (unsigned char gridX, unsigned char gridY, unsigned char tile);
signed char * getEvent (unsigned char gridX, unsigned char gridY);
unsigned char getEventHits (unsigned char gridX, unsigned char gridY);
unsigned int getEventTime (unsigned char gridX, unsigned char gridY);
void clearEvent (unsigned char gridX, unsigned char gridY);
int hitEvent (Player *source, unsigned char gridX,
unsigned char gridY);
void setEventTime (unsigned char gridX, unsigned char gridY,
unsigned int time);
int hitEvent (unsigned char gridX, unsigned char gridY, Player *source, bool TNT);
void setEventTime (unsigned char gridX, unsigned char gridY, unsigned int time);
signed char * getBullet (unsigned char bullet);
Sprite * getSprite (unsigned char sprite);
Anim * getAnim (unsigned char anim);
Anim * getMiscAnim (unsigned char anim);
void addTimer ();
void setWaterLevel (unsigned char gridY);
fixed getWaterLevel (int phase);
fixed getWaterLevel ();
void playSound (int sound);
void setStage (int stage);
int getStage ();
......
......@@ -8,7 +8,7 @@
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2009 Alister Thomson
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
......@@ -133,6 +133,14 @@ int Level::step () {
}
// Handle change in water level
if (waterLevel < waterLevelTarget) waterLevelSpeed += 100 * msps;
else waterLevelSpeed -= 100 * msps;
if (waterLevelSpeed > 40000) waterLevelSpeed = 40000;
if (waterLevelSpeed < -40000) waterLevelSpeed = -40000;
waterLevel += (waterLevelSpeed * msps) >> 10;
return E_NONE;
......@@ -303,8 +311,11 @@ void Level::draw () {
}
// Uncomment the following for a line showing the water level
/* drawRect(0, FTOI(getWaterLevel(ticks) - viewY), screenW, 2, 24); */
// Temporary lines showing the water level
drawRect(0, FTOI(waterLevel - viewY), screenW, 2, 24);
drawRect(0, FTOI(waterLevel - viewY) + 3, screenW, 1, 24);
drawRect(0, FTOI(waterLevel - viewY) + 6, screenW, 1, 24);
drawRect(0, FTOI(waterLevel - viewY) + 10, screenW, 1, 24);
SDL_SetClipRect(screen, NULL);
......
......@@ -12,7 +12,7 @@
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2009 Alister Thomson
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
......@@ -610,6 +610,7 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) {
grid[y][x].bg = buffer[((y + (x * LH)) << 1) + 1] >> 7;
grid[y][x].event = buffer[((y + (x * LH)) << 1) + 1] & 127;
grid[y][x].hits = 0;
grid[y][x].time = 0;
}
......@@ -823,9 +824,11 @@ int Level::load (char *fileName, unsigned char diff, bool checkpoint) {
setNext(x, y);
// Thanks to Doubble Dutch for this next bit
// Thanks to Doubble Dutch for the water level bytes
file->seek(4, false);
waterLevel = ITOF(file->loadShort());
waterLevelTarget = ITOF(file->loadShort());
waterLevel = waterLevelTarget - F8;
waterLevelSpeed = 0;
// Thanks to Feline and the JCS94 team for the next bits:
......
......@@ -8,7 +8,7 @@
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2009 Alister Thomson
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
......@@ -118,11 +118,11 @@ bool Bird::step (unsigned int ticks, int msps) {
}
if (y > level->getWaterLevel(ticks) - F24) {
if (y > level->getWaterLevel() - F24) {
// Always stay above water
y = level->getWaterLevel(ticks) - F24;
y = level->getWaterLevel() - F24;
dy = 0;
} else {
......
......@@ -11,7 +11,7 @@
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2009 Alister Thomson
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
......@@ -678,7 +678,7 @@ void Player::floatUp (signed char *newEvent, int speed) {
void Player::belt (int speed) {
dx += speed * 160;
dx += speed * 20;
return;
......
......@@ -8,7 +8,7 @@
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2009 Alister Thomson
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
......@@ -98,11 +98,11 @@
#define T_WARP 1000
// Player offsets
#define PXO_L (F12 - F10)
#define PXO_ML (F12 - F4)
#define PXO_MID F12
#define PXO_MR (F12 + F4)
#define PXO_R (F12 + F10)
#define PXO_MID F16
#define PXO_L (PXO_MID - F10)
#define PXO_ML (PXO_MID - F4)
#define PXO_MR (PXO_MID + F4)
#define PXO_R (PXO_MID + F10)
#define PYO_TOP (-F20)
#define PYO_MID (-F10)
......@@ -176,7 +176,7 @@ class Player : public Movable {
3 = 1 orange, 4 = 2 orange, 5 = 3 orange, 6 = 4 orange */
bool floating; // false = normal, true = boarding/bird/etc.
bool facing;
unsigned int lookTime; /* Negative if looking up, positive if looking
int lookTime; /* Negative if looking up, positive if looking
down, 0 if neither */
int reaction;
unsigned int reactionTime;
......
......@@ -8,7 +8,7 @@
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2009 Alister Thomson
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
......@@ -153,7 +153,7 @@ void Player::control (unsigned int ticks, int msps) {
if (dy < -PXS_RUN) dy = -PXS_RUN;
if (dy > PXS_RUN) dy = PXS_RUN;
} else if (y > level->getWaterLevel(ticks)) {
} else if (y + PYO_MID > level->getWaterLevel()) {
if (pcontrols[C_JUMP]) {
......@@ -213,8 +213,8 @@ void Player::control (unsigned int ticks, int msps) {
jumpY = y - jumpHeight;
// Increase jump height if walking/running
if (dx < 0) jumpY += dx >> 4;
else if (dx > 0) jumpY -= dx >> 4;
if (dx < 0) jumpY += dx >> 3;
else if (dx > 0) jumpY -= dx >> 3;
event = NULL;
......@@ -248,9 +248,19 @@ void Player::control (unsigned int ticks, int msps) {
dy = (jumpY - y - F64) * 4;
// Avoid jumping to fast, unless caused by an event
if (!event && (dy < (ITOF(-92) - F64) * 4))
dy = (ITOF(-92) - F64) * 4;
// Spring speed limit
if (event && (event[E_MODIFIER] == 29)) {
if ((event[E_MULTIPURPOSE] == 0) && (dy < PYS_JUMP))
dy = PYS_JUMP;
if ((event[E_MULTIPURPOSE] > 0) && (dy < event[E_MULTIPURPOSE] * -F20))
dy = event[E_MULTIPURPOSE] * -F20;
}
// Avoid jumping too fast, unless caused by an event
if (!event && (dy < PYS_JUMP)) dy = PYS_JUMP;
} else {
......@@ -261,7 +271,8 @@ void Player::control (unsigned int ticks, int msps) {
}
// Stop looking
if (!pcontrols[C_UP] && !pcontrols[C_DOWN]) lookTime = 0;
if (!pcontrols[C_UP] && (lookTime < 0)) lookTime = 0;
if (!pcontrols[C_DOWN] && (lookTime > 0)) lookTime = 0;
}
......@@ -534,22 +545,19 @@ void Player::view (unsigned int ticks, int mspf) {
// Find new position
viewX = x + F8 - (viewW << 9);
viewY = y - F24 - (viewH << 9);
if (!lookTime || (ticks < 1000 + lookTime) || (ticks < 1000 - lookTime)) {
viewY = y - F24 - (viewH << 9);
} else if (lookTime > 0) {
if ((lookTime > 0) && ((int)ticks > 1000 + lookTime)) {
if (ticks < 2000 + lookTime)
viewY = y - F24 - (64 * (lookTime + 1000 - ticks)) - (viewH << 9);
else viewY = y + F64 - F24 - (viewH << 9);
// Look down
if ((int)ticks < 2000 + lookTime) viewY += 64 * (ticks - (1000 + lookTime));
else viewY += F64;
} else {
} else if ((lookTime < 0) && ((int)ticks > 1000 - lookTime)) {
if (ticks < 2000 - lookTime)
viewY = y - F24 - (64 * (lookTime - 1000 + ticks)) - (viewH << 9);
else viewY = y - F64 - F24 - (viewH << 9);
// Look up
if ((int)ticks < 2000 - lookTime) viewY -= 64 * (ticks - (1000 - lookTime));
else viewY -= F64;
}
......@@ -595,7 +603,7 @@ void Player::draw (unsigned int ticks, int change) {
(reactionTime - ticks > PRT_HURT - PRT_HURTANIM))
anim = anims[facing? PA_RHURT: PA_LHURT];
else if (y > level->getWaterLevel(ticks))
else if (y + PYO_MID > level->getWaterLevel())
anim = anims[facing? PA_RSWIM: PA_LSWIM];
else if (floating) anim = anims[facing? PA_RBOARD: PA_LBOARD];
......@@ -639,12 +647,12 @@ void Player::draw (unsigned int ticks, int change) {
else if (pcontrols[C_FIRE])
anim = anims[facing? PA_RSHOOT: PA_LSHOOT];
else if ((lookTime < 0) && (ticks > 1000 - lookTime))
else if ((lookTime < 0) && ((int)ticks > 1000 - lookTime))
anim = anims[PA_LOOKUP];
else if (lookTime > 0) {
if (ticks < 1000 + lookTime)
if ((int)ticks < 1000 + lookTime)
anim = anims[facing? PA_RCROUCH: PA_LCROUCH];
else anim = anims[PA_LOOKDOWN];
......@@ -691,6 +699,17 @@ void Player::draw (unsigned int ticks, int change) {
an->restorePalette();
// Uncomment the following to see the area of the player
/*drawRect(FTOI(getDrawX(change) + PXO_L - viewX),
FTOI(getDrawY(change) + PYO_TOP - viewY),
FTOI(PXO_R - PXO_L),
FTOI(-PYO_TOP), 89);
drawRect(FTOI(getDrawX(change) + PXO_ML - viewX),
FTOI(getDrawY(change) + PYO_TOP - viewY),
FTOI(PXO_MR - PXO_ML),
FTOI(-PYO_TOP), 88);*/
if (reaction == PR_INVINCIBLE) {
// Show invincibility stars
......
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