坦克大战的源代码~做的很好~很适合研究~~不错~
源代码在线查看: tank.cpp
// Tank.cpp: implementation of the CTank class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Tank.h"
#include "Ai.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CTank::CTank()
{
Init();
}
CTank::~CTank()
{
}
RECT CTank::GetTankRect()
{
m_rect.left=ScreenXY.x+1;
m_rect.top=ScreenXY.y+1;
m_rect.right=m_rect.left+m_width-2;
m_rect.bottom=m_rect.top+m_height-2;
return m_rect;
}
void CTank::Init()
{
way=1; //坦克面向
m_width=m_height=32; //大小
BmpX=BmpY=0; //图片位置
MoveSpeed=1; //移动速率
m_MoveX=m_MoveY=MoveSpeed; //X\Y方向的移动速度
ScreenXY.x=ScreenXY.y=0; //屏幕坐标
dead=false; //死亡
BoomNow=false; //爆炸
fire=false; //开火
m_hit=false; //碰撞到
MoveStop=false; //没有移动
//坦克物品
// things.kind=0;
// things.ScreenXY.x=0;
// things.ScreenXY.y=0;
// things.show=false;
}
POINT CTank::Move(POINT &StartPoint,int n,int &speed)
{
CAi ai;
way=ai.GetWay(StartPoint,way,n);
switch (way)
{
case 1:
StartPoint.y+=speed;
BmpY=32;
break;
case 2:
StartPoint.x+=speed;
BmpY=96;
break;
case 3:
StartPoint.y-=speed;
BmpY=0;
break;
case 4:
StartPoint.x-=speed;
BmpY=64;
break;
default :
break;
}
return StartPoint;
}