Commit f313f23f authored by Gerhard Stein's avatar Gerhard Stein

introduced 2D Vector for the position

parent 396f8d0d
......@@ -24,7 +24,8 @@ sprite(BLANKSPRITE),
mp_object(NULL),
mp_Map(pmap),
m_blinktime(0),
m_invincible(false)
m_invincible(false),
m_Pos(x,y)
{
bboxX1 = 0;
bboxX2 = 0;
......@@ -36,8 +37,6 @@ m_invincible(false)
solid = true;
inhibitfall = false;
this->x = x;
this->y = y;
canbezapped = false;
onscreen = false;
......@@ -160,7 +159,7 @@ bool CObject::calcVisibility()
(mp_Map->m_scrolly<<STC)-(visibility<<CSF);
Uint32 down = ((mp_Map->m_scrolly+gameres.h)<<STC)+(visibility<<CSF);
bool inscreen = ( right > x && left < x && down > y && up < y );
bool inscreen = ( right > m_Pos.x && left < m_Pos.x && down > m_Pos.y && up < m_Pos.y );
// Bullets should disappear when offscreen
if(m_type == OBJ_SNDWAVE || m_type == OBJ_RAY || m_type == OBJ_FIREBALL)
......@@ -227,8 +226,8 @@ void CObject::moveTo(const VectorD2<Uint32> &new_loc)
void CObject::moveTo(int new_x, int new_y)
{
int amount_x = new_x-x;
int amount_y = new_y-y;
int amount_x = new_x-m_Pos.x;
int amount_y = new_y-m_Pos.y;
if(amount_x < 0) // move left
moveLeft(-amount_x);
......@@ -261,17 +260,17 @@ void CObject::moveLeft(int amount, bool force)
if(amount <= 0)
return;
int y1 = y + bboxY1;
int y2 = y + bboxY2;
int y1 = m_Pos.y + bboxY1;
int y2 = m_Pos.y + bboxY2;
blockedr = false;
// If it is forced don't check for collision
if(force) {
x -= amount;
m_Pos.x -= amount;
return;
}
if( y-amount < 0 )
if( m_Pos.y-amount < 0 )
return;
// If object isn't solid it won't be stopped anyway
......@@ -279,7 +278,7 @@ void CObject::moveLeft(int amount, bool force)
{
blockedr = blockedl = false;
blockedu = blockedd = false;
x -= amount;
m_Pos.x -= amount;
return;
}
......@@ -290,13 +289,13 @@ void CObject::moveLeft(int amount, bool force)
{
if(amount > (1<<STC))
{
x -= (1<<STC);
m_Pos.x -= (1<<STC);
moveSlopedTiles(getXMidPos()-64, y1, y2, -(1<<STC));
amount -= (1<<STC);
}
else
{
x -= amount;
m_Pos.x -= amount;
moveSlopedTiles(getXMidPos()-64, y1, y2, -amount);
amount = 0;
}
......@@ -310,12 +309,12 @@ void CObject::moveRight(int amount, bool force)
if(amount <= 0)
return;
int y1 = y + bboxY1;
int y2 = y + bboxY2;
int y1 = m_Pos.y + bboxY1;
int y2 = m_Pos.y + bboxY2;
blockedl = false;
if(force) {
x += amount;
m_Pos.x += amount;
return;
}
......@@ -323,7 +322,7 @@ void CObject::moveRight(int amount, bool force)
{
blockedr = blockedl = false;
blockedu = blockedd = false;
x += amount;
m_Pos.x += amount;
return;
}
......@@ -335,13 +334,13 @@ void CObject::moveRight(int amount, bool force)
{
if(amount > (1<<STC))
{
x += (1<<STC);
m_Pos.x += (1<<STC);
moveSlopedTiles(getXMidPos()+64, y1, y2, (1<<STC));
amount -= (1<<STC);
}
else
{
x += amount;
m_Pos.x += amount;
moveSlopedTiles(getXMidPos()+64, y1, y2, amount);
amount = 0;
}
......@@ -355,7 +354,7 @@ void CObject::moveUp(int amount)
if(amount <= 0)
return;
int y1 = y + bboxY1;
int y1 = m_Pos.y + bboxY1;
if( y1-amount < 0 )
return;
......@@ -364,7 +363,7 @@ void CObject::moveUp(int amount)
{
blockedr = blockedl = false;
blockedu = blockedd = false;
y -= amount;
m_Pos.y -= amount;
return;
}
......@@ -375,12 +374,12 @@ void CObject::moveUp(int amount)
{
if(amount > (1<<STC))
{
y -= (1<<STC);
m_Pos.y -= (1<<STC);
amount -= (1<<STC);
}
else
{
y -= amount;
m_Pos.y -= amount;
amount = 0;
}
}
......@@ -399,7 +398,7 @@ void CObject::moveDown(int amount)
{
blockedr = blockedl = false;
blockedu = blockedd = false;
y += amount;
m_Pos.y += amount;
return;
}
......@@ -410,12 +409,12 @@ void CObject::moveDown(int amount)
{
if(amount > (1<<STC))
{
y += (1<<STC);
m_Pos.y += (1<<STC);
amount -= (1<<STC);
}
else
{
y += amount;
m_Pos.y += amount;
amount = 0;
}
}
......@@ -458,21 +457,21 @@ void CObject::InertiaAndFriction_X()
}
unsigned int CObject::getXPosition()
{ return x; }
{ return m_Pos.x; }
unsigned int CObject::getYPosition()
{ return y; }
{ return m_Pos.y; }
unsigned int CObject::getXLeftPos()
{ return x+bboxX1; }
{ return m_Pos.x+bboxX1; }
unsigned int CObject::getXRightPos()
{ return x+bboxX2; }
{ return m_Pos.x+bboxX2; }
unsigned int CObject::getXMidPos()
{ return x+(bboxX2-bboxX1)/2; }
{ return m_Pos.x+(bboxX2-bboxX1)/2; }
unsigned int CObject::getYUpPos()
{ return y+bboxY1; }
{ return m_Pos.y+bboxY1; }
unsigned int CObject::getYDownPos()
{ return y+bboxY2; }
{ return m_Pos.y+bboxY2; }
unsigned int CObject::getYMidPos()
{ return y+(bboxY2-bboxY1)/2; }
{ return m_Pos.y+(bboxY2-bboxY1)/2; }
/**
......@@ -637,8 +636,8 @@ void CObject::draw()
CSprite &Sprite = g_pGfxEngine->getSprite(sprite);
SDL_Surface *sfc = g_pVideoDriver->getBlitSurface();
scrx = (x>>STC)-mp_Map->m_scrollx;
scry = (y>>STC)-mp_Map->m_scrolly;
scrx = (m_Pos.x>>STC)-mp_Map->m_scrollx;
scry = (m_Pos.y>>STC)-mp_Map->m_scrolly;
SDL_Rect gameres = g_pVideoDriver->getGameResolution();
......
......@@ -176,7 +176,7 @@ protected:
Uint16 m_blinktime;
bool m_invincible;
unsigned int x, y; // x,y location in map coords, CSFed
VectorD2<Uint32> m_Pos; // x,y location in map coords, CSFed, represent as 2D Vector
static int m_number_of_objects;
......
......@@ -17,12 +17,12 @@
void CObject::performCollisionsSameBox()
{
// Left/Right borders
blockedl = checkSolidL(x+bboxX1, x+bboxX2, y+bboxY1, y+bboxY2);
blockedr = checkSolidR(x+bboxX1, x+bboxX2, y+bboxY1, y+bboxY2);
blockedl = checkSolidL(m_Pos.x+bboxX1, m_Pos.x+bboxX2, m_Pos.y+bboxY1, m_Pos.y+bboxY2);
blockedr = checkSolidR(m_Pos.x+bboxX1, m_Pos.x+bboxX2, m_Pos.y+bboxY1, m_Pos.y+bboxY2);
// Upper/Lower borders
blockedu = checkSolidU(x+bboxX1, x+bboxX2, y+bboxY1);
blockedd = checkSolidD(x+bboxX1, x+bboxX2, y+bboxY2);
blockedu = checkSolidU(m_Pos.x+bboxX1, m_Pos.x+bboxX2, m_Pos.y+bboxY1);
blockedd = checkSolidD(m_Pos.x+bboxX1, m_Pos.x+bboxX2, m_Pos.y+bboxY2);
if(g_pBehaviorEngine->getEpisode() > 3)
{ // now check for the sloped tiles
......@@ -56,9 +56,9 @@ const int COLISION_RES = (1<<STC);
void CObject::performCollisionOnSlopedTiles()
{
const Uint32 halftile = ((1<<CSF)/2);
const Uint32 x1 = x + bboxX1;
const Uint32 x2 = x + bboxX2;
const Uint32 y2 = y + bboxY2;
const Uint32 x1 = m_Pos.x + bboxX1;
const Uint32 x2 = m_Pos.x + bboxX2;
const Uint32 y2 = m_Pos.y + bboxY2;
std::vector<CTileProperties> &TileProperty = g_pBehaviorEngine->getTileProperties();
onslope = false;
......@@ -133,8 +133,8 @@ void CObject::pushOutofSolidTiles()
{
if(onslope)
{
const int px= (x+(bboxX1+bboxX2)/2);
const int py= (y+bboxY2+1);
const int px= (m_Pos.x+(bboxX1+bboxX2)/2);
const int py= (m_Pos.y+bboxY2+1);
std::vector<CTileProperties> &TileProperty = g_pBehaviorEngine->getTileProperties();
const char slope = TileProperty[mp_Map->at(px>>CSF, py>>CSF)].bup;
......@@ -147,7 +147,7 @@ void CObject::pushOutofSolidTiles()
const int yh = yb1 + dy;
if( py%512 > yh )
y -= ((py%512) - yh);
m_Pos.y -= ((py%512) - yh);
}
}
}
......@@ -222,14 +222,14 @@ bool CObject::moveSlopedTileDown( int x, int y, int xspeed )
if( x_r >= 480 && ( yb1>yb2 ) ) // At Tile edge
{
new_y = (new_y>>CSF)<<CSF;
dy = this->y - (new_y+yb2);
dy = m_Pos.y - (new_y+yb2);
moveUp( dy );
moveRight( dy );
}
else // In the Tile itself or walking into...
{
moveYDir( new_y - this->y );
moveYDir( new_y - m_Pos.y );
}
}
else if(xspeed < 0) // Going left
......@@ -238,13 +238,13 @@ bool CObject::moveSlopedTileDown( int x, int y, int xspeed )
if( x_r <= 32 && ( yb1<yb2 ) ) // At Tile edge
{
new_y = (new_y>>CSF)<<CSF;
dy = (new_y+yb1) - this->y;
dy = (new_y+yb1) - m_Pos.y;
moveYDir( dy );
moveLeft( dy );
}
else // In the Tile itself or walking into...
{
moveYDir( new_y - this->y );
moveYDir( new_y - m_Pos.y );
}
}
return true;
......@@ -305,7 +305,7 @@ void CObject::moveSlopedTileUp( int x, int y, int xspeed )
// get new position
const Uint32 new_y = y_pos - bboxY1 + (1<<STC);
moveYDir( new_y - this->y );
moveYDir( new_y - m_Pos.y );
}
// returns nonzero if object1 overlaps object2
......@@ -315,16 +315,16 @@ bool CObject::hitdetect(CObject &hitobject)
unsigned int rect2x1, rect2y1, rect2x2, rect2y2;
// get the bounding rectangle of the first object
rect1x1 = x + bboxX1;
rect1y1 = y + bboxY1;
rect1x2 = x + bboxX2;
rect1y2 = y + bboxY2;
rect1x1 = m_Pos.x + bboxX1;
rect1y1 = m_Pos.y + bboxY1;
rect1x2 = m_Pos.x + bboxX2;
rect1y2 = m_Pos.y + bboxY2;
// get the bounding rectangle of the second object
rect2x1 = hitobject.x + hitobject.bboxX1;
rect2y1 = hitobject.y + hitobject.bboxY1;
rect2x2 = hitobject.x + hitobject.bboxX2;
rect2y2 = hitobject.y + hitobject.bboxY2;
rect2x1 = hitobject.getXPosition() + hitobject.bboxX1;
rect2y1 = hitobject.getYPosition() + hitobject.bboxY1;
rect2x2 = hitobject.getXPosition() + hitobject.bboxX2;
rect2y2 = hitobject.getYPosition() + hitobject.bboxY2;
// find out if the rectangles overlap
if ((rect1x1 <= rect2x1) && (rect1x2 <= rect2x1)) return false;
......
......@@ -31,6 +31,7 @@ word CPlane::getMapDataAt(Uint16 x, Uint16 y)
{
if( x < m_width && y < m_height )
return mp_data[y*m_width+x];
return 0;
}
void CPlane::setMapDataAt(Uint16 t, Uint16 x, Uint16 y)
......
......@@ -72,15 +72,15 @@ void CCamera::process()
}
else
{
if(mp_AttachedObject->getXPosition() > x)
moveRight(mp_AttachedObject->getXPosition() - x );
else if(mp_AttachedObject->getXPosition() < x)
moveLeft(x - mp_AttachedObject->getXPosition());
if(mp_AttachedObject->getYPosition() > y)
moveDown(mp_AttachedObject->getYPosition() - y);
else if(mp_AttachedObject->getYPosition() < y)
moveUp(y - mp_AttachedObject->getYPosition());
if(mp_AttachedObject->getXPosition() > getXPosition())
moveRight(mp_AttachedObject->getXPosition() - getXPosition() );
else if(mp_AttachedObject->getXPosition() < getXPosition())
moveLeft(getXPosition() - mp_AttachedObject->getXPosition());
if(mp_AttachedObject->getYPosition() > getYPosition())
moveDown(mp_AttachedObject->getYPosition() - getYPosition());
else if(mp_AttachedObject->getYPosition() < getYPosition())
moveUp(getYPosition() - mp_AttachedObject->getYPosition());
}
......
......@@ -25,7 +25,8 @@ CObject(pmap, x, y, OBJ_NONE),
m_animation(0),
m_animation_time(1),
m_animation_ticker(0),
m_ObjectPtrs(ObjectPtrs)
m_ObjectPtrs(ObjectPtrs),
m_cliff_hanging(false)
{
m_index = 0;
m_direction = facedir;
......@@ -216,15 +217,30 @@ void CPlayerLevel::processMoving()
// Normal moving
if(!m_playcontrol[PA_FIRE])
{
if( m_playcontrol[PA_X]<0 && !blockedl)
if( m_playcontrol[PA_X]<0 )
{
xinertia = -movespeed;
m_direction = LEFT;
if(!blockedl)
{
// make him walk
xinertia = -movespeed;
m_direction = LEFT;
}
else
{
// TODO: check if keen can hang on the cliff
}
}
else if( m_playcontrol[PA_X]>0 && !blockedr)
else if( m_playcontrol[PA_X]>0)
{
xinertia = movespeed;
m_direction = RIGHT;
if(!blockedr)
{
xinertia = movespeed;
m_direction = RIGHT;
}
else
{
// TODO: check if keen can hang on the cliff
}
}
Uint16 l_x = ( getXLeftPos() + getXRightPos() ) / 2;
......
......@@ -78,6 +78,7 @@ private:
bool m_pfiring;
int m_jumpheight;
bool m_cliff_hanging;
};
}
......
......@@ -155,7 +155,7 @@ void CPlayerWM::finishLevel(Uint16 object)
if(mp_Map->findTile(flag_dest, &x, &y, 2))
{
// spawn the flag
VectorD2<Uint32> src(this->x, this->y);
VectorD2<Uint32> src(getXPosition(), getYPosition());
VectorD2<Uint32> dst((x<<CSF), (y<<CSF));
CFlag *pFlag = new CFlag(mp_Map, src, dst);
......
......@@ -135,6 +135,7 @@ void CBallJack::getShotByRay()
{
case DUPRIGHT: m_Direction = DUPLEFT; break;
case DDOWNRIGHT: m_Direction = DDOWNLEFT; break;
default : break;
}
}
else
......@@ -143,6 +144,7 @@ void CBallJack::getShotByRay()
{
case DUPLEFT: m_Direction = DUPRIGHT; break;
case DDOWNLEFT: m_Direction = DDOWNRIGHT; break;
default : break;
}
}
}
......
#include "CFireBall.h"
#include "../../../sdl/sound/CSound.h"
#include "sdl/sound/CSound.h"
// fireball projectile shot out by Vorticon Mother (Ep3)
......@@ -22,7 +22,8 @@ CRay(p_map, x, y, dir, byType, byID)
blockedl = blockedr = 0;
canbezapped = 1;
if(dir == LEFT)
this->x-=(14<<STC);
m_Pos -= VectorD2<Uint32>(14<<STC,0);
m_speed = (mp_Map->m_Difficulty>1) ? FIREBALL_HARD_SPEED : FIREBALL_SPEED;
sprite = (m_Direction == RIGHT) ? FIREBALL_RIGHT_FRAME : FIREBALL_LEFT_FRAME;
performCollisions();
......
......@@ -76,7 +76,7 @@ void CMessie::process()
{
if (mounted[it_player->m_index])
{
it_player->moveTo(x, y);
it_player->moveTo(m_Pos);
isMounted = true;
}
}
......@@ -96,17 +96,17 @@ void CMessie::process()
{
case NESSIE_SWIMNORMAL:
// arrived at destination?
if ( x > (destx-NESSIE_SPEED/2) &&
x < (destx+NESSIE_SPEED/2) )
if ( getXPosition() > (destx-NESSIE_SPEED/2) &&
getXPosition() < (destx+NESSIE_SPEED/2) )
{
if ( y > (desty-NESSIE_SPEED/2) &&
y < (desty+NESSIE_SPEED/2) )
if ( getYPosition() > (desty-NESSIE_SPEED/2) &&
getYPosition() < (desty+NESSIE_SPEED/2) )
{
nessie_find_next_checkpoint();
// set up/down and left/right direction flags for frame selection
bool goleft = (destx < x);
bool godown = (desty > y);
bool goleft = (destx < getXPosition());
bool godown = (desty > getYPosition());
if(goleft && !godown)
m_direction = LEFTUP;
......@@ -147,14 +147,14 @@ void CMessie::move_nessie()
baseframe = NESSIE_UPRIGHT_FRAME;
// head to destination
if (x < destx)
if (getXPosition() < destx)
moveRight(NESSIE_SPEED);
else if (x > destx)
else if (getXPosition() > destx)
moveLeft(NESSIE_SPEED);
if (y < desty)
if (getYPosition() < desty)
moveDown(NESSIE_SPEED);
else if (y > desty)
else if (getYPosition() > desty)
moveUp(NESSIE_SPEED);
}
......
......@@ -25,9 +25,6 @@ m_speed(speed)
else if(Episode == 2) sprite = OBJ_RAY_DEFSPRITE_EP2;
else if(Episode == 3) sprite = OBJ_RAY_DEFSPRITE_EP3;
this->x=x;
this->y=y;
CSprite &rSprite = g_pGfxEngine->getSprite(sprite);
bboxX1 = rSprite.m_bboxX1; bboxX2 = rSprite.m_bboxX2;
bboxY1 = rSprite.m_bboxY1; bboxY2 = rSprite.m_bboxY2;
......@@ -113,9 +110,9 @@ void CRay::moveinAir()
{
// don't go through bonklethal tiles, even if they're not solid
// (for the arms on mortimer's machine)
if (TileProperties.at(mp_Map->at(((x>>(CSF-4))+raysprite.getWidth())>>4, (y>>CSF)+1)).behaviour == 1)
if (TileProperties.at(mp_Map->at(((getXPosition()>>(CSF-4))+raysprite.getWidth())>>4, (getYPosition()>>CSF)+1)).behaviour == 1)
hitlethal = true;
else if (TileProperties.at(mp_Map->at(((x>>(CSF-4))+raysprite.getWidth())>>4, ((y>>(CSF-4))+(raysprite.getHeight()-1))>>(CSF-4))).behaviour == 1)
else if (TileProperties.at(mp_Map->at(((getXPosition()>>(CSF-4))+raysprite.getWidth())>>4, ((getYPosition()>>(CSF-4))+(raysprite.getHeight()-1))>>(CSF-4))).behaviour == 1)
hitlethal = true;
else
hitlethal = false;
......@@ -131,9 +128,9 @@ void CRay::moveinAir()
}
else if (m_Direction == LEFT)
{
if (TileProperties.at(mp_Map->at((x-1)>>CSF, (y+1)>>CSF)).behaviour == 1)
if (TileProperties.at(mp_Map->at((getXPosition()-1)>>CSF, (getYPosition()+1)>>CSF)).behaviour == 1)
hitlethal = true;
else if (TileProperties.at(mp_Map->at((x-1)>>CSF, ((y>>(CSF-4))+(raysprite.getHeight()-1))>>(CSF-4))).behaviour == 1)
else if (TileProperties.at(mp_Map->at((getXPosition()-1)>>CSF, ((getYPosition()>>(CSF-4))+(raysprite.getHeight()-1))>>(CSF-4))).behaviour == 1)
hitlethal = true;
else
hitlethal = false;
......
......@@ -6,9 +6,9 @@
#define RAY_AUTO_SPEED 120
#define RAY_ZAPZOT_TIME 10
#include "../../../common/CObject.h"
#include "../../../common/CPlayer.h"
#include "../../../common/objenums.h"
#include "common/CObject.h"
#include "common/CPlayer.h"
#include "common/objenums.h"
#include <vector>
// reference to ../misc.cpp
......
......@@ -282,7 +282,7 @@ void CSectorEffector::se_mortimer_spark()
{
set_mortimer_surprised(true);
g_pGfxEngine->pushEffectPtr(new CVibrate(200));
mp_Map->redrawAt(this->x>>CSF, this->y>>CSF);
mp_Map->redrawAt(getXPosition()>>CSF, getYPosition()>>CSF);
// if there are any sparks left, destroy the spark,
// else destroy mortimer's arms
......
......@@ -6,10 +6,10 @@
*/
#include "CPlayGameVorticon.h"
#include "../ai/CSectorEffector.h"
#include "../../../common/objenums.h"
#include "../../../sdl/sound/CSound.h"
#include "../finale/CTantalusRay.h"
#include "engine/vorticon/ai/CSectorEffector.h"
#include "common/objenums.h"
#include "sdl/sound/CSound.h"
#include "engine/vorticon/finale/CTantalusRay.h"
void CPlayGameVorticon::processInLevel()
{
......
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