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

📄 actionprocess.cpp

📁 游戏框架
💻 CPP
字号:
// ***************************************************************
//  ActionProcess   version:  1.0
//  -------------------------------------------------------------
//	File Name:	ActionProcess.cpp
//	Created:	2007/07/18
//	Modified:	2007/07/18   16:54
//	Author:		William.Liang
//  Msn:		lwq49@msn.com
//  Email:		lwq49@21cn.com, lwq49@msn.com
//	Description:
//
//	Purpose:	
//  -------------------------------------------------------------
//  license:
//
//  The contents of this file are subject to the Mozilla Public
//  License Version 1.1 (the "License"); you may not use this file
//  except in compliance with the License. You may obtain a copy
//  of the License at http://www.mozilla.org/MPL/ Software dis-
//  tributed under the License is distributed on an "AS IS" 
//  basis, WITHOUT WARRANTY OF ANY KIND, either express or im-
//  plied. See the License for the specific language governing
//  rights and limitations under the License.
//
//  The Initial Developer of the Original Code is William.Liang .
//  Copyright (C) 2007 - All Rights Reserved.
// ***************************************************************
#include "StdAfx.h"
#include "ActionProcess.h"

//************************************
// <p>Description: 构造函数</p>
// <p>Parameters:  </p>
// <p>    IGameObject * pIGameObject</p>
// <p>    DWORD dwFrames</p>
// <p>    _POINT Point</p>
//
// <p>Returns:   </p>
//************************************
CActionProcessMove::CActionProcessMove(IGameObject* pIGameObject, DWORD dwFrames, _POINT Point){
	m_pIGameObject	= pIGameObject;							//动作对象
	m_piTarget		= Point;
	m_piCurrent = m_piOriginal = pIGameObject->GetLocalPosition();		//原始坐标

	//计算步长值
	m_piStep.x		= (float)(m_piTarget.x-m_piOriginal.x)/dwFrames;
	m_piStep.y		= (float)(m_piTarget.y-m_piOriginal.y)/dwFrames;
}

//************************************
// <p>Description: 动作处理</p>
// <p>Parameters:  </p>
// <p>    bool bFlag</p>
//
// <p>Returns:   bool</p>
//************************************
bool CActionProcessMove::Process(bool bFlag){
	if(bFlag){
		m_piCurrent.x = (float)m_piTarget.x;	m_piCurrent.y = (float)m_piTarget.y;
	}
	else{
		m_piCurrent.x += m_piStep.x;			m_piCurrent.y += m_piStep.y;
	}
	m_pIGameObject->MoveTo(m_piCurrent);

	return true;
}

//************************************
// <p>Description: 构造函数</p>
// <p>Parameters:  </p>
// <p>    IGameObject * pIGameObject</p>
// <p>    DWORD dwFrames</p>
// <p>    tagProcessTrackParam * lpParam</p>
//
// <p>Returns:   </p>
//************************************
CActionProcessMoveTrack::CActionProcessMoveTrack(IGameObject* pIGameObject, DWORD dwFrames, tagProcessTrackParam* lpParam){
	m_pIGameObject	= pIGameObject;							//动作对象
	m_dwFrameCount	= 0;
	m_wCurrentPoint	= 1;
	m_Params.dwTracks	= lpParam->dwTracks;
	m_Params.pPoints	= new _POINT[m_Params.dwTracks];
	m_Params.pFrames	= new DWORD[m_Params.dwTracks];
	memcpy(m_Params.pPoints, lpParam->pPoints, sizeof(_POINT)*m_Params.dwTracks);
	memcpy(m_Params.pFrames, lpParam->pFrames, sizeof(DWORD)*m_Params.dwTracks);

	//for(int i=1;i<m_Params.dwTracks;i++){
	//	m_Params.pFrames[i] = (m_Params.pFrames[i]+25-1)/25;
	//	IActionProcess*		pIActionProcess = new CActionProcessMove(pIGameObject, m_Params.pFrames[i], m_Params.pPoints[i]);
	//	m_lstSubProcess.Push(pIActionProcess, m_Params.pFrames[i]);
	//}

	//首先移动至起始位置
	pIGameObject->MoveTo(m_Params.pPoints[0]);

	m_Params.pFrames[m_wCurrentPoint] = (m_Params.pFrames[m_wCurrentPoint]+25-1)/25;
	pSubProcess = new CActionProcessMove(pIGameObject, m_Params.pFrames[m_wCurrentPoint], m_Params.pPoints[m_wCurrentPoint]);
}

