⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cplayer.cpp

📁 一个3D的保龄球的源代码
💻 CPP
字号:
/**
* <p>Title: class CPlayer</p>
* <p>Description: The action control and state switch of player with controlled
* by user. Also include of properties of player.</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: Gameloft ShangHai</p>
* @author Tao Qing, Wei XIA
* @version 1.0
*/

#include "CPlayer.h"


CPlayer::CPlayer():CObject(OBJ_PLAYER) {
	m_playerType = 0;
	m_strength = 0;
	m_precision = 0;
	m_rotation = 0;
	m_mentation = 1;
	//Level attribute
	m_currentLevel =1;

	restart();
	m_tipsyDegree = 0;
	m_currentState = 0;
	
	m_iFoulType = FOUL_TYPE_NONE;	
	m_iClothesId = 0;
}


CPlayer::CPlayer(int playerType, int strength = 0, int precision = 0, 
				 int rotation = 0, int mentation = 0, int currentLevel = 0)
		:CObject(OBJ_PLAYER) 
{
	m_playerType = playerType;
	m_strength = strength;
	m_precision = precision;
	m_rotation = rotation;
	m_mentation = mentation;
	//Level attribute
	m_currentLevel = currentLevel;
	restart();
	m_tipsyDegree = 0;
	m_currentState = 0;
	m_iClothesId = 0;
}

void CPlayer::restart() {
	m_iCurFrame  = 1;
	m_vPos.x = PLAYER_POSITION_X;
	m_vPos.y = PLAYER_POSITION_Y;	
	m_vPos.z = PLAYER_POSITION_Z;

	m_vRot.x = PLAYER_ROTATION_X;
	m_vRot.y = PLAYER_ROTATION_Y;
	m_vRot.z = PLAYER_ROTATION_Z;

	
	m_curPower = 0;

	m_precision = 0;	
	
	m_count = 0;
	m_animationOption = 0;

	m_iFoulType = FOUL_TYPE_NONE;
	m_iMovingStep = 0;
	m_iAniPlayingBack = 0;

}
CPlayer::~CPlayer() {
}

int CPlayer::StrengthChanging(int ballWeight)
{
	int old = m_curPower;
	m_curPower += getPowerLevel(ballWeight);
	if (m_curPower>100 && old < 100)
		m_curPower = 100;
	if (m_curPower >= 200 ) //(60 * (10-m_currentLevel*2))/10)
	{
		m_curPower = 0;
	}
	return m_curPower;
}


void CPlayer::SetCurrentPower(int ballWeight)
{
	int power = m_curPower > 100?200-m_curPower:m_curPower;
	m_curPower = power;

	int foulpower = 80;//FOUL_POWER(ballWeight);
	m_iFoulAnimType = FOUL_ANIM_NONE;
	if(power > foulpower) 
	{
		if(power > 90)
		{
			int i = getRandomNumber(100);
			i%=2;
			if(  i== 0 )
			{
				m_iFoulAnimType = FOUL_LINE_ANIM;
				m_vPos.y = PLAYER_POSITION_Y + 35 ;		
			}
			else
			{
				m_iFoulAnimType = FOUL_TRIP_ANIM;
			}
			m_iFoulType = FOUL_TYPE_FOUL;
			m_curPower = 100;
		}
		else
		{
			m_iFoulType = FOUL_TYPE_FASTER_DIRECTION;
			//m_curPower = (m_curPower*100)/80;
		}
	}
	else
	{
		m_curPower = (m_curPower*100)/80;//(100-ballWeight*5);
	}
}


void CPlayer::SetMovingStep(int movingStep)
{
	m_iMovingStep += movingStep;
	m_iMovingStep = m_iMovingStep < 55 ? m_iMovingStep : 55;
}

bool CPlayer::MovingPlayer(bool isLeft)
{	
	bool  ret = FALSE;
	if(m_iMovingStep > 0)
	{
		if(isLeft)
		{	
			if ( (m_vPos.x - 1 ) > -(55 )+(PLAYER_POSITION_X))//LANE_WIDTH / 2 ))
			{
				m_vPos.x -= 1 ; //left moving
				ret = TRUE;
			}
		}
		else
		{	
			if ( (m_vPos.x + 1 ) < (55 )+(PLAYER_POSITION_X))//LANE_WIDTH / 2 )) //Milo 12-03
			{
				m_vPos.x += 1  ; //right moving
				ret = TRUE;
			}
		}
		--m_iMovingStep;
	}
	DBGPRINTF( "PLAYER X: %d", m_vPos.x);
	return ret;
}



