xtExp; }
FGMyRole.h文件:
class FGMyRole :public FGRoleObject{public: //基类的参数:1.编号 2.阵营标示 3.角色名称 4.角色X坐标 5.角色Y坐标 //hgeAnimation类需要参数: 6.贴图中的x坐标 7.贴图中的y坐标 8.贴图中每一帧的宽 9.贴图中每一帧的高 // 10.动画播放的速度 11.动画总共的帧数 12.动画所需要的贴图 //我方角色本身的参数: 13.UI中角色人物图片 14.角色的移动的速度 FGMyRole(short _id, TYPE_Camp _camp, char* _name,float _x, float _y, float _tx, float _ty, float _tw, float _th, float _fps, int _nframe, HTEXTURE _tex,short _h_Index, float m_speed); virtual ~FGMyRole(void); void Logic();
void Render();
short GethSpri_UIIndex() { return hSpri_UIIndex; }
//初始化装备槽 void InitEquips();
//装备栏数组-次游戏拥有5个装备槽 ItemObject* Equips[5];
private: //角色头像图片索引(UI ) short hSpri_UIIndex;
//动画对象 hgeAnimation* spr[8];
//fps播放的速度 float FPS;
//帧数 int Nframe;
//贴图中的X坐标 float tx;
//贴图中的Y坐标 float ty;
//贴图中的长 float tw;
//贴图中的宽 float th; };
FGMyRole.cpp文件:
#include "FGMyRole.h"#include "FGGameScreen.h"
FGMyRole::FGMyRole(short _id, TYPE_Camp _camp, char* _name,float _x, float _y, float _tx, float _ty, float _tw, float _th, float _fps, int _nframe, HTEXTURE _tex,short _h_Index, float _speed):FGRoleObject(_id,_camp,_name,_x,_y) { SetAttribute(4,163,163,250,203,44,46,20,15,15,16,4,4,2,46,46,500,100,250);
m_speed = _speed;
FPS = _fps;
Nframe = _nframe;
tx = _tx;
ty = _ty;
tw = _tw;
th = _th;
hSpri_UIIndex = _h_Index;
for(int i=0;i<8;i ) { spr[i] = new hgeAnimation(_tex,Nframe,FPS,tx,ty 128*i,tw,th);
spr[i]->Play(); } m_drection = RIGHT; //初始化角色装备 InitEquips(); }
FGMyRole::~FGMyRole(void){ for(int i=7;i<0;i--) { if(spr[i]!=NULL) { delete spr[i];
spr[i] = NULL; } }}
void FGMyRole::Logic(){ //动画更新 spr[m_drection]->Update(hge->Timer_GetDelta());
//状态 switch(m_ationmode) { case MOVE: //键盘响应 if(hge->Input_GetKeyState(HGEK_W)) //上 { if(hge->Input_GetKeyState(HGEK_D)) { m_y-=m_speed; m_x =m_speed; m_drection = RIGHTUP;
} else if(hge->Input_GetKeyState(HGEK_A)) { m_y-=m_speed; m_x-=m_speed; m_drection = LEFTUP; } else if(hge->Input_GetKeyState(HGEK_S)) { m_y =m_speed;
m_drection = DOWN; } else { m_y-=m_speed;
m_drection = UP; }
spr[m_drection]->SetTexture(FGResMangner::mangner->GetTexture("role2-move1")); } else if(hge->Input_GetKeyState(HGEK_S)) //下 { if(hge->Input_GetKeyState(HGEK_W)) { m_y-=m_speed;
m_drection = UP;
} else if(hge->Input_GetKeyState(HGEK_D)) { m_x =m_speed;
m_y =m_speed;
m_drection = RIGHTDOWN; } else if(hge->Input_GetKeyState(HGEK_A)) { m_x-=m_speed;
m_y =m_speed; m_drection = LEFTDOWN; } else { m_y =m_speed; m_drection = DOWN; } spr[m_drection]->SetTexture(FGResMangner::mangner->GetTexture("role2-move1")); } else if(hge->Input_GetKeyState(HGEK_D)) //右 { if(hge->Input_GetKeyState(HGEK_W)) { m_x =m_speed;
m_y-=m_speed;
m_drection = RIGHTUP; } else if(hge->Input_GetKeyState(HGEK_S)) { m_x =m_speed;
m_y =m_speed;
m_drection = RIGHTDOWN; } else if(hge->Input_GetKeyState(HGEK_A)) { m_x-=m_speed;
m_drection = LEFT; } else { m_x =m_speed; m_drection = RIGHT; } spr[m_drection]->SetTexture(FGResMangner::mangner->GetTexture("role2-move1")); } else if(hge->Input_GetKeyState(HGEK_A)) //左 { if(hge->Input_GetKeyState(HGEK_W)) { m_x-=m_speed;
m_y-=m_speed;
m_drection = LEFTUP; } else if(hge->Input_GetKeyState(HGEK_D)) { m_x =m_speed;
m_drection = RIGHT; } else if(hge->Input_GetKeyState(HGEK_S)) { m_x-=m_speed;
m_y =m_speed;
m_drection = LEFTDOWN; } else { m_x-=m_speed;
m_drection = LEFT; } spr[m_drection]->SetTexture(FGResMangner::mangner->GetTexture("role2-move1")); } else { //在没有任何按键响应时把动画帧数调整为0 spr[m_d