Commit e27ccdd4 authored by Gerhard Stein's avatar Gerhard Stein

Blue Bird fully working now!

parent b1bae2f9
......@@ -23,7 +23,7 @@
struct ActionFormatType {
int16_t Left_sprite; // 124-400
int16_t Right_sprite; // 124-400
int16_t Movement_parameter; // 0-3
int16_t Movement_parameter; // 0-4
int16_t Change_h; // 0/1
int16_t Change_v; // 0/1
int16_t Delay; // (Anim speed) 0-8000
......
......@@ -42,6 +42,8 @@
#include "engine/galaxy/ai/ep4/CSkypest.h"
#include "engine/galaxy/ai/ep4/CMimrock.h"
#include "engine/galaxy/ai/ep4/CEgg.h"
#include "engine/galaxy/ai/ep4/CBlueBird.h"
// General stuff
#include "engine/galaxy/ai/CSpriteItem.h"
......@@ -428,7 +430,10 @@ CGalaxySpriteObject* CMapLoaderGalaxy::addFoe(CMap &Map, word foe, size_t x, siz
case 13:
// This is an egg
// TODO: Those relative coordinates are not a good sign. Try to remove them and make the Sprite substract them
p_newfoe = new galaxy::CEgg(&Map, foe, x, y-(2<<CSF));
if( g_pBehaviorEngine->mDifficulty > 1 )
p_newfoe = new galaxy::CBlueBird(&Map, foe, x, y-(2<<CSF));
else
p_newfoe = new galaxy::CEgg(&Map, foe, x, y-(2<<CSF));
break;
......
/*
* CBlueBird.cpp
*
* Created on: 11.07.2012
* Author: gerstong
*/
#include "CBlueBird.h"
#include "engine/galaxy/ai/CPlayerLevel.h"
#include "engine/galaxy/ai/CBullet.h"
#include "misc.h"
namespace galaxy {
const int A_EAGLE_HATCHED = 0;
const int A_EAGLE_WALKING = 1;
const int A_EAGLE_FLYING = 5;
const int A_EAGLE_STUNNED = 10;
const int WALK_SPEED = 34;
const int FLY_SPEED = 34;
const int CHANCETOFLY = 50;
const int CHANCETOSTAND = 50;
CBlueBird::CBlueBird(CMap *pmap, const Uint16 foeID, Uint32 x, Uint32 y) :
CGalaxySpriteObject(pmap, foeID, x, y),
mTimer(0)
{
mActionMap[A_EAGLE_HATCHED] = &CBlueBird::processHatched;
mActionMap[A_EAGLE_WALKING] = &CBlueBird::processWalking;
mActionMap[A_EAGLE_WALKING+1] = &CBlueBird::processWalking;
mActionMap[A_EAGLE_FLYING] = &CBlueBird::processFlying;
mActionMap[A_EAGLE_STUNNED] = &CBlueBird::processStunned;
setupGalaxyObjectOnMap( 0x21B6, A_EAGLE_HATCHED );
m_hDir = LEFT;
CSprite &rSprite = g_pGfxEngine->getSprite(sprite);
performCollisions();
processMove( 0, rSprite.m_bboxY1-rSprite.m_bboxY2 );
processActionRoutine();
}
void CBlueBird::setActionForce(const size_t ActionNumber)
{
CGalaxySpriteObject::setActionForce(ActionNumber);
if( mActionMap.find(ActionNumber) != mActionMap.end() )
mpProcessState = mActionMap[ActionNumber];
else
setActionForce(0); // This might happen, when the action-map is incomplete
}
bool CBlueBird::isNearby(CSpriteObject &theObject)
{
if( !getProbability(80) )
return false;
if( CPlayerLevel *player = dynamic_cast<CPlayerLevel*>(&theObject) )
{
if( player->getXMidPos() < getXMidPos() )
m_hDir = LEFT;
else
m_hDir = RIGHT;
if( player->getYMidPos() < getYMidPos() )
m_vDir = UP;
else
m_vDir = DOWN;
}
return true;
}
void CBlueBird::processHatched()
{
if( getActionStatus(A_EAGLE_WALKING) )
setAction(A_EAGLE_WALKING);
}
void CBlueBird::processWalking()
{
if( mTimer % CHANCETOFLY == 0 )
{
// Chance to poo
if( getProbability(30) )
{
setAction(A_EAGLE_FLYING);
inhibitfall = true;
}
}
mTimer++;
// Move normally in the direction
if( m_hDir == RIGHT )
moveRight( WALK_SPEED );
else
moveLeft( WALK_SPEED );
}
void CBlueBird::processFlying()
{
if(inhibitfall)
{
if( mTimer % CHANCETOFLY == 0 )
{
// Chance to land
if( getProbability(20) )
inhibitfall = false;
}
mTimer++;
// Move normally in the direction
if( m_hDir == RIGHT )
moveRight( FLY_SPEED );
else
moveLeft( FLY_SPEED );
if( m_vDir == UP )
moveUp( FLY_SPEED );
else
moveDown( FLY_SPEED );
}
else
{
if(blockedd)
setAction(A_EAGLE_WALKING);
}
}
void CBlueBird::processStunned()
{
//Put some stun time here
if( getActionStatus(A_EAGLE_WALKING) )
setAction(A_EAGLE_WALKING);
}
void CBlueBird::getTouchedBy(CSpriteObject &theObject)
{
if( theObject.dead )
return;
if( CBullet *bullet = dynamic_cast<CBullet*>(&theObject) )
{
bullet->setAction(A_KEENSHOT_IMPACT);
bullet->playSound( SOUND_SHOT_HIT );
bullet->dead = true;
inhibitfall = false;
setAction(A_EAGLE_STUNNED);
}
if( CPlayerBase *player = dynamic_cast<CPlayerBase*>(&theObject) )
{
player->kill();
}
}
void CBlueBird::process()
{
performCollisions();
processFalling();
if( blockedl )
m_hDir = RIGHT;
else if( blockedr )
m_hDir = LEFT;
if( blockedu )
m_vDir = DOWN;
else if( blockedu )
m_vDir = UP;
(this->*mpProcessState)();
processActionRoutine();
}
} /* namespace galaxy */
/*
* CBlueBird.h
*
* Created on: 11.07.2012
* Author: gerstong
*/
#ifndef CBLUEBIRD_H_
#define CBLUEBIRD_H_
#include "engine/galaxy/CGalaxySpriteObject.h"
namespace galaxy {
class CBlueBird: public CGalaxySpriteObject
{
public:
CBlueBird(CMap *pmap, const Uint16 foeID, Uint32 x, Uint32 y);
void setActionForce(const size_t ActionNumber);
bool isNearby(CSpriteObject &theObject);
void processHatched();
void processWalking();
void processFlying();
void processStunned();
void getTouchedBy(CSpriteObject &theObject);
void process();
private:
void (CBlueBird::*mpProcessState)();
std::map< size_t, void (CBlueBird::*)() > mActionMap;
int mTimer;
};
} /* namespace galaxy */
#endif /* CBLUEBIRD_H_ */
......@@ -243,8 +243,6 @@ void CBounder::process()
performCollisions();
processFalling();
(this->*mp_processState)();
if( blockedl )
......
......@@ -8,6 +8,7 @@
#include "CEgg.h"
#include "engine/galaxy/ai/CPlayerLevel.h"
#include "engine/galaxy/ai/CBullet.h"
#include "engine/galaxy/ai/ep4/CBlueBird.h"
namespace galaxy
{
......@@ -31,11 +32,12 @@ void CEgg::hatch()
setAction(A_EGG_BROKEN);
setActionSprite();
// Create
// Create the shards.
CEgg *shard1 = new CEgg( getMapPtr(), mFoeID, getXMidPos(), getYMidPos()-(8<<STC) );
CEgg *shard2 = new CEgg( getMapPtr(), mFoeID, getXMidPos(), getYMidPos()-(8<<STC) );
CEgg *shard3 = new CEgg( getMapPtr(), mFoeID, getXMidPos(), getYMidPos()-(8<<STC) );
// Some impulse values for the shards when Egg is shot
shard1->xinertia = -70;
shard1->yinertia = -60;
shard2->xinertia = -100;
......@@ -54,6 +56,9 @@ void CEgg::hatch()
g_pBehaviorEngine->m_EventList.add( new EventSpawnObject( shard1 ) );
g_pBehaviorEngine->m_EventList.add( new EventSpawnObject( shard2 ) );
g_pBehaviorEngine->m_EventList.add( new EventSpawnObject( shard3 ) );
CBlueBird *blueBird = new CBlueBird( getMapPtr(), mFoeID, getXMidPos(), getYMidPos() );
g_pBehaviorEngine->m_EventList.add( new EventSpawnObject( blueBird ) );
}
......
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