16,203
社区成员
发帖
与我相关
我的任务
分享
if ( m_pCharacter->pos( ).y( ) > 20.0 )
{
qDebug( "AI go Up." );
m_pCharacter->SetAnimation( Character::_Up_ );
emit TriggerTransition( );
}
else if ( m_pCharacter->pos( ).x( ) < 608.0 )
{
qDebug( "AI go Right." );
m_pCharacter->SetAnimation( Character::_Right_ );
emit TriggerTransition( );
}
else if ( m_pCharacter->pos( ).y( ) < 340.0 )
{
qDebug( "AI go Down." );
m_pCharacter->SetAnimation( Character::_Down_ );
emit TriggerTransition( );
}
else if ( m_pCharacter->pos( ).x( ) > 0.0 )
{
qDebug( "AI go Left." );
m_pCharacter->SetAnimation( Character::_Left_ );
emit TriggerTransition( );
}
if ( m_pCharacter->pos( ).y( ) > 20.0 &&
m_pCharacter->m_Direction != Character::_Down_ )
{
qDebug( "AI go Up." );
m_pCharacter->SetAnimation( Character::_Up_ );
emit TriggerTransition( );
}
else if ( m_pCharacter->pos( ).x( ) < 608.0 &&
m_pCharacter->m_Direction != Character::_Left_ )
{
qDebug( "AI go Right." );
m_pCharacter->SetAnimation( Character::_Right_ );
emit TriggerTransition( );
}
else if ( m_pCharacter->pos( ).y( ) < 340.0 &&
m_pCharacter->m_Direction != Character::_Up_ )
{
qDebug( "AI go Down." );
m_pCharacter->SetAnimation( Character::_Down_ );
emit TriggerTransition( );
}
else if ( m_pCharacter->pos( ).x( ) > 0.0 &&
m_pCharacter->m_Direction != Character::_Right_ )
{
qDebug( "AI go Left." );
m_pCharacter->SetAnimation( Character::_Left_ );
emit TriggerTransition( );
}
if ( m_pCharacter->pos( ).y( ) > 20.0 &&
m_pCharacter->m_Direction != Character::_Down_ &&
m_pCharacter->m_Direction != Character::_Left_ )
{
qDebug( "AI go Up." );
m_pCharacter->SetAnimation( Character::_Up_ );
emit TriggerTransition( );
}
else if ( m_pCharacter->pos( ).x( ) < 608.0 &&
m_pCharacter->m_Direction != Character::_Left_ )
{
qDebug( "AI go Right." );
m_pCharacter->SetAnimation( Character::_Right_ );
emit TriggerTransition( );
}
else if ( m_pCharacter->pos( ).y( ) < 340.0 )
{
qDebug( "AI go Down." );
m_pCharacter->SetAnimation( Character::_Down_ );
emit TriggerTransition( );
}
else if ( m_pCharacter->pos( ).x( ) > 0.0 )
{
qDebug( "AI go Left." );
m_pCharacter->SetAnimation( Character::_Left_ );
emit TriggerTransition( );
}
else if ( m_pCharacter->pos( ).x( ) == 0.0 )// 为防止角色在左下角卡死设立的判断
{
m_pCharacter->SetDirection( Character::_Up_ );
}
class Clause: public QObject
{
public:
Clause( Character* pParent = 0 ):
QObject( pParent ), m_pCharacter( pParent ){ }
virtual bool JudgeSentence( void ) = 0;
virtual void Statement( void ) = 0;
protected:
Character* m_pCharacter;
};
QQueue<Clause*> m_Clauses;
class DirUpClause: public Clause
{
public:
DirUpClause( Character* pParent = 0 ): Clause( pParent )
{
}
bool JudgeSentence( void )
{
return m_pCharacter->pos( ).y( ) > 20.0;
}
void Statement( void )
{
qDebug( "AI go Up." );
m_pCharacter->SetAnimation( Character::_Up_ );
}
};
class DirDownClause: public Clause
{
public:
DirDownClause( Character* pParent = 0 ): Clause( pParent )
{
}
bool JudgeSentence( void )
{
return m_pCharacter->pos( ).y( ) < 340.0;
}
void Statement( void )
{
qDebug( "AI go Down." );
m_pCharacter->SetAnimation( Character::_Down_ );
}
};
class DirLeftClause: public Clause
{
public:
DirLeftClause( Character* pParent = 0 ): Clause( pParent )
{
}
bool JudgeSentence( void )
{
return m_pCharacter->pos( ).x( ) > 0.0;
}
void Statement( void )
{
qDebug( "AI go Left." );
m_pCharacter->SetAnimation( Character::_Left_ );
}
};
class DirRightClause: public Clause
{
public:
DirRightClause( Character* pParent = 0 ): Clause( pParent )
{
}
bool JudgeSentence( void )
{
return m_pCharacter->pos( ).x( ) < 608.0;
}
void Statement( void )
{
qDebug( "AI go Right." );
m_pCharacter->SetAnimation( Character::_Right_ );
}
};
foreach ( Clause* pClause, m_Clauses )
{
if ( pClause->JudgeSentence( ) )
{
pClause->Statement( );
emit TriggerTransition( );
break;
}
else
{
m_Clauses.dequeue( );
m_Clauses.enqueue( pClause );
break;
}
}