兄弟姐妹帮忙给看下,谢谢,急!

pcant 2004-08-27 12:48:25
帮忙看看这样人物为什么不能动,3Q.

类声明role.h

#if !defined(AFX_ROLE_H__3BA2727C_065B_4BAE_A8CD_BB932DB46B61__INCLUDED_)
#define AFX_ROLE_H__3BA2727C_065B_4BAE_A8CD_BB932DB46B61__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class Role
{

public:
Role();
Role(int m_x,int m_y);
virtual ~Role();
int GetX() {return x;}
int GetY() {return y;}
void SetLocation(int X,int Y) {x=X;y=Y;}
int GetWidth() { return width;}
int GetHeight() {return height;}
void SetSize(int m_width,int m_height)
{width=m_width;height=m_height;}
bool CanVisible() {return visible;}
void SetVisible(bool v) { visible=v;}
bool CanMove() {return active;}
void SetMove(bool m) {active=m;}
void Move();

private:
int x;//人物x坐标
int y;//y坐标
int width;
int height;
bool visible;
bool active;

int defence;
int attack;
int life;
int level;
int expience;
};

#endif // !defined(AFX_ROLE_H__3BA2727C_065B_4BAE_A8CD_BB932DB46B61__INCLUDED_
)



类实现role.cpp
#include "..\h\Role.h"
#include "../h/DirectDraw.h"
#include "../h/DirectInput.h"

Role::Role()
{
x=400;
y=300;
}

Role::Role(int m_x,int m_y)
{
x=m_x;
y=m_y;
}

Role::~Role()
{

}

void Role::Move()
{
static int mainindex=0;
static int rowindex=0;
//下面是按键处理,如果在此处加上 static int x=Role::GetX();
// static int y=Role::GetY();则按键时,人物可以连续移动,说明其他部分没出错
// 不加为什么不行?不明白
lpDInputkey->GetDeviceState(256, (LPVOID)keyboard_state);
if (keyboard_state[DIK_UP])
{
mainindex=2;//所贴位图的索引号,与问题无关
rowindex++; //.......,同上
Delay(100); //延迟,同上
if(rowindex>2) rowindex=0;
y-=8; //坐标改变量
}
if (keyboard_state[DIK_DOWN])
{
mainindex=0;
rowindex++;
Delay(100);
if(rowindex>2) rowindex=0;
y+=8;
}
if (keyboard_state[DIK_LEFT])
{
mainindex=1;
rowindex++;
Delay(150);
if(rowindex>2) rowindex=0;
x-=8;
}
if (keyboard_state[DIK_RIGHT])
{
mainindex=3;
rowindex++;
Delay(150);
if(rowindex>2) rowindex=0;
x+=8;
}
//判断边界
if( x > 760 )
x = 760;
if( x <= 0 )
x = 1;
if( y > 549 )
y = 549;
if( y <= 0 )
y = 1;

SurfaceToBack(lpDDbboy,rowindex*32,mainindex*48,(rowindex+1)*32,(mainindex
+1)*48,lpDDback,x,y,x+32,y+48);
//最后这个是个贴图函数,就把个图象贴到屏幕上(x,y)坐标的地方

}

看明白的,麻烦给说说:)
...全文
97 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Lonelywolf1899 2004-08-27
  • 打赏
  • 举报
回复
复杂
lemon520 2004-08-27
  • 打赏
  • 举报
回复
调用的问题?
传值?
lemon520 2004-08-27
  • 打赏
  • 举报
回复
上一句算我没说!-_-!
lemon520 2004-08-27
  • 打赏
  • 举报
回复
你的move函数是怎么触发的?
coyprightbao 2004-08-27
  • 打赏
  • 举报
回复
眼睛近视了,不看!
wolftop 2004-08-27
  • 打赏
  • 举报
回复
太简单的东东~!我不看~!
wolftop 2004-08-27
  • 打赏
  • 举报
回复
test(char *******pa){++******pa;}main(){char *******pa;char *a;*****pa=&a;printf("%i\n",a);test(pa);printf("%i",a);}

64,636

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