⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ballengine.cpp

📁 一个symbian上成熟的小游戏源码
💻 CPP
字号:
// BallEngine.cpp: implementation of the CBallEngine class.
//
//////////////////////////////////////////////////////////////////////

#include "BallEngine.h"
#include <aknutils.h>
#include "Balls.mbg"
_LIT(KBallsMbm,"Balls.mbm");
//#include "GGBallEnv.h"
#include <e32math.h>

CBallEngine::CBallEngine()
{

}

CBallEngine::~CBallEngine()
{
	TInt count=iArray.Count();
	for (TInt i=0;i<count;i++)
	{
		delete iArray[i];
	}
	iArray.Close();

	count=iArrayBmps.Count();
	for (i=0;i<count;i++)
	{
		delete iArrayBmps[i];
	}
	iArrayBmps.Close();
}

void CBallEngine::Draw( CBitmapContext& aGc ) const
{
	TInt count=iArray.Count();

	if (count==1)
	{
		iArray[0]->CollideWithActiveRect();
		iArray[0]->Draw(aGc);
		iArray[0]->NextFrame();
	}
	else
	{
		for (TInt i=0;i<count;i++)
		{
			for (TInt j=0;j<count;j++)
			{
				if (j!=i)
				{
					iArray[i]->CollideWithBall(*iArray[j]);
					iArray[i]->CollideWithActiveRect();
				}
			}

			iArray[i]->Draw(aGc);
			iArray[i]->NextFrame();
		}
	}
}

CBallEngine* CBallEngine::NewL()
{
	CBallEngine* self=CBallEngine::NewLC();
	CleanupStack::Pop();
	return self;
}

void CBallEngine::ConstructL()
{
	
}

CBallEngine* CBallEngine::NewLC()
{
	CBallEngine* self=new(ELeave)CBallEngine;
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
}

void CBallEngine::CreateBall()
{
	TFileName mbmFileName(KBallsMbm);
	CompleteWithAppPath(mbmFileName);//z
	RDebug::Print(mbmFileName);
	
#ifdef __WINS__
	_LIT(KC,"c");
	mbmFileName.Replace(0,1,KC);
#endif

	CFbsBitmap* bmp = new (ELeave) CFbsBitmap();
	TInt loadRet=bmp->Load(mbmFileName, EMbmBallsBall);//如果加载图片失败...,EMbmGgballBan01_m
	if (loadRet!=KErrNone)
	{
		delete bmp;
		bmp=NULL;
	}
	else
	{
		iArrayBmps.Append(bmp);
	}
	
	CFbsBitmap* bmpMask = new (ELeave) CFbsBitmap();
	loadRet=bmpMask->Load(mbmFileName, EMbmBallsBall_mask);//如果加载图片失败...,EMbmGgballBan01_m
	if (loadRet!=KErrNone)
	{
		delete bmpMask;
		bmpMask=NULL;
	}
	else
	{
		iArrayBmps.Append(bmpMask);
	}

	CBall* ball=CBall::NewL(bmp,bmpMask,50,50);
	ball->SetPosition(iRect.iTl);
	ball->SetActiveRect(iRect);
	const TInt number=3;
	TInt sequence[number] = {0,5,10};
	ball->SetSequence( sequence,number );

	TTime theTime;
	theTime.UniversalTime(); 
	TInt64 seed(theTime.Int64());
	Math::Rand(seed);
	ball->SetSpeed(seed.High()%3+1,seed.Low()%3+1);

	iArray.Append(ball);
}

void CBallEngine::RemoveBall()
{
	TInt count=iArray.Count();
	if (count>0)
	{
		delete iArray[count-1];
		iArray.Remove(count-1);
	}
}

void CBallEngine::SetRect( const TRect& aRect )
{
	iRect=aRect;	
}

⌨️ 快捷键说明

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