Commit 8a58449c authored by Gerhard Stein's avatar Gerhard Stein

Wormmouth Class filled and enemy seems to work pretty well

parent 14a495e5
......@@ -260,6 +260,26 @@ bool CSpriteObject::hitdetectWithTilePropertyRect(const Uint16 Property, int &lx
}
bool CSpriteObject::turnAroundOnCliff( int x1, int x2, int y2 )
{
std::vector<CTileProperties> &TileProperty = g_pBehaviorEngine->getTileProperties();
// This is a special case for foes which can turn around when they walk over an edge before they fall
if( !TileProperty[mp_Map->at((x1-(1<<STC))>>CSF, (y2+(1<<STC))>>CSF)].bup ||
!TileProperty[mp_Map->at((x2+(1<<STC))>>CSF, (y2+(1<<STC))>>CSF)].bup )
{
blockedl = TileProperty[mp_Map->at((x2+(1<<STC))>>CSF, (y2+(1<<STC))>>CSF)].bup;
blockedr = TileProperty[mp_Map->at((x1-(1<<STC))>>CSF, (y2+(1<<STC))>>CSF)].bup;
return 1;
}
return 0;
}
/**
* \brief this new type of hit detection only checks if the foe touches something that has that property
* \param Property The Tile Property we are looking
......
......@@ -177,6 +177,8 @@ public:
// The object can hold events process them here!
void processEvents();
bool turnAroundOnCliff( int x1, int x2, int y2 );
bool hitdetect(CSpriteObject &hitobject);
bool hitdetectWithTilePropertyRect(const Uint16 Property, int &lx, int &ly, int &lw, int &lh, const int res);
bool hitdetectWithTileProperty(const int Property, const int x, const int y);
......
......@@ -116,9 +116,19 @@ void CPoisonSlug::getTouchedBy(CSpriteObject &theObject)
}
int CPoisonSlug::checkSolidD( int x1, int x2, int y2, const bool push_mode )
{
turnAroundOnCliff( x1, x2, y2 );
return CSpriteObject::checkSolidD(x1, x2, y2, push_mode);
}
void CPoisonSlug::process()
{
performCollisions();
processFalling();
(this->*mp_processState)();
if( blockedl )
......
......@@ -33,6 +33,7 @@ public:
*/
void processPooing();
int checkSolidD( int x1, int x2, int y2, const bool push_mode );
void process();
......
......@@ -6,14 +6,173 @@
*/
#include "CWormmouth.h"
#include "engine/galaxy/ai/CPlayerBase.h"
#include "misc.h"
namespace galaxy {
const int A_WORMMOUTH_MOVE = 0;
const int A_WORMMOUTH_LOOK = 1;
const int A_WORMMOUTH_EAT = 9;
const int A_WORMMOUTH_STUNNED = 14;
const int DIST_TO_EAT = 2<<CSF;
const int LOOK_TIMER = 10;
CWormmouth::CWormmouth(CMap *pmap, const Uint16 foeID, Uint32 x, Uint32 y) :
CStunnable(pmap, foeID, x, y)
CStunnable(pmap, foeID, x, y),
mTurnAround(false),
mTimer(0)
{
mActionMap[A_WORMMOUTH_MOVE] = (void (CStunnable::*)()) &CWormmouth::processMoving;
mActionMap[A_WORMMOUTH_LOOK] = (void (CStunnable::*)()) &CWormmouth::processLooking;
mActionMap[A_WORMMOUTH_EAT] = (void (CStunnable::*)()) &CWormmouth::processEating;
mActionMap[A_WORMMOUTH_STUNNED] = &CStunnable::processGettingStunned;
setupGalaxyObjectOnMap(0x26DE, A_WORMMOUTH_MOVE);
m_hDir = LEFT;
}
bool CWormmouth::isNearby(CSpriteObject &theObject)
{
if(dead || theObject.dead )
return false;
if( CPlayerBase *player = dynamic_cast<CPlayerBase*>(&theObject) )
{
const int playerX = player->getXMidPos();
const int playerY = player->getYMidPos();
const int wormmouthX = getXMidPos();
const int wormmouthY = getYMidPos();
if( getActionNumber(A_WORMMOUTH_LOOK) )
{
if( playerX < wormmouthX && m_hDir != LEFT )
mTurnAround = true;
else if( playerX > wormmouthX && m_hDir != RIGHT )
mTurnAround = true;
}
const int diffX = playerX - wormmouthX;
const int diffY = playerY - wormmouthY;
if( abs(diffX) < DIST_TO_EAT && abs(diffY) < DIST_TO_EAT
&& !getActionNumber(A_WORMMOUTH_EAT) )
{
setAction(A_WORMMOUTH_EAT);
playSound( SOUND_WORMOUTH_STRIKE );
}
}
return true;
}
void CWormmouth::getTouchedBy(CSpriteObject &theObject)
{
if(dead || theObject.dead )
return;
CStunnable::getTouchedBy(theObject);
// Was it a bullet? Than make it stunned.
if( dynamic_cast<CBullet*>(&theObject) )
{
setAction( A_WORMMOUTH_STUNNED );
dead = true;
theObject.dead = true;
processActionRoutine();
performCollisions();
processGettingStunned();
}
if( !getActionNumber(A_WORMMOUTH_EAT) )
return;
if( CPlayerBase *player = dynamic_cast<CPlayerBase*>(&theObject) )
{
player->kill();
}
}
void CWormmouth::processMoving()
{
// TODO Auto-generated constructor stub
if( mTurnAround )
{
if( m_hDir == LEFT )
m_hDir = RIGHT;
else
m_hDir = LEFT;
mTurnAround = false;
setAction( A_WORMMOUTH_LOOK );
}
if( mTimer < LOOK_TIMER )
{
mTimer++;
return;
}
else
{
mTimer = 0;
}
if( getProbability(30) )
setAction( A_WORMMOUTH_LOOK );
}
void CWormmouth::processLooking()
{
if( getActionStatus(A_WORMMOUTH_MOVE) )
setAction(A_WORMMOUTH_MOVE);
}
void CWormmouth::processEating()
{
if( getActionStatus(A_WORMMOUTH_MOVE) )
setAction(A_WORMMOUTH_MOVE);
}
int CWormmouth::checkSolidD( int x1, int x2, int y2, const bool push_mode )
{
turnAroundOnCliff( x1, x2, y2 );
return CSpriteObject::checkSolidD(x1, x2, y2, push_mode);
}
void CWormmouth::process()
{
if( getActionNumber(A_WORMMOUTH_MOVE) || getActionNumber(A_WORMMOUTH_STUNNED) )
{
performCollisions();
processFalling();
}
(this->*mp_processState)();
if( getActionNumber(A_WORMMOUTH_STUNNED) )
return;
if( blockedl )
m_hDir = RIGHT;
else if(blockedr)
m_hDir = LEFT;
processActionRoutine();
}
} /* namespace galaxy */
......@@ -16,6 +16,21 @@ class CWormmouth : public CStunnable
{
public:
CWormmouth(CMap *pmap, const Uint16 foeID, Uint32 x, Uint32 y);
bool isNearby(CSpriteObject &theObject);
void getTouchedBy(CSpriteObject &theObject);
int checkSolidD( int x1, int x2, int y2, const bool push_mode );
void process();
void processMoving();
void processLooking();
void processEating();
private:
bool mTurnAround;
int mTimer;
};
} /* namespace galaxy */
......
......@@ -87,18 +87,7 @@ void CButler::getTouchedBy(CVorticonSpriteObject &theObject)
int CButler::checkSolidD( int x1, int x2, int y2, const bool push_mode )
{
CSpriteObject::checkSolidD(x1, x2, y2, push_mode);
std::vector<CTileProperties> &TileProperty = g_pBehaviorEngine->getTileProperties();
turnAroundOnCliff( x1, x2, y2 );
// This is a special case for foes which can turn around when they walk over an edge before they fall
if( !TileProperty[mp_Map->at((x1-(1<<STC))>>CSF, (y2+(1<<STC))>>CSF)].bup ||
!TileProperty[mp_Map->at((x2+(1<<STC))>>CSF, (y2+(1<<STC))>>CSF)].bup )
{
blockedl = TileProperty[mp_Map->at((x2+(1<<STC))>>CSF, (y2+(1<<STC))>>CSF)].bup;
blockedr = TileProperty[mp_Map->at((x1-(1<<STC))>>CSF, (y2+(1<<STC))>>CSF)].bup;
return 1;
}
return 0;
return CSpriteObject::checkSolidD(x1, x2, y2, push_mode);
}
......@@ -16,7 +16,7 @@ const int NESSIE_PATH = 8192;
const int NESSIE_WEED = 8448;
const int NESSIE_LAND = 8704;
const int NESSIETRAILLEN = 5;
const unsigned int NESSIETRAILLEN = 5;
class CMessie : public CVorticonSpriteObject
{
......
......@@ -195,19 +195,8 @@ void CTank::getTouchedBy(CVorticonSpriteObject &theObject)
int CTank::checkSolidD( int x1, int x2, int y2, const bool push_mode )
{
CSpriteObject::checkSolidD(x1, x2, y2, push_mode);
std::vector<CTileProperties> &TileProperty = g_pBehaviorEngine->getTileProperties();
turnAroundOnCliff( x1, x2, y2 );
// This is a special case for foes which can turn around when they walk over an edge before they fall
if( !TileProperty[mp_Map->at((x1-(1<<STC))>>CSF, (y2+(1<<STC))>>CSF)].bup ||
!TileProperty[mp_Map->at((x2+(1<<STC))>>CSF, (y2+(1<<STC))>>CSF)].bup )
{
blockedl = TileProperty[mp_Map->at((x2+(1<<STC))>>CSF, (y2+(1<<STC))>>CSF)].bup;
blockedr = TileProperty[mp_Map->at((x1-(1<<STC))>>CSF, (y2+(1<<STC))>>CSF)].bup;
return 1;
}
return 0;
return CSpriteObject::checkSolidD(x1, x2, y2, push_mode);
}
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