设为首页 加入收藏

TOP

利用HGE引擎设计的角色部分 (二)
2014-11-24 00:40:17 来源: 作者: 【 】 浏览:104
Tags:利用 HGE 引擎 设计 角色 部分
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

首页 上一页 1 2 3 4 下一页 尾页 2/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇一个C笔试题引出一系列的问题 下一篇深入浅出C指针(一)基本概念

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: