Commit 8676ac88 authored by Gerhard Stein's avatar Gerhard Stein

Thundercloud is now working

parent b55a24d5
......@@ -424,7 +424,8 @@ void CSpriteObject::draw()
///
// Cleanup Routine
///
CSpriteObject::~CSpriteObject() {
CSpriteObject::~CSpriteObject()
{
if(m_number_of_objects > 0)
m_number_of_objects--;
}
......
......@@ -17,6 +17,7 @@ class CBaseEngine
{
public:
virtual ~CBaseEngine() {}
virtual void init() = 0;
virtual void process() = 0;
......
......@@ -147,10 +147,10 @@ struct EventSendSelectionDialogMsg : CEvent {
*/
struct EventSpawnObject : CEvent {
const CGalaxySpriteObject* pObject;
const CGalaxySpriteObject *pObject;
EventSpawnObject( const CGalaxySpriteObject* pObject ) :
pObject(pObject) {}
pObject( pObject ) {}
};
......
......@@ -25,7 +25,8 @@ const int STRIKE_TIME = 80;
CThunderCloud::CThunderCloud(CMap *pmap, const Uint16 foeID, Uint32 x, Uint32 y) :
CGalaxySpriteObject(pmap, foeID, x, y),
mTimer(0)
mTimer(0),
mpBolt(NULL)
{
mActionMap[A_CLOUD_ASLEEP] = &CThunderCloud::processAsleep;
mActionMap[A_CLOUD_WAKING] = &CThunderCloud::processWaking;
......@@ -83,7 +84,7 @@ bool CThunderCloud::isNearby(CSpriteObject &theObject)
m_hDir = RIGHT;
}
if( player->getYMidPos() > getYMidPos() )
if( mpBolt == NULL && player->getYMidPos() > getYMidPos() )
{
const unsigned int playXStrikeLeft = player->getXMidPos() - DIST_TO_STRIKE;
const unsigned int playXStrikeRight = player->getXMidPos() + DIST_TO_STRIKE;
......@@ -94,6 +95,8 @@ bool CThunderCloud::isNearby(CSpriteObject &theObject)
getProbability(90) )
{
setAction(A_CLOUD_STRIKING);
mpBolt = new CThunderBolt( mp_Map, getXLeftPos() + (12<<STC), getYDownPos()-(1<<STC) );
g_pBehaviorEngine->m_EventList.add( new EventSpawnObject( mpBolt ) );
}
......@@ -116,9 +119,6 @@ void CThunderCloud::processWaking()
void CThunderCloud::processMoving()
{
if( getActionStatus(A_CLOUD_STRIKING) )
setAction(A_CLOUD_STRIKING);
// Move normally in the direction
if( m_hDir == RIGHT )
moveRight( MOVE_SPEED );
......@@ -131,7 +131,7 @@ void CThunderCloud::processStriking()
if( getActionStatus(A_CLOUD_STRIKING+1) )
setAction(A_CLOUD_STRIKING);
if( mTimer % STRIKE_TIME == 0)
if( mpBolt == NULL && mTimer % STRIKE_TIME == 0)
{
setAction(A_CLOUD_MOVING);
setActionSprite();
......@@ -142,6 +142,12 @@ void CThunderCloud::processStriking()
void CThunderCloud::process()
{
if( mpBolt )
{
if(!mpBolt->exists)
mpBolt = NULL; // This can be done because the object container will care deleting the it.
}
performCollisions();
processFalling();
......@@ -159,4 +165,36 @@ void CThunderCloud::process()
}
/**
* The thunderbold itself.
*/
const int A_LIGHTNING_STRIKE = 0;
CThunderBolt::CThunderBolt(CMap *pmap,Uint32 x, Uint32 y) :
CGalaxySpriteObject(pmap, 0, x, y)
{
setupGalaxyObjectOnMap(0x2A44, A_LIGHTNING_STRIKE);
inhibitfall = false;
}
void CThunderBolt::getTouchedBy(CSpriteObject &theObject)
{
if(theObject.dead )
return;
if( CPlayerBase *player = dynamic_cast<CPlayerBase*>(&theObject) )
{
player->kill();
}
}
void CThunderBolt::process()
{
performCollisions();
processActionRoutine();
}
} /* namespace galaxy */
......@@ -9,10 +9,24 @@
#define CTHUNDERCLOUD_H_
#include "engine/galaxy/CGalaxySpriteObject.h"
#include "SmartPointer.h"
namespace galaxy
{
class CThunderBolt: public CGalaxySpriteObject
{
public:
CThunderBolt(CMap *pmap, Uint32 x, Uint32 y);
void getTouchedBy(CSpriteObject &theObject);
void process();
};
class CThunderCloud: public CGalaxySpriteObject
{
public:
......@@ -34,7 +48,9 @@ private:
void (CThunderCloud::*mpProcessState)();
std::map< size_t, void (CThunderCloud::*)() > mActionMap;
int mTimer;
CThunderBolt *mpBolt;
};
} /* namespace galaxy */
#endif /* CTHUNDERCLOUD_H_ */
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