car.cpp

来自「本程序是用vc++做的一个模拟交通灯的程序」· C++ 代码 · 共 85 行

CPP
85
字号
// Car.cpp: implementation of the CCar class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "Trafficlight.h"
#include "Car.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CCar::CCar()
{
	m_bmpCar.LoadBitmap(IDB_CAR);
	BITMAP BM;
	m_bmpCar.GetBitmap(&BM);
	m_nHeight=BM.bmHeight;
	m_nWidth=BM.bmWidth;


}

CCar::~CCar()
{

}

CRect CCar::GetCar()
{return CRect(m_pointCar.x,m_pointCar.y,m_pointCar.x+m_nWidth,m_pointCar.y+m_nHeight);


}

void CCar::ChangePos(int tag)
{
	if(m_pointCar.x<-80)
	{
	m_pointCar.x=700;
        m_pointCar.y=400;
	}
	else
	{
		if(tag==0)
		{
			m_pointCar.x-=3;
		}
		else{m_pointCar.x-=6;}
	}
       

		

	

}

void CCar::ResetPos(int tag)
{
	if(tag==0)
	{
		m_pointCar.x=700;
        m_pointCar.y=400;
	}
	if(tag==1)
	{
		m_pointCar.x=200;
	    m_pointCar.y=400;
	}

}

void CCar::ShowCar(CDC *pDC, CDC *pMemDC)
{
	pMemDC->SelectObject(&m_bmpCar);
	pDC->BitBlt(m_pointCar.x,m_pointCar.y,m_nWidth,m_nHeight,pMemDC,0,0,SRCAND);

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?