int CPlayer::GetCurrentPower()
{
	int ret ;
	ret = m_curPower;
	if (m_curPower > 100)// (60 * (10-m_currentLevel*2)/10)/2)
	{
		ret =  200 - m_curPower;  //(60 * (10-m_currentLevel*2)/10) - m_curPower;
	}
				
	return ret;
}
	
void CPlayer::SetAnimationOption(int animationOption, bool isPlayingBack)
{	
	
	m_iAniPlayingBack = isPlayingBack ? PLAYER_ANI_PLAYING_BACK : 0;  

	if(m_animationOption == PLAYER_ANI_DEPRESSION1 ||m_animationOption == PLAYER_ANI_CHEER1 
		|| m_animationOption == PLAYER_ANI_DEPRESSION2 || m_animationOption == PLAYER_ANI_CHEER2
		|| m_animationOption == PLAYER_ANI_FOULS)
	{
		m_vRot.z -= 1024 ;			
	}
	m_animationOption = animationOption;

	m_iCurFrame = isPlayingBack 
		? m_actionTable[m_animationOption].actionEnd : m_actionTable[m_animationOption].actionStart;	
    m_count = m_iCurFrame;

	if(m_animationOption == PLAYER_ANI_DEPRESSION1 ||m_animationOption == PLAYER_ANI_CHEER1 
		|| m_animationOption == PLAYER_ANI_DEPRESSION2 || m_animationOption == PLAYER_ANI_CHEER2
		|| m_animationOption == PLAYER_ANI_FOULS)
	{
		m_vRot.z += 1024 ;		
	}


}

//return: 0 - finish 1 - not yet 2 - foul -1 - finish with foul
int CPlayer::PlayingAnimation(bool isJump)
{ 
	int ret = PLAYER_ANI_PLAYING;	
	
	if(m_iAniPlayingBack ==PLAYER_ANI_PLAYING_BACK)
	{
		--m_count;
		if(m_iCurFrame > m_actionTable[m_animationOption].actionStart)
		{
			if(m_actionTable[m_animationOption].actionInterval <= (m_iCurFrame - m_count))
			{
				--m_iCurFrame;
				m_count = m_iCurFrame;
				
			}
		}
		else
		{		
			m_iCurFrame = m_actionTable[m_animationOption].actionStart;
			if(m_iFoulType == FOUL_TYPE_FOUL)
			{
				ret = PLAYER_ANI_FOUL_FINISH;
			}
			else
			{
				ret = PLAYER_ANI_FINISH;
			}
			
		}
	}
	else
	{
		++m_count;
		if(m_iCurFrame < m_actionTable[m_animationOption].actionEnd)
		{
			if(m_actionTable[m_animationOption].actionInterval <= (m_count - m_iCurFrame))
			{
				++m_iCurFrame;
				m_count = m_iCurFrame;
				
			}
		}
		else
		{		
			m_iCurFrame = m_actionTable[m_animationOption].actionEnd;
			if(m_iFoulType == FOUL_TYPE_FOUL)
			{
				ret = PLAYER_ANI_FOUL_FINISH;
			}
			else
			{
				ret = PLAYER_ANI_FINISH;
			}
			
		}	
	}
	return ret;
}

int CPlayer::GetStrength()
{
	int ret ;
	ret = m_curPower * m_strength / 100 ;//(m_strength * (10-m_currentLevel*2)/10);//Milo 12-20

	return ret;
}

//return: 0 for no foul; 1 for faster_direction; 2 for FOUL
int CPlayer::GetIsFouls(int ballWeight)
{
	int power = m_curPower > 100?200-m_curPower:m_curPower;

	int foulpower = 80;//FOUL_POWER(ballWeight);
	if(power > foulpower) 
	{		
		if(power > 90)
		{
			m_iFoulType = FOUL_TYPE_FOUL;
		}
		else
		{
			m_iFoulType = FOUL_TYPE_FASTER_DIRECTION;
		}
	}
	else
	{
		m_iFoulType = FOUL_TYPE_NONE;
	}
	return m_iFoulType;
}

int CPlayer::GetAnimationOption()
{
	return m_animationOption;
}

int CPlayer::GetStopFrame()
{
	return m_actionTable[m_animationOption].stopFrame;
}

int CPlayer::getPowerLevel(int ballWeight)
{
	int ret = 0;
	if(ballWeight == 0 || ballWeight == 1)
	{//light ball
		ret = 5;
	}
	else if(ballWeight == 2)
	{//medium ball
		ret = 8;
	}
	else if(ballWeight == 3 || ballWeight == 4)
	{//heavy ball
		ret = 10;
	}
	return ret;
}

⌨️ 快捷键说明

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