www.gusucode.com > VC++游戏雷霆战机源代码-源码程序 > VC++游戏雷霆战机源代码-源码程序\code\BkGround.cpp

    // BkGround.cpp: implementation of the CBkGround class.
// Download by http://www.NewXing.com
//////////////////////////////////////////////////////////////////////

#include "BkGround.h"

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

CBkGround::CBkGround(CDirectWnd* win)
{
	m_win = win;
	yspeed = 0;

	m_T0=0;
	m_T1=0;
	m_c=0;
	m_fps=0;
}

CBkGround::~CBkGround()
{
	m_win = NULL;
}

void CBkGround::Run()
{
	RECT rtSrc,rtDest;
	bkPic = m_win->lpBKGObject[1];
	for( int i = 0 ; i < 4 ; i++ )
	{
		m_win->GetRect(&rtSrc,0,200-yspeed,200,yspeed);
		m_win->GetRect(&rtDest,200*i,0,200,yspeed);
		m_win->BltBitMap(bkPic,&rtSrc,&rtDest);
	}
	for( i = 0 ; i < 4 ; i++ )
	{
		m_win->GetRect(&rtDest,200*i,yspeed,200,200);
		m_win->BltBitMap(bkPic,NULL,&rtDest);
	}
	for( i = 0 ; i < 4 ; i++ )
	{
		m_win->GetRect(&rtDest,200*i,200+yspeed,200,200);
		m_win->BltBitMap(bkPic,NULL,&rtDest);
	}
	for( i = 0 ; i < 4 ; i++ )
	{
		m_win->GetRect(&rtSrc,0,0,200,200-yspeed);
		m_win->GetRect(&rtDest,200*i,400+yspeed,200,200-yspeed);
		m_win->BltBitMap(bkPic,&rtSrc,&rtDest);
	}

	yspeed += 1;
	if ( 200 == yspeed ) yspeed = 0; 

	
	m_T1 = timeGetTime();  //获得现在的时间,以毫秒为单位(从开机到现在经过了多少毫秒)
    m_c++;                 //这个函数的执行次数
	if( (m_T1-m_T0)>999 )  //如果m_T1-m_T0超过1000毫秒(1秒)
	{
		m_fps=m_c*1000/(m_T1-m_T0);  //这秒内执行了多少次(帧速率)
		m_c=0;                       //计数器清零
		m_T0 = m_T1;                 //
	}
	m_win->ShowText(10,0,m_fps);
	m_win->ShowText(35,0,"帧/秒");
}