64,685
社区成员
发帖
与我相关
我的任务
分享
#include "stdafx.h"
#include "GMap.h"
enum TW{UP,DOWN,LEFT,RIGHT,OVER};
class GObject
{
protected:
POINT point;
TW tw;
int speed;
int frame;
int dArray;
int dRow;
bool Achive();
void AchiveCtrl();
int PtTransform(int k);
bool Collision();
public:
void virtual action()=0;
void virtual Draw(HDC &hdc)=0;
void DrawBlank(HDC &hdc);
static GMap* pStage;
GObject(int x,int y)
{
point.x=x;
point.y=y;
speed=3;
frame=1;
}
};
class PacMan:public GObject
{
public:
void Draw(HDC &hdc);
void action();
PacMan(int x,int y):GObject(x,y)
{
}
};
int GObject::PtTransform(int k)
{
return (k-(pStage->LD)/2)/pStage->LD;
}
void GObject::AchiveCtrl()
{
if(Achive())
{
dArray=PtTransform(point.x);
dRow=PtTransform(point.y);
}
}
bool GObject::Collision()
{
bool b=true;
AchiveCtrl();
if(dArray<0||dRow<0||dArray>MAPLENTH||dRow>MAPLENTH)
{
b=false;
}
if(Achive())
{
switch(tw)
{
case LEFT:
{
if(dArray>0&&pStage->mapData[dRow][dArray-1])
{
b=false;
}
break;
}
case RIGHT:
{
if(dArray<MAPLENTH-1&&pStage->mapData[dRow][dArray+1])
b=false;
break;
}
case UP:
{
if(dRow>0&&pStage->mapData[dRow-1][dArray])
b=false;
break;
}
case DOWN:
{
if(dRow<MAPLENTH&&pStage->mapData[dRow+1][dArray])
b=false;
break;
}
}
if(b)
{
switch(tw)
{
case LEFT:
point.x-=speed;
break;
case RIGHT:
point.x+=speed;
break;
case UP:
point.y-=speed;
break;
case DOWN:
point.y+=speed;
break;
}
}
}
return b;
}