//************************************
// <p>Description: 动作处理</p>
// <p>Parameters:  </p>
// <p>    bool bFlag</p>
//
// <p>Returns:   bool</p>
//************************************
bool CActionProcessMoveTrack::Process(bool bFlag){
	if(pSubProcess){
		pSubProcess->Process(m_dwFrameCount>=m_Params.pFrames[m_wCurrentPoint]);

		if(m_dwFrameCount++>=m_Params.pFrames[m_wCurrentPoint]){
			m_wCurrentPoint++;
			m_dwFrameCount = 0;

			if(m_wCurrentPoint<m_Params.dwTracks){
				m_Params.pFrames[m_wCurrentPoint] = (m_Params.pFrames[m_wCurrentPoint]+25-1)/25;
				SafeDelete(pSubProcess);
				pSubProcess = new CActionProcessMove(m_pIGameObject, m_Params.pFrames[m_wCurrentPoint], m_Params.pPoints[m_wCurrentPoint]);
			}
			else{
				SafeDelete(pSubProcess);
			}
		}
	}
	//if(m_lstSubProcess.GetCount()>0){
	//	IActionProcess*		pIActionProcess	= m_lstSubProcess.Get(1);
	//	DWORD				dwFrames = m_lstSubProcess.GetKey(1);
	//	if(pIActionProcess){
	//		pIActionProcess->Process(bFlag);
	//	}

	//	if(m_dwFrameCount==dwFrames){
	//		if(pIActionProcess){
	//			SafeDelete(pIActionProcess);
	//		}
	//		m_lstSubProcess.Remove(1);
	//		m_dwFrameCount = 0;
	//	}
	//	else{
	//		m_dwFrameCount++;
	//	}
	//}
	return true;
}


//************************************
// <p>Description: 构造函数</p>
// <p>Parameters:  </p>
// <p>    IGameObject * pIGameObject</p>
// <p>    DWORD dwFrames</p>
// <p>    tagProcessAngleParam * lpParam</p>
//
// <p>Returns:   </p>
//************************************
CActionProcessAngle::CActionProcessAngle(IGameObject* pIGameObject, DWORD dwFrames, tagProcessAngleParam* lpParam){
	m_pIGameObject	= pIGameObject;									//动作对象
	m_fCurrent = m_fOriginal = pIGameObject->GetAngle();			//原始角度
	m_nState		= 0;
	memcpy(&m_Params, lpParam, sizeof(m_Params));

	//计算步长值
	if(m_Params.bVibrating){
		//从原点至起始,再到结束后返回原点
		m_fStep		= (float)(m_Params.fStart)*4/dwFrames;
	}
	else{
		//从起始至结束
		m_fStep		= (float)(m_Params.fEnd-m_Params.fStart)/dwFrames;
		m_pIGameObject->SetAngle(m_Params.fStart);
	}
}

//************************************
// <p>Description: 动作处理</p>
// <p>Parameters:  </p>
// <p>    bool bFlag</p>
//
// <p>Returns:   bool</p>
//************************************
bool CActionProcessAngle::Process(bool bFlag){
	if(bFlag){
		if(m_Params.bVibrating){
			m_fCurrent		= 0;
		}
		else{
			m_fCurrent		= m_Params.fEnd;
		}
	}
	else{
		if(m_Params.bVibrating){
			switch(m_nState){
				case 0:			//原点至开始点
					if(abs(m_fCurrent)>abs(m_Params.fStart)){
						m_fStep		= -m_fStep;		//反转步长值
						m_nState	= 1;
						m_fCurrent	= m_Params.fStart;
					}
					else{
						m_fCurrent		+= m_fStep;
					}
					break;
				case 1:			//开始点至结束点
					if(abs(m_fCurrent)>abs(m_Params.fEnd)){
						m_fStep		= -m_fStep;		//反转步长值
						m_nState	= 2;
						m_fCurrent	= m_Params.fEnd;
					}
					else{
						m_fCurrent		+= m_fStep;
					}
					break;
				case 2:			//结束点至原点
					if(abs(m_fCurrent)>=0){
						m_fCurrent	= 0;
					}
					else{
						m_fCurrent		+= m_fStep;
					}
					break;
			}
		}
		else{
			m_fCurrent		+= m_fStep;
		}
	}
	m_pIGameObject->SetAngle(m_fCurrent);

	return true;
}

//************************************
// <p>Description: 构造函数</p>
// <p>Parameters:  </p>
// <p>    IGameObject * pIGameObject</p>
// <p>    DWORD dwFrames</p>
// <p>    tagProcessVibratingParam * lpParam</p>
//
// <p>Returns:   </p>
//************************************
CActionProcessVibrating::CActionProcessVibrating(IGameObject* pIGameObject, DWORD dwFrames, tagProcessVibratingParam* lpParam){
	m_pIGameObject	= pIGameObject;							//动作对象
	m_fOriginal		= pIGameObject->GetAngle();				//原始角度
	m_dwFrameCount	= 0;
	memcpy(&m_Params, lpParam, sizeof(m_Params));

	DWORD	dwPreFrames = dwFrames/(m_Params.nFrequency+1);
	tagProcessAngleParam	AngleParam;
	//计算每次振动的衰减值
	for(int i=0;i<m_Params.nFrequency;i++){
		AngleParam.bVibrating	= true;
		AngleParam.fStart		= m_Params.fStart-(m_Params.fStart/m_Params.nFrequency)*i;
		AngleParam.fEnd			= AngleParam.fStart;
		IActionProcess*		pIActionProcess = new CActionProcessAngle(pIGameObject, dwPreFrames, &AngleParam);

		m_lstSubProcess.Push(pIActionProcess, dwPreFrames);
	}
}

//************************************
// <p>Description: 动作处理</p>
// <p>Parameters:  </p>
// <p>    bool bFlag</p>
//
// <p>Returns:   bool</p>
//************************************
bool CActionProcessVibrating::Process(bool bFlag){
	if(m_lstSubProcess.GetCount()>0){
		IActionProcess*		pIActionProcess	= m_lstSubProcess.Get(1);
		DWORD				dwFrames = m_lstSubProcess.GetKey(1);
		if(pIActionProcess){
			pIActionProcess->Process(bFlag);
		}

		if(m_dwFrameCount==dwFrames){
			if(pIActionProcess){
				SafeDelete(pIActionProcess);
			}
			m_lstSubProcess.Remove(1);
			m_dwFrameCount = 0;
		}
		else{
			m_dwFrameCount++;
		}
	}
	return true;
}

//************************************
// <p>Description: 构造函数</p>
// <p>Parameters:  </p>
// <p>    IGameObject * pIGameObject</p>
// <p>    DWORD dwFrames</p>
// <p>    _SIZE Size</p>
//
// <p>Returns:   </p>
//************************************
CActionProcessScaling::CActionProcessScaling(IGameObject* pIGameObject, DWORD dwFrames, _SIZE Size){
	m_pIGameObject	= pIGameObject;							//动作对象
	m_siTarget		= Size;									//目标坐标
	m_siCurrent = m_siOriginal = pIGameObject->GetSize();	//原始坐标

	//计算步长值
	m_siStep.cx		= (float)(m_siTarget.cx-m_siOriginal.cx)/dwFrames;
	m_siStep.cy		= (float)(m_siTarget.cy-m_siOriginal.cy)/dwFrames;
}

//************************************
// <p>Description: 动作处理</p>
// <p>Parameters:  </p>
// <p>    bool bFlag</p>
//
// <p>Returns:   bool</p>
//************************************
bool CActionProcessScaling::Process(bool bFlag){
	if(bFlag){
		m_siCurrent.cx = (float)m_siTarget.cx;
		m_siCurrent.cy = (float)m_siTarget.cy;
	}
	else{
		m_siCurrent.cx += m_siStep.cx;
		m_siCurrent.cy += m_siStep.cy;
	}
	m_pIGameObject->SetScaling(m_siCurrent);

	return true;
}

⌨️ 快捷键说明

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