cmodelgame.cpp
来自「Symbian手机游戏,可运行于S60 1.x和2.x下, Carbide.C」· C++ 代码 · 共 2,364 行 · 第 1/4 页
CPP
2,364 行
aGc.SetPenStyle( CGraphicsContext::ENullPen );
aGc.DrawRect(TRect(0,0,iSystem->Width(),iSystem->Height()));
imgIntro->Draw( aTarget, TPoint(0,0) );
aGc.SetPenColor(KRgbWhite);
aGc.SetPenStyle( CGraphicsContext::ESolidPen );
TBuf<20> formatText;
CEikonEnv::Static()->ReadResource( formatText, R_DIJIGUAN );
TBuf<40> text;
text.Format(formatText, level);
TInt w = font->TextWidthInPixels(text);
aGc.DrawText(text, TPoint((iSystem->Width() - w)/2,48));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_HINT );
aGc.DrawText(text,TPoint(24,70));
text.Zero();
if(level==1)
{
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE1 );
aGc.DrawText(text, TPoint(24,92));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE2 );
aGc.DrawText(text, TPoint(24,114));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE3 );
aGc.DrawText(text, TPoint(24,136));
text.Zero();
}
else if(level==2)
{
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE4 );
aGc.DrawText(text, TPoint(24,92));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE5 );
aGc.DrawText(text, TPoint(24,114));
text.Zero();
}
else if(level==3)
{
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE6 );
aGc.DrawText(text, TPoint(24,92));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE7 );
aGc.DrawText(text, TPoint(24,114));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE8 );
aGc.DrawText(text, TPoint(24,136));
text.Zero();
}else if(level==4)
{
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE9 );
aGc.DrawText(text, TPoint(24,92));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE10 );
aGc.DrawText(text, TPoint(24,114));
text.Zero();
}else if(level==5)
{
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE11 );
aGc.DrawText(text, TPoint(24,92));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE12 );
aGc.DrawText(text, TPoint(24,114));
text.Zero();
}else if(level==6)
{
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE13 );
aGc.DrawText(text,TPoint(24,92));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE14 );
aGc.DrawText(text, TPoint(24,114));
text.Zero();
}else if(level==7)
{
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE15 );
aGc.DrawText(text, TPoint(24,92));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE16 );
aGc.DrawText(text, TPoint(24,114));
text.Zero();
}else if(level==8)
{
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE17 );
aGc.DrawText(text, TPoint(24,92));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE18 );
aGc.DrawText(text, TPoint(24,114));
text.Zero();
}else if(level==9)
{
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE19 );
aGc.DrawText(text, TPoint(24,92));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_HINT_LINE20 );
aGc.DrawText(text, TPoint(24,114));
text.Zero();
}
CEikonEnv::Static()->ReadResource( text, R_OK );
aGc.DrawText(text, TPoint(4,iSystem->Height()-22));
aGc.DiscardFont();
}
void CModelGame::DrawBack(CBitmap &aTarget, CFbsBitGc &aGc)
{
aGc.SetBrushStyle( CGraphicsContext::ESolidBrush );
aGc.SetPenStyle( CGraphicsContext::ENullPen );
if ((level-1)/3==0)
{
aGc.SetBrushColor( TRgb(0x8F, 0x5A, 0xFB) );
}
else if((level-1)/3==1)
{
aGc.SetBrushColor( TRgb(0x39, 0x15, 0xC8) );
}
else if((level-1)/3==2)
{
aGc.SetBrushColor( TRgb(0x21, 0x00, 0xA5) );
}
aGc.DrawRect(TRect(0,0,iSystem->Width(),iSystem->Height()));
if(offsetX>0)
{
imgBack[(level-1)/3]->Draw(aTarget,TPoint(-128+offsetX,iSystem->Height()-64+offsetY));
}
imgBack[(level-1)/3]->Draw(aTarget, TPoint(offsetX,iSystem->Height()-64+offsetY));
imgBack[(level-1)/3]->Draw(aTarget, TPoint(128+offsetX,iSystem->Height()-64+offsetY));
}
void CModelGame::DrawSP(CBitmap &aTarget, CFbsBitGc &aGc)
{
for(TInt j=0;j<iSystem->Height();j++)
{
for(TInt i=0;i<70;i++)
{
if(sprite[i].type!=0&&sprite[i].y==j)
{
SP sp=sprite[i];
if(sp.type==PLAYER)
{//绘制主角
if (deadCtr>0)
continue;
if (gameOverCtr>0)
continue;
if (yummyCtr>0)
{
imgYummy->Draw(aTarget,TPoint(player->x+player->width,player->y-imgYummy->Size().iHeight));
if (player->level==SMALL)
{
imgEnemy[(small[level-1]-2)*15]->Draw(aTarget,TPoint(player->x+player->width+10,player->y-imgYummy->Size().iHeight+10));
}
else if (player->level==MIDDLE)
{
imgEnemy[(middle[level-1]-2)*15]->Draw(aTarget, TPoint(player->x+player->width+10,player->y-imgYummy->Size().iHeight+10));
}
else if(player->level==LARGE)
{
imgEnemy[(large[level-1]-2)*15]->Draw(aTarget, TPoint(player->x+player->width+10,player->y-imgYummy->Size().iHeight+10));
}
}
if(newCtr>0)
{
if((newCtr%6)/3==0)
continue;
}
if(player->action==SWIM)
{
if(player->direction==RIGHT)
{
imgPlayer[player->level*11+(counter%9)/3]->Draw(aTarget, TPoint(player->x,player->y));
}
else
{
TInt debug = player->level*11+3+(counter%9)/3;
imgPlayer[player->level*11+3+(counter%9)/3]->Draw(aTarget, TPoint(player->x,player->y));
}
}
else if(player->action==TURN)
{
if(player->ctr>6||player->ctr<3)
{
if(player->direction==RIGHT)
{
imgPlayer[player->level*11+(counter%9)/3]->Draw(aTarget, TPoint(player->x,player->y));
}
else
{
imgPlayer[player->level*11+3+(counter%9)/3]->Draw(aTarget, TPoint(player->x,player->y));
}
}
else
{
imgPlayer[player->level*11+6]->Draw(aTarget, TPoint(player->x,player->y));
}
}
else if (player->action==KILL)
{
imgPlayer[player->level*11+7+player->direction*2+(player->ctr%6)/3]->Draw(aTarget, TPoint(player->x,player->y));
}
else if(player->action==STUN)
{
imgPlayer[player->level*11+player->direction*3]->Draw(aTarget, TPoint(player->x,player->y));
//CBitmap* temp = CBitmap::NewL( TSize(12,6) );
TRect clipRect = TRect(TPoint(12*((counter%6)/3),0), TSize(12,6));
imgStun->SetDrawRect(clipRect);
//imgStun->Draw(*temp, TPoint(sp.x+sp.width/2-6-12*((counter%6)/3),sp.y-6)-TPoint(sp.x+sp.width/2-6,sp.y-6));
//aTarget.SetDrawRect( TRect(TPoint(sp.x+sp.width/2-6,sp.y-6), TSize(12,6)));
//imgStun->Draw(aTarget, TPoint(sp.x+sp.width/2-6-12*((counter%6)/3),sp.y-6));
//aTarget.SetDrawRect( TRect(0,0,iSystem->Width(),iSystem->Height()));
imgStun->Draw(aTarget, TPoint(sp.x+sp.width/2-6,sp.y-6));
/*temp->Destroy();
delete temp;*/
}
}
else if (sp.type>PLAYER)
{
if(sp.type>=2&&sp.type<=12)
{
if(sp.action==MOVENEAR||sp.action==MOVEFAR||sp.action==IDLE||sp.action==SWIM)
{
if(sp.direction==RIGHT)
{
imgEnemy[(sp.type-2)*15+sp.level*5+(counter%6)/3]->Draw(aTarget, TPoint(sp.x,sp.y));
}
else
{
imgEnemy[(sp.type-2)*15+sp.level*5+2+(counter%6)/3]->Draw(aTarget, TPoint(sp.x,sp.y));
}
}else if (sp.action==TURN)
{
if(sp.ctr>6||sp.ctr<3)
{
if(sp.direction==RIGHT)
{
imgEnemy[(sp.type-2)*15+sp.level*5+(counter%6)/3]->Draw(aTarget, TPoint(sp.x,sp.y));
}
else
{
imgEnemy[(sp.type-2)*15+sp.level*5+2+(counter%6)/3]->Draw(aTarget, TPoint(sp.x,sp.y));
}
}
else
{
imgEnemy[(sp.type-2)*15+sp.level*5+4]->Draw(aTarget, TPoint(sp.x,sp.y));
}
}
}
else if(sp.type==SCORE)
{
if(sp.value/100==0)
{
imgScore[2]->Draw(aTarget, TPoint(sp.x,sp.y));
imgScore[sp.value/10+3]->Draw(aTarget, TPoint(sp.x+6,sp.y));
imgScore[3]->Draw(aTarget, TPoint(sp.x+12,sp.y));
}
else
{
imgScore[2]->Draw(aTarget, TPoint(sp.x,sp.y));
imgScore[sp.value/100+3]->Draw(aTarget, TPoint(sp.x+6,sp.y));
imgScore[(sp.value%100)/10+3]->Draw(aTarget, TPoint(sp.x+12,sp.y));
imgScore[3]->Draw(aTarget, TPoint(sp.x+18,sp.y));
}
}
else if(sp.type==PERL)
{
if(sp.action==OPEN)
{
imgPerl[3]->Draw(aTarget, TPoint(sp.x,sp.y));
}
else if(sp.action==CLOSE)
{
imgPerl[2]->Draw(aTarget, TPoint(sp.x,sp.y));
}
else if(sp.action==EAT)
{
if(sp.ctr>5)
{
imgPerl[3]->Draw(aTarget, TPoint(sp.x,sp.y));
}
else
{
imgPerl[2]->Draw(aTarget, TPoint(sp.x,sp.y));
}
}
}
else if(sp.type==BUBBLE1||sp.type==BUBBLE2)
{
//CBitmap* temp = CBitmap::NewL(TSize(10,10));
TInt i = sp.type % 2;
TRect clipRect = TRect( TPoint(i*10,0), TSize(10,10) );
imgBubble->SetDrawRect(clipRect);
//imgBubble->Draw(*temp, TPoint(0, 0));
imgBubble->Draw(aTarget, TPoint(sp.x, sp.y));
/*temp->Destroy();
delete temp;*/
}else if(sp.type==SEASTAR)
{
imgBounus[0]->Draw(aTarget, TPoint(sp.x,sp.y));
}
else if(sp.type==EXTRALIFE)
{
imgBounus[2]->Draw(aTarget, TPoint(sp.x,sp.y));
}
else if(sp.type==DOUBLE)
{
imgBounus[1]->Draw(aTarget, TPoint(sp.x,sp.y));
}
else if(sp.type==SPEED)
{
imgBounus[3]->Draw(aTarget, TPoint(sp.x,sp.y));
}
else if(sp.type==FREEZE)
{
imgBounus[4]->Draw(aTarget, TPoint(sp.x,sp.y));
}
else if(sp.type==SHUIMU)
{
//CBitmap* temp = CBitmap::NewL(TSize(28,35));
//g.setClip(sp.x,sp.y,28,35);
TRect clipRect;
if(sp.ctr>18)
{
//g.drawImage(imgShuimu,sp.x,sp.y,0);
clipRect = TRect( TPoint(0,0), TSize(28,35));
//imgShuimu->Draw(*temp, TPoint(0, 0));
}
else if(sp.ctr>16)
{
clipRect = TRect( TPoint(28,0), TSize(28,35));
//imgShuimu->Draw(*temp, TPoint(-28, 0));
}
else if(sp.ctr>14)
{
clipRect = TRect( TPoint(56,0), TSize(28,35));
//imgShuimu->Draw(*temp, TPoint(-56,0));
}
else if(sp.ctr>7)
{
clipRect = TRect( TPoint(84,0), TSize(28,35));
//imgShuimu->Draw(*temp,TPoint(-84,0));
}
else
{
clipRect = TRect( TPoint(112,0), TSize(28,35));
//imgShuimu->Draw(*temp,TPoint(-112,0));
}
imgShuimu->SetDrawRect(clipRect);
imgShuimu->Draw(aTarget, TPoint(sp.x,sp.y));
//g.setClip(0,0,screenWidth,screenHeight);
//temp->Destroy();
//delete temp;
}
else if(sprite[i].type==BLACK||sprite[i].type==WHITE)
{
if(sprite[i].type==BLACK)
{
imgPerl[1]->Draw(aTarget, TPoint(sprite[i].x,sprite[i].y));
}
else
{
imgPerl[0]->Draw(aTarget, TPoint(sprite[i].x,sprite[i].y));
}
}
else if(sp.type==SHARK)
{
imgShark[sp.direction*2+(counter%6)/3]->Draw(aTarget, TPoint(sp.x,sp.y));
}
}
}
}
}
}
void CModelGame::DrawStatus(CBitmap &aTarget, CFbsBitGc &aGc)
{
DrawBoard(aTarget, aGc);
DrawScore(aTarget, aGc);
DrawGrowth(aTarget, aGc);
DrawCanEat(aTarget, aGc);
DrawBounus(aTarget, aGc);
}
void CModelGame::DrawBoard(CBitmap &aTarget, CFbsBitGc &aGc)
{
aGc.SetBrushColor( TRgb(0xC2, 0xA6, 0xFC));
aGc.SetBrushStyle( CGraphicsContext::ESolidBrush );
aGc.SetPenStyle( CGraphicsContext::ENullPen );
aGc.DrawRect( TRect(0,0,iSystem->Width(),47));
imgTop->Draw(aTarget,TPoint(0,0));
}
void CModelGame::DrawScore(CBitmap &aTarget, CFbsBitGc &aGc)
{
imgScore[(score/1000000)%10+3]->Draw(aTarget, TPoint(18,10));
imgScore[(score/100000)%10+3]->Draw(aTarget, TPoint(24,10));
imgScore[(score/10000)%10+3]->Draw(aTarget, TPoint(30,10));
imgScore[(score/1000)%10+3]->Draw(aTarget, TPoint(36,10));
imgScore[(score/100)%10+3]->Draw(aTarget, TPoint(42,10));
imgScore[(score/10)%10+3]->Draw(aTarget, TPoint(48,10));
imgScore[3]->Draw(aTarget, TPoint(54,10));
}
void CModelGame::DrawGrowth(CBitmap &aTarget, CFbsBitGc &aGc)
{
aGc.SetBrushColor(TRgb(1,1,1));
aGc.SetPenStyle( CGraphicsContext::ENullPen );
aGc.SetBrushStyle( CGraphicsContext::ESolidBrush );
imgGrowth->Draw(aTarget, TPoint(10,25));
aGc.DrawRect( TRect(TPoint(34,28),TSize(screenWidth-44,8)));
aGc.SetBrushColor( TRgb(0xE5, 0xE5, 0x19) );
if((collected*(screenWidth-46))/goal[level-1]<screenWidth-46)
{
aGc.DrawRect( TRect( TPoint(35,29), TSize((collected*(screenWidth-46))/goal[level-1],6)));
}
else
{
aGc.DrawRect( TRect( TPoint(35,29), TSize(screenWidth-46,6)));
}
aGc.SetBrushColor( TRgb(0xB8, 0x1D, 0x1C) );
CArrayFixFlat<TPoint>* pointList = new (ELeave) CArrayFixFlat<TPoint>(3);
pointList->AppendL(TPoint(35+(screenWidth-44)/3,34));
pointList->AppendL(TPoint(31+(screenWidth-44)/3,40));
pointList->AppendL(TPoint(39+(screenWidth-44)/3,40));
aGc.DrawPolygon(pointList);
pointList->Reset();
pointList->AppendL(TPoint(35+((screenWidth-44)*2)/3,34));
pointList->AppendL(TPoint(31+((screenWidth-44)*2)/3,40));
pointList->AppendL(TPoint(39+((screenWidth-44)*2)/3,40));
aGc.DrawPolygon(pointList);
pointList->Reset();
delete pointList;
}
void CModelGame::DrawCanEat(CBitmap &aTarget, CFbsBitGc &aGc)
{
imgEnemy[(small[level-1]-2)*15]->Draw(aTarget, TPoint(70,10));
if(player->level>=MIDDLE)
{
imgEnemy[(middle[level-1]-2)*15]->Draw(aTarget, TPoint(84,10));
}
if(player->level==LARGE)
{
imgEnemy[(large[level-1]-2)*15]->Draw(aTarget, TPoint(98,10));
}
}
void CModelGame::DrawBounus(CBitmap &aTarget, CFbsBitGc &aGc)
{
if(doubleCtr>0)
{
imgBounus[1]->Draw(aTarget, TPoint(screenWidth-25,50));
}
if(speedCtr>0)
{
imgBounus[3]->Draw(aTarget, TPoint(screenWidth-25,50));
}
if(freezeCtr>0)
{
imgBounus[4]->Draw(aTarget, TPoint(screenWidth-25,50));
}
}
void CModelGame::DrawReset(CBitmap &aTarget, CFbsBitGc &aGc)
{
imgPlayer[0]->Draw(aTarget, TPoint(128,10));
imgBy->Draw(aTarget,TPoint(148,10));
TRect clipRect = TRect( TPoint(rest*6,0), TSize(6,10));
//CBitmap* temp = CBitmap::NewL(TSize(6,10));
//g.setClip(155,10,6,10);
//imgNumber->Draw(*temp,TPoint(-rest*6,0));
//g.setClip(0,0,screenWidth,screenHeight);
imgNumber->SetDrawRect(clipRect);
imgNumber->Draw(aTarget, TPoint(155,10));
/*temp->Destroy();
delete temp;*/
}
void CModelGame::DrawLevelComplete(CBitmap &aTarget, CFbsBitGc &aGc)
{
aGc.SetPenColor( TRgb(0xFE, 0xFE, 0xFE) );
aGc.SetPenStyle( CGraphicsContext::ESolidPen );
const CFont* font = CEikonEnv::Static()->NormalFont();
aGc.UseFont(font);
TBuf<40> fText;
CEikonEnv::Static()->ReadResource(fText, R_K_LEVEL_COMPLETE);
TBuf<60> text;
text.Format(fText, level);
TInt w = font->TextWidthInPixels(text);
aGc.DrawText(text, TPoint((screenWidth-w)/2,screenHeight/2-8));
aGc.DiscardFont();
}
void CModelGame::DrawPause(CBitmap &aTarget, CFbsBitGc &aGc)
{
aGc.SetPenColor( TRgb(0xFE, 0xFE, 0xFE) );
aGc.SetPenStyle( CGraphicsContext::ESolidPen );
const CFont* font = CEikonEnv::Static()->NormalFont();
aGc.UseFont(font);
TBuf<60> text;
CEikonEnv::Static()->ReadResource(text, R_GAME_PAUSED);
TInt w = font->TextWidthInPixels(text);
aGc.DrawText(text, TPoint((screenWidth-w)/2,screenHeight/2-8));
TBuf<20> backText;
CEikonEnv::Static()->ReadResource(backText, R_BACK);
w = font->TextWidthInPixels(backText);
aGc.DrawText(backText, TPoint(2, screenHeight - 2));
aGc.DiscardFont();
}
void CModelGame::DrawDead(CBitmap &aTarget, CFbsBitGc &aGc)
{
aGc.SetPenColor( TRgb(0xFE, 0xFE, 0xFE) );
aGc.SetPenStyle( CGraphicsContext::ESolidPen );
const CFont* font = CEikonEnv::Static()->NormalFont();
aGc.UseFont(font);
TBuf<20> text;
CEikonEnv::Static()->ReadResource(text, R_YOU_DEAD);
TInt w = font->TextWidthInPixels(text);
aGc.DrawText(text, TPoint((screenWidth-w)/2,screenHeight/2-8));
aGc.DiscardFont();
}
void CModelGame::DrawGameOver(CBitmap &aTarget, CFbsBitGc &aGc)
{
aGc.SetPenColor( TRgb(0xFE, 0xFE, 0xFE) );
aGc.SetPenStyle( CGraphicsContext::ESolidPen );
const CFont* font = CEikonEnv::Static()->NormalFont();
aGc.UseFont(font);
TBuf<20> text;
CEikonEnv::Static()->ReadResource(text, R_GAME_OVER);
TInt w = font->TextWidthInPixels(text);
aGc.DrawText(text, TPoint((screenWidth-w)/2,screenHeight/2-8));
aGc.DiscardFont();
}
void CModelGame::DrawAnalys(CBitmap &aTarget, CFbsBitGc &aGc)
{
aGc.SetBrushColor( TRgb(0x11, 0x75, 0xAB) );
aGc.SetBrushStyle( CGraphicsContext::ESolidBrush );
aGc.SetPenStyle( CGraphicsContext::ENullPen );
aGc.DrawRect( TRect(0,0,screenWidth,screenHeight));
imgIntro->Draw(aTarget, TPoint(0,0));
aGc.SetPenStyle( CGraphicsContext::ESolidPen );
aGc.SetPenColor( TRgb(0xFE, 0xFE, 0xFE) );
const CFont* font = CEikonEnv::Static()->NormalFont();
aGc.UseFont(font);
TBuf<20> formatText;
CEikonEnv::Static()->ReadResource(formatText, R_DIJIGUAN);
TBuf<30> text;
text.Format(formatText, level);
TInt w = font->TextWidthInPixels( text );
aGc.DrawText(text, TPoint((screenWidth-w)/2,48));
text.Zero();
CEikonEnv::Static()->ReadResource(text, R_STATISTIC);
aGc.DrawText(text, TPoint(24,70));
imgEnemy[(small[level-1]-2)*15]->Draw(aTarget, TPoint(24,92));
imgEnemy[(middle[level-1]-2)*15]->Draw(aTarget, TPoint(24,114));
imgEnemy[(large[level-1]-2)*15]->Draw(aTarget, TPoint(24,136));
imgBy->Draw(aTarget, TPoint(40,92));
imgBy->Draw(aTarget, TPoint(40,114));
imgBy->Draw(aTarget, TPoint(40,136));
//CBitmap* clip = CBitmap::NewL( TSize(6,10) );
TRect clipRect = TRect( TPoint(6*((smallEaten-smallCtr)/10),0), TSize(6,10));
//imgNumber->Draw(*clip, TPoint(6*((smallEaten-smallCtr)/10),0));
imgNumber->SetDrawRect(clipRect);
imgNumber->Draw(aTarget, TPoint(49,92));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?