enemy.cpp

来自「一个symbian 冒险游戏代码」· C++ 代码 · 共 1,167 行 · 第 1/4 页

CPP
1,167
字号

	app->enemyAnims[ENEMY_OGRE][ANIM_RUN][DIR_0].loadCustom( expandPath("data/anims/ogre/ogre_walk_e.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_OGRE][ANIM_RUN][DIR_315].loadCustom( expandPath("data/anims/ogre/ogre_walk_se.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_OGRE][ANIM_RUN][DIR_270].loadCustom( expandPath("data/anims/ogre/ogre_walk_s.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_OGRE][ANIM_RUN][DIR_90].loadCustom( expandPath("data/anims/ogre/ogre_walk_n.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_OGRE][ANIM_RUN][DIR_45].loadCustom( expandPath("data/anims/ogre/ogre_walk_ne.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_OGRE][ANIM_RUN][DIR_135] = Surface( app->enemyAnims[ENEMY_OGRE][ANIM_RUN][DIR_45], Surface::FLAG_MIRROR );
	app->enemyAnims[ENEMY_OGRE][ANIM_RUN][DIR_180] = Surface( app->enemyAnims[ENEMY_OGRE][ANIM_RUN][DIR_0], Surface::FLAG_MIRROR );
	app->enemyAnims[ENEMY_OGRE][ANIM_RUN][DIR_225] = Surface( app->enemyAnims[ENEMY_OGRE][ANIM_RUN][DIR_315], Surface::FLAG_MIRROR );
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_RUN, DIR_0, 24, 85 );                 
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_RUN, DIR_315, 25, 81 );               
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_RUN, DIR_270, 25, 87 );
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_RUN, DIR_90, 24, 83 );
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_RUN, DIR_45, 24, 86 );
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_RUN, DIR_225, 25, 81 );
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_RUN, DIR_180, 24, 85 );
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_RUN, DIR_135, 24, 86 );
	
	app->enemyAnims[ENEMY_OGRE][ANIM_ATTACK][DIR_0].loadCustom( expandPath("data/anims/ogre/ogre_hit_e.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_OGRE][ANIM_ATTACK][DIR_315].loadCustom( expandPath("data/anims/ogre/ogre_hit_se.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_OGRE][ANIM_ATTACK][DIR_270].loadCustom( expandPath("data/anims/ogre/ogre_hit_s.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_OGRE][ANIM_ATTACK][DIR_90].loadCustom( expandPath("data/anims/ogre/ogre_hit_n.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_OGRE][ANIM_ATTACK][DIR_45].loadCustom( expandPath("data/anims/ogre/ogre_hit_ne.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_OGRE][ANIM_ATTACK][DIR_135] = Surface( app->enemyAnims[ENEMY_OGRE][ANIM_ATTACK][DIR_45], Surface::FLAG_MIRROR );
	app->enemyAnims[ENEMY_OGRE][ANIM_ATTACK][DIR_180] = Surface( app->enemyAnims[ENEMY_OGRE][ANIM_ATTACK][DIR_0], Surface::FLAG_MIRROR );
	app->enemyAnims[ENEMY_OGRE][ANIM_ATTACK][DIR_225] = Surface( app->enemyAnims[ENEMY_OGRE][ANIM_ATTACK][DIR_315], Surface::FLAG_MIRROR );
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_ATTACK, DIR_0, 28, 95 );                 
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_ATTACK, DIR_315, 46, 86 );               
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_ATTACK, DIR_270, 58, 91 );
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_ATTACK, DIR_90, 36, 100 );
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_ATTACK, DIR_45, 22, 103 );
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_ATTACK, DIR_225, 46, 86 );
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_ATTACK, DIR_180, 28, 95 );
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_ATTACK, DIR_135, 22, 103 );

	app->enemyAnims[ENEMY_OGRE][ANIM_HIT][DIR_0].loadCustom( expandPath("data/anims/ogre/ogre_gethit_e.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_OGRE][ANIM_HIT][DIR_315].loadCustom( expandPath("data/anims/ogre/ogre_gethit_se.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_OGRE][ANIM_HIT][DIR_270].loadCustom( expandPath("data/anims/ogre/ogre_gethit_s.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_OGRE][ANIM_HIT][DIR_90].loadCustom( expandPath("data/anims/ogre/ogre_gethit_n.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_OGRE][ANIM_HIT][DIR_45].loadCustom( expandPath("data/anims/ogre/ogre_gethit_ne.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_OGRE][ANIM_HIT][DIR_135] = Surface( app->enemyAnims[ENEMY_OGRE][ANIM_HIT][DIR_45], Surface::FLAG_MIRROR );
	app->enemyAnims[ENEMY_OGRE][ANIM_HIT][DIR_180] = Surface( app->enemyAnims[ENEMY_OGRE][ANIM_HIT][DIR_0], Surface::FLAG_MIRROR );
	app->enemyAnims[ENEMY_OGRE][ANIM_HIT][DIR_225] = Surface( app->enemyAnims[ENEMY_OGRE][ANIM_HIT][DIR_315], Surface::FLAG_MIRROR );
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_HIT, DIR_0, 40, 100 );                 
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_HIT, DIR_315, 35, 90 );               
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_HIT, DIR_270, 39, 88 );
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_HIT, DIR_90, 36, 100 );
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_HIT, DIR_45, 37, 94 );
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_HIT, DIR_225, 37, 99 );
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_HIT, DIR_180, 40, 100 );
	app->setEnemyAnimationReferencePoint(ENEMY_OGRE, ANIM_HIT, DIR_135, 37, 94 );

	//Hell Beast
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_IDLE][DIR_0].loadCustom( expandPath("data/anims/hellbeast/hellbeast_idle_e.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_IDLE][DIR_315].loadCustom( expandPath("data/anims/hellbeast/hellbeast_idle_se.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_IDLE][DIR_270].loadCustom( expandPath("data/anims/hellbeast/hellbeast_idle_s.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_IDLE][DIR_90].loadCustom( expandPath("data/anims/hellbeast/hellbeast_idle_n.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_IDLE][DIR_45].loadCustom( expandPath("data/anims/hellbeast/hellbeast_idle_ne.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_IDLE][DIR_135] = Surface( app->enemyAnims[ENEMY_HELLBEAST][ANIM_IDLE][DIR_45], Surface::FLAG_MIRROR );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_IDLE][DIR_180] = Surface( app->enemyAnims[ENEMY_HELLBEAST][ANIM_IDLE][DIR_0], Surface::FLAG_MIRROR );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_IDLE][DIR_225] = Surface( app->enemyAnims[ENEMY_HELLBEAST][ANIM_IDLE][DIR_315], Surface::FLAG_MIRROR );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_IDLE, DIR_0, 26, 103 );                 
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_IDLE, DIR_315, 44, 99 );               
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_IDLE, DIR_270, 45, 98 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_IDLE, DIR_90, 44, 100 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_IDLE, DIR_45, 39, 100 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_IDLE, DIR_225, 44, 99 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_IDLE, DIR_180, 26, 103 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_IDLE, DIR_135, 39, 100 );

	app->enemyAnims[ENEMY_HELLBEAST][ANIM_DEATH][DIR_0].loadCustom( expandPath("data/anims/hellbeast/hellbeast_death_e.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_DEATH][DIR_315].loadCustom( expandPath("data/anims/hellbeast/hellbeast_death_se.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_DEATH][DIR_270].loadCustom( expandPath("data/anims/hellbeast/hellbeast_death_s.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_DEATH][DIR_90].loadCustom( expandPath("data/anims/hellbeast/hellbeast_death_n.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_DEATH][DIR_45].loadCustom( expandPath("data/anims/hellbeast/hellbeast_death_ne.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_DEATH][DIR_135] = Surface( app->enemyAnims[ENEMY_HELLBEAST][ANIM_DEATH][DIR_45], Surface::FLAG_MIRROR );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_DEATH][DIR_180] = Surface( app->enemyAnims[ENEMY_HELLBEAST][ANIM_DEATH][DIR_0], Surface::FLAG_MIRROR );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_DEATH][DIR_225] = Surface( app->enemyAnims[ENEMY_HELLBEAST][ANIM_DEATH][DIR_315], Surface::FLAG_MIRROR );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_DEATH, DIR_0, 140, 98 );                 
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_DEATH, DIR_315, 131, 98 );               
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_DEATH, DIR_270, 42, 81 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_DEATH, DIR_90, 42, 108 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_DEATH, DIR_45, 111, 113 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_DEATH, DIR_225, 131, 98 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_DEATH, DIR_180, 140, 98 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_DEATH, DIR_135, 111, 113 );
	
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_RUN][DIR_0].loadCustom( expandPath("data/anims/hellbeast/hellbeast_walk_e.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_RUN][DIR_315].loadCustom( expandPath("data/anims/hellbeast/hellbeast_walk_se.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_RUN][DIR_270].loadCustom( expandPath("data/anims/hellbeast/hellbeast_walk_s.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_RUN][DIR_90].loadCustom( expandPath("data/anims/hellbeast/hellbeast_walk_n.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_RUN][DIR_45].loadCustom( expandPath("data/anims/hellbeast/hellbeast_walk_ne.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_RUN][DIR_135] = Surface( app->enemyAnims[ENEMY_HELLBEAST][ANIM_RUN][DIR_45], Surface::FLAG_MIRROR );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_RUN][DIR_180] = Surface( app->enemyAnims[ENEMY_HELLBEAST][ANIM_RUN][DIR_0], Surface::FLAG_MIRROR );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_RUN][DIR_225] = Surface( app->enemyAnims[ENEMY_HELLBEAST][ANIM_RUN][DIR_315], Surface::FLAG_MIRROR );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_RUN, DIR_0, 43, 101 );                 
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_RUN, DIR_315, 44, 93 );               
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_RUN, DIR_270, 41, 98 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_RUN, DIR_90, 40, 98 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_RUN, DIR_45, 44, 103 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_RUN, DIR_225, 44, 93 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_RUN, DIR_180, 43, 101 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_RUN, DIR_135, 44, 103 );

	app->enemyAnims[ENEMY_HELLBEAST][ANIM_ATTACK][DIR_0].loadCustom( expandPath("data/anims/hellbeast/hellbeast_hit_e.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_ATTACK][DIR_315].loadCustom( expandPath("data/anims/hellbeast/hellbeast_hit_se.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_ATTACK][DIR_270].loadCustom( expandPath("data/anims/hellbeast/hellbeast_hit_s.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_ATTACK][DIR_90].loadCustom( expandPath("data/anims/hellbeast/hellbeast_hit_n.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_ATTACK][DIR_45].loadCustom( expandPath("data/anims/hellbeast/hellbeast_hit_ne.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_ATTACK][DIR_135] = Surface( app->enemyAnims[ENEMY_HELLBEAST][ANIM_ATTACK][DIR_45], Surface::FLAG_MIRROR );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_ATTACK][DIR_180] = Surface( app->enemyAnims[ENEMY_HELLBEAST][ANIM_ATTACK][DIR_0], Surface::FLAG_MIRROR );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_ATTACK][DIR_225] = Surface( app->enemyAnims[ENEMY_HELLBEAST][ANIM_ATTACK][DIR_315], Surface::FLAG_MIRROR );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_ATTACK, DIR_0, 46, 108 );                 
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_ATTACK, DIR_315, 46, 100 );               
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_ATTACK, DIR_270, 45, 100 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_ATTACK, DIR_90, 45, 103 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_ATTACK, DIR_45, 40, 106 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_ATTACK, DIR_225, 46, 100 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_ATTACK, DIR_180, 46, 108 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_ATTACK, DIR_135, 46, 106 );

	app->enemyAnims[ENEMY_HELLBEAST][ANIM_HIT][DIR_0].loadCustom( expandPath("data/anims/hellbeast/hellbeast_gethit_e.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_HIT][DIR_315].loadCustom( expandPath("data/anims/hellbeast/hellbeast_gethit_se.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_HIT][DIR_270].loadCustom( expandPath("data/anims/hellbeast/hellbeast_gethit_s.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_HIT][DIR_90].loadCustom( expandPath("data/anims/hellbeast/hellbeast_gethit_n.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_HIT][DIR_45].loadCustom( expandPath("data/anims/hellbeast/hellbeast_gethit_ne.nan"), resampler, halfRes );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_HIT][DIR_135] = Surface( app->enemyAnims[ENEMY_HELLBEAST][ANIM_HIT][DIR_45], Surface::FLAG_MIRROR );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_HIT][DIR_180] = Surface( app->enemyAnims[ENEMY_HELLBEAST][ANIM_HIT][DIR_0], Surface::FLAG_MIRROR );
	app->enemyAnims[ENEMY_HELLBEAST][ANIM_HIT][DIR_225] = Surface( app->enemyAnims[ENEMY_HELLBEAST][ANIM_HIT][DIR_315], Surface::FLAG_MIRROR );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_HIT, DIR_0, 48, 111 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_HIT, DIR_315, 67, 99 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_HIT, DIR_270, 42, 86 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_HIT, DIR_90, 42, 103 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_HIT, DIR_45, 56, 109 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_HIT, DIR_225, 67, 99 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_HIT, DIR_180, 48, 111 );
	app->setEnemyAnimationReferencePoint(ENEMY_HELLBEAST, ANIM_HIT, DIR_135, 56, 109 );

	for ( int i = 0 ; i < ENEMY_COUNT ; ++i )
		for ( int k = 0 ; k < DIR_COUNT ; ++k )
		{
			app->enemyAnims[i][ANIM_ATTACK][k].setEndBehaviorStop();
			app->enemyAnims[i][ANIM_HIT][k].setEndBehaviorStop();
			app->enemyAnims[i][ANIM_DEATH][k].setEndBehaviorStop();
		}
}

void Enemy::deinitStatic()
{
	GameApp* app = GameApp::get();

	for ( int k = 0 ; k < ENEMY_COUNT ; ++k )
		for ( int i = 0 ; i < BODY_COUNT ; ++i )
		{
			app->enemyAnims[k][i][MapObject::DIR_0].destroy();
			app->enemyAnims[k][i][MapObject::DIR_45].destroy();
			app->enemyAnims[k][i][MapObject::DIR_90].destroy();
			app->enemyAnims[k][i][MapObject::DIR_270].destroy();
			app->enemyAnims[k][i][MapObject::DIR_315].destroy();
		}
}

bool Enemy::isInState( const char* statename )
{
	if ( m_state == BODY_IDLE )
	{
		if ( strcmp( statename, "IDLE" ) == 0 ) return true;
	}
	else if ( m_state == BODY_RUN )
	{
		if ( strcmp( statename, "RUN" ) == 0 ) return true;
	}
	else if ( m_state == BODY_ATTACK )
	{
		if ( strcmp( statename, "ATTACK" ) == 0 ) return true;
	}
	else if ( m_state == BODY_BACKUP )
	{
		if ( strcmp( statename, "BACKUP" ) == 0 ) return true;
	}
	else if ( m_state == BODY_HIT )
	{
		if ( strcmp( statename, "GETHIT" ) == 0 ) return true;
	}
	else if ( m_state == BODY_DEATH )
	{
		if ( strcmp( statename, "DEATH" ) == 0 ) return true;
	}
	else if ( m_state == BODY_DEAD )
	{
		if ( strcmp( statename, "DEAD" ) == 0 ) return true;
	}

	if ( m_behavior == BEHAVIOR_PATROL )
	{
		if ( strcmp( statename, "PATROL" ) == 0 ) return true;
	}
	else if ( m_behavior == BEHAVIOR_COMBAT )
	{
		if ( strcmp( statename, "COMBAT" ) == 0 ) return true;
	}
	else if ( m_behavior == BEHAVIOR_FLEE )
	{
		if ( strcmp( statename, "FLEE" ) == 0 ) return true;
	}

	return false;
}

FixVec2 Enemy::blockRenderPositionReference() const
{
	return m_map->pixelToBlock( FixVec2( m_pos.x, m_pos.y ) );
}

FixVec2 Enemy::blockRenderPositionExtreme() const
{
	bool lowerHalf, oddBlock;
	FixVec2 lowRightPoint = renderPositionLow( SIDE_RIGHT );
	FixVec2 block = m_map->pixelToBlock( lowRightPoint, 0, &lowerHalf, &oddBlock );
	if ( lowerHalf )
	{
		// point located on the lower half of the block: need to check left
		FixVec2 left = m_map->pixelToBlock( renderPositionLow( SIDE_LEFT ) );
		if ( ( left.x != block.x ) || ( left.y != block.y ) )
		{
			// exceeding the boundary of the block located below and on the left, which is a latter block:
			// need to change the rendering position there to maintain correct drawing order
			block.y += Fix::fromInt( 1 );
			if ( !oddBlock ) block.x -= Fix::fromInt( 1 );
		}
	}

	return block;
}

FixVec2 Enemy::renderPositionLow( int side ) const
{
	const bool halfResolution = GameApp::get()->isHalfResolution();
	const int xSign = ( side < 0 ) ? -1 : ( side > 0 ) ? 1 : 0;
	int refX, refY;
	const Surface& anim = bodyAnim( &refX, &refY );
	if ( anim.mirror() ) refX = -refX;
	const int frameHalfWidth = anim.frameWidth() >> 1;
	const int frameHeight = anim.frameHeight();
	const int barHalfWidth = m_maxHitPoints.toInt() >> 2;
	const int barHeight = 6;

	int hpx = position().x.toInt();
	int hpy = position().y.toInt();
	int x0 = position().x.toInt() - refX;
	int y0 = position().y.toInt() - refY;
	int shiftX = anim.mirror() ? ( -anim.offsetX() - anim.frameWidth() ) : anim.offsetX();
	int shiftY = anim.offsetY();
	shiftX += frameHalfWidth;
	x0 += shiftX;
	y0 += shiftY;
	if ( halfResolution )
	{
		x0 += shiftX;
		y0 += shiftY;
	}

	int x1 = x0 + frameHalfWidth * xSign;
	int y1 = y0 + frameHeight;
	int hpx1 = hpx + barHalfWidth * xSign;
	int hpy1 = hpy + barHeight;
	if ( halfResolution )
	{
		x1 += frameHalfWidth * xSign;
		y1 += frameHeight;
		hpx1 += barHalfWidth * xSign;
		hpy1 += barHeight;
	}

	if ( xSign > 0 )
	{
		// right
		if ( hpx1 > x1 ) x1 = hpx1;
	}
	else if ( xSign < 0 )
	{
		// left
		if ( hpx1 < x1 ) x1 = hpx1;
	}
	if ( hpy1 > y1 ) y1 = hpy1;
	
	return FixVec2( Fix::fromInt(x1), Fix::fromInt(y1) );
}

// End of file

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?