cmodelgame.cpp
来自「Symbian手机游戏,可运行于S60 1.x和2.x下, Carbide.C」· C++ 代码 · 共 2,364 行 · 第 1/4 页
CPP
2,364 行
//clip->Clear(0);
//g.setClip(49,92,6,10);
//g.drawImage(imgNumber,49-6*((smallEaten-smallCtr)/10),92,0);
clipRect = TRect( TPoint(6*((smallEaten-smallCtr)%10),0), TSize(6,10));
imgNumber->SetDrawRect( clipRect );
//imgNumber->Draw(*clip, TPoint(-6*((smallEaten-smallCtr)%10), 0));
imgNumber->Draw(aTarget, TPoint(55, 92));
//clip->Clear(0);
//g.setClip(55,92,6,10);
//g.drawImage(imgNumber,55-6*((smallEaten-smallCtr)%10),92,0);
clipRect = TRect(TPoint(6*((middleEaten-middleCtr)/10),0), TSize(6,10));
imgNumber->SetDrawRect(clipRect);
//imgNumber->Draw(*clip, TPoint(-6*((middleEaten-middleCtr)/10),0));
imgNumber->Draw(aTarget, TPoint(49,114));
//clip->Clear(0);
//g.setClip(49,114,6,10);
//g.drawImage(imgNumber,49-6*((middleEaten-middleCtr)/10),114,0);
clipRect = TRect(TPoint(6*((middleEaten-middleCtr)%10),0), TSize(6,10));
//imgNumber->Draw(*clip, TPoint(6*((middleEaten-middleCtr)%10), 0));
imgNumber->SetDrawRect(clipRect);
imgNumber->Draw(aTarget, TPoint(55,114));
//clip->Clear(0);
//g.setClip(55,114,6,10);
//g.drawImage(imgNumber,55-6*((middleEaten-middleCtr)%10),114,0);
clipRect = TRect( TPoint(6*((largeEaten-largeCtr)/10), 0), TSize(6,10));
//imgNumber->Draw(*clip, TPoint(6*((largeEaten-largeCtr)/10),0));
imgNumber->SetDrawRect(clipRect);
imgNumber->Draw(aTarget, TPoint(49, 136));
//clip->Clear(0);
//g.setClip(49,136,6,10);
//g.drawImage(imgNumber,49-6*((largeEaten-largeCtr)/10),136,0);
clipRect = TRect( TPoint(6*((largeEaten-largeCtr)%10),0), TSize(6,10));
//imgNumber->Draw(*clip, TPoint(-6*((largeEaten-largeCtr)%10), 0));
imgNumber->SetDrawRect(clipRect);
imgNumber->Draw(aTarget, TPoint(55,136));
//g.setClip(55,136,6,10);
//g.drawImage(imgNumber,55-6*((largeEaten-largeCtr)%10),136,0);
//g.setClip(0,0,screenWidth,screenHeight);
/*clip->Destroy();
delete clip;*/
text.Zero();
CEikonEnv::Static()->ReadResource(text, R_OK);
aGc.DrawText(text,TPoint(4,screenHeight-22));
aGc.DiscardFont();
}
void CModelGame::DrawTitle(CBitmap &aTarget, CFbsBitGc &aGc)
{
imgTitle->Draw(aTarget, TPoint((screenWidth-imgTitle->Size().iWidth)/2,titleY));
}
void CModelGame::DrawMenu(CBitmap &aTarget, CFbsBitGc &aGc)
{
//g.setClip(0,170,screenWidth,13);
TInt w = imgMenu->Size().iWidth;
TRect clipRect;
if (menuIndex<3)
{
clipRect = TRect( TPoint(0, menuIndex*13), TSize(imgMenu->Size().iWidth, 13) );
}
else if (menuIndex==3&&hasSound)
{
clipRect = TRect( TPoint(0, 3*13), TSize(imgMenu->Size().iWidth, 13));
}
else if (menuIndex==3&&!hasSound)
{
clipRect = TRect( TPoint(0, 4*13), TSize(imgMenu->Size().iWidth, 13));
}
else if(menuIndex>3)
{
clipRect = TRect( TPoint(0, (menuIndex+1)*13), TSize(imgMenu->Size().iWidth, 13));
}
imgMenu->SetDrawRect(clipRect);
imgMenu->Draw(aTarget, TPoint((screenWidth-w)/2, 170));
//g.setClip(0,0,screenWidth,screenHeight);
imgArrow->Draw(aTarget, TPoint(118+2*((counter%8)/4),173));
imgArrowL->Draw(aTarget, TPoint(50-2*((counter%8)/4),174));
//problem //g.drawRegion(imgArrow,0,0,imgArrow.getWidth(),imgArrow.getHeight(),2,50-2*((counter%8)/4),174,0);
//g.drawImage(imgSinlan,screenWidth/2,screenHeight-10,17);
imgSinlan->Draw(aTarget, TPoint((screenWidth-imgSinlan->Size().iWidth)/2,screenHeight-10));
}
void CModelGame::DrawHelp(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.SetBrushColor( KRgbWhite );
if(helpY>-68&&(counter%10)>4)
{
CArrayFixFlat<TPoint>* pointList = new (ELeave) CArrayFixFlat<TPoint>(3);
pointList->AppendL( TPoint(screenWidth/2,65) );
pointList->AppendL( TPoint(screenWidth/2-3,70) );
pointList->AppendL( TPoint(screenWidth/2+3,70) );
aGc.DrawPolygon(pointList);
pointList->Reset();
delete pointList;
}
const CFont* font = CEikonEnv::Static()->NormalFont();
aGc.UseFont(font);
TBuf<80> text;
CEikonEnv::Static()->ReadResource( text, R_HELP_TITLE );
TInt w = font->TextWidthInPixels(text);
aGc.DrawText(text, TPoint((screenWidth-w)/2,44));
//CBitmap* clip = CBitmap::NewL( TSize(screenWidth, 96) );
aGc.SetClippingRect( TRect( TPoint(0,76), TSize(screenWidth,96)));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_INTRO_TITLE );
aGc.DrawText(text, TPoint(24,helpY));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_INTRO_LINE1 );
aGc.DrawText(text, TPoint(24,helpY+16));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_INTRO_LINE2 );
aGc.DrawText(text, TPoint(24,helpY+32));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_INTRO_LINE3 );
aGc.DrawText(text, TPoint(24,helpY+48));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_METHOD_TITLE );
aGc.DrawText(text, TPoint(24,helpY+64));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_METHOD_LINE1 );
aGc.DrawText(text, TPoint(24,helpY+80));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_METHOD_LINE2);
aGc.DrawText(text, TPoint(24,helpY+96));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_METHOD_LINE3);
aGc.DrawText(text, TPoint(24,helpY+112));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_METHOD_LINE4);
aGc.DrawText(text, TPoint(24,helpY+128));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_METHOD_LINE5);
aGc.DrawText(text, TPoint(24,helpY+144));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_METHOD_LINE6);
aGc.DrawText(text, TPoint(24,helpY+160));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_RULE_TITLE);
aGc.DrawText(text, TPoint(24,helpY+176));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_RULE_LINE1);
aGc.DrawText(text, TPoint(24,helpY+192));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_RULE_LINE2);
aGc.DrawText(text, TPoint(24,helpY+208));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_RULE_LINE3);
aGc.DrawText(text, TPoint(24,helpY+224));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_RULE_LINE4);
aGc.DrawText(text, TPoint(24,helpY+240));
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_RULE_LINE5);
aGc.DrawText(text, TPoint(24,helpY+256));
aGc.SetClippingRect( TRect(0,0,screenWidth,screenHeight));
if(helpY<76&&(counter%10)>4)
{
CArrayFixFlat<TPoint>* pointList = new (ELeave) CArrayFixFlat<TPoint>(3);
pointList->AppendL( TPoint(screenWidth/2,185) );
pointList->AppendL( TPoint(screenWidth/2-3,180) );
pointList->AppendL( TPoint(screenWidth/2+3,180) );
aGc.DrawPolygon(pointList);
pointList->Reset();
delete pointList;
//g.fillTriangle(,,);
}
text.Zero();
CEikonEnv::Static()->ReadResource( text, R_BACK);
aGc.DrawText(text, TPoint(screenWidth-30,screenHeight-22));
aGc.DiscardFont();
}
void CModelGame::DrawAbout(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.SetPenColor( KRgbWhite );
aGc.SetPenStyle( CGraphicsContext::ESolidPen );
const CFont* font = CEikonEnv::Static()->NormalFont();
aGc.UseFont(font);
TBuf<80> text;
CEikonEnv::Static()->ReadResource(text, R_ABOUT);
TInt w = font->TextWidthInPixels(text);
aGc.DrawText(text, TPoint((screenWidth-w)/2,54));
text.Zero();
CEikonEnv::Static()->ReadResource(text, R_ABOUT_LINE1);
aGc.DrawText(text, TPoint(24,70));
text.Zero();
CEikonEnv::Static()->ReadResource(text, R_ABOUT_LINE2);
aGc.DrawText(text, TPoint(24,86));
text.Zero();
CEikonEnv::Static()->ReadResource(text, R_ABOUT_LINE3);
aGc.DrawText(text, TPoint(24,102));
text.Zero();
CEikonEnv::Static()->ReadResource(text, R_ABOUT_LINE4);
aGc.DrawText(text, TPoint(24,118));
text.Zero();
CEikonEnv::Static()->ReadResource(text, R_ABOUT_LINE5);
aGc.DrawText(text, TPoint(24,134));
text.Zero();
CEikonEnv::Static()->ReadResource(text, R_ABOUT_LINE6);
aGc.DrawText(text, TPoint(24,150));
text.Zero();
CEikonEnv::Static()->ReadResource(text, R_ABOUT_LINE7);
aGc.DrawText(text, TPoint(24,166));
aGc.DiscardFont();
}
void CModelGame::DrawCongratulations(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.SetPenColor( KRgbWhite );
aGc.SetPenStyle( CGraphicsContext::ESolidPen );
const CFont* font = CEikonEnv::Static()->NormalFont();
aGc.UseFont(font);
TBuf<40> text;
CEikonEnv::Static()->ReadResource(text, R_CONGRATULATIONS);
TInt w = font->TextWidthInPixels(text);
aGc.DrawText(text, TPoint((screenWidth - w)/2,screenHeight/2-8));
aGc.DiscardFont();
}
void CModelGame::DrawRest(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* clip = CBitmap::NewL( TSize(6,10) );
//g.setClip(155,10,6,10);
//imgNumber->Draw(*clip, TPoint(-rest*6, 0));
imgNumber->SetDrawRect(clipRect);
imgNumber->Draw(aTarget, TPoint(155, 10 ));
//g.drawImage(imgNumber,155-rest*6,10,0);
//g.setClip(0,0,screenWidth,screenHeight);
/*clip->Destroy();
delete clip;*/
}
void CModelGame::RandomBubbles()
{
TInt r=(Math::Rand(seed))%50;
if(r==0)
{
InitBubble();
}
r=(Math::Rand(seed))%200;
if(r==0)
{
InitBubbleBounus();
}
}
void CModelGame::InitBubble()
{
SP* bubble=GetFreeSprite();
if(bubble!=NULL)
{
TInt s=(Math::Rand(seed))%2;
bubble->type=BUBBLE1+s;
bubble->level=9999;
bubble->width=4;
bubble->height=4;
TInt r=(Math::Rand(seed))%(screenWidth-offsetXMin[level-1]+offsetXMax[level-1]-bubble->width)+offsetXMin[level-1];
bubble->x=r;
bubble->y=screenHeight+offsetY;
bubble->action=BUBBLEINCREASE;
}
}
void CModelGame::InitBubbleBounus()
{
SP* bubbleBounus=GetFreeSprite();
if(bubbleBounus!=NULL)
{
TInt r=(Math::Rand(seed))%100;
if(level==1)
{
bubbleBounus->type=SEASTAR;
}
else if(level==2)
{
if(r<10)
{
bubbleBounus->type=DOUBLE;
}
else
{
bubbleBounus->type=SEASTAR;
}
}
else if(level==3||level==4)
{
if(r<10)
{
bubbleBounus->type=DOUBLE;
}
else if(r<12)
{
bubbleBounus->type=EXTRALIFE;
}
else
{
bubbleBounus->type=SEASTAR;
}
}
else if(level==5)
if(r<10)
bubbleBounus->type=DOUBLE;
else if(r<12)
bubbleBounus->type=EXTRALIFE;
else if(r<20)
bubbleBounus->type=SPEED;
else
bubbleBounus->type=SEASTAR;
else{
if(r<10)
bubbleBounus->type=DOUBLE;
else if(r<12)
bubbleBounus->type=EXTRALIFE;
else if(r<20)
bubbleBounus->type=SPEED;
else if(r<35)
bubbleBounus->type=FREEZE;
else
bubbleBounus->type=SEASTAR;
}
bubbleBounus->level=SMALL;
bubbleBounus->width=15;
bubbleBounus->height=15;
r=(Math::Rand(seed))%(screenWidth-offsetXMin[level-1]+offsetXMax[level-1]-bubbleBounus->width)+offsetXMin[level-1];
bubbleBounus->x=r;
bubbleBounus->y=screenHeight+offsetY;
bubbleBounus->action=BUBBLEBOUNUSINCREASE;
}
}
void CModelGame::UpdatePlayer()
{
if(gameOverCtr>0)
{
if(gameOverCtr==1)
{
gameState=MENU;
menuIndex=0;
resumeFlag=EFalse;
}
gameOverCtr--;
return;
}
if(yummyCtr>0)
yummyCtr--;
if(newCtr>0)
newCtr--;
if(deadCtr>0)
deadCtr--;
if(doubleCtr>0)
doubleCtr--;
if(speedCtr>0)
speedCtr--;
if(player->ctr>0)
{
//处理主角计数器>0的事件
player->ctr--;
if(player->action==TURN)
{
//如果动作为转身
if(player->ctr==5)//计数器到5改变方向
if(player->direction==RIGHT)
player->direction=LEFT;
else
player->direction=RIGHT;
}
if(player->ctr==0)
{
//处理计数器到0的事件
if(player->action==TURN||player->action==KILL||player->action==STUN)//动作为转身就把动作变为游泳
player->action=SWIM;
}
}
if(gameState==PLAY&&(player->action==SWIM||player->action==KILL||player->action==TURN)&&deadCtr==0)
{
//动作为游泳时响应键盘事件
TInt s=0;
if(speedCtr>0)
s=2;
else
s=1;
if((iSystem->KeyState( EStdKeyUpArrow ))||(iSystem->KeyState( 50 )))////////change//////////
{
if(player->y>BOARDHEIGHT+1*s+32)
player->y-=2*s;
else if(offsetY<offsetYMax[level-1])
{
offsetY+=2*s;
for(TInt i=0;i<70;i++)
{
if(sprite[i].type>PLAYER)
{
sprite[i].y+=2*s;
}
}
}
else if(player->y>BOARDHEIGHT+1*s)
{
player->y-=2*s;
}
}
if((iSystem->KeyState( EStdKeyDownArrow )) || (iSystem->KeyState( 56 )) )/////////////change/////////////
{
if(player->y<screenHeight-player->height-1*s-32)
player->y+=2*s;
else if(offsetY>0){
offsetY-=2*s;
for(TInt i=0;i<70;i++)
{
if(sprite[i].type>PLAYER)
{
sprite[i].y-=2*s;
}
}
}else if(player->y<screenHeight-player->height-1*s){
player->y+=2*s;
}
}
if((iSystem->KeyState( EStdKeyLeftArrow ))||(iSystem->KeyState( 52 )))///////////////////change//////////////
{
if(player->x>1*s+32)
player->x-=2*s;
else if(offsetX<offsetXMax[level-1])
{
offsetX+=2*s;
for(TInt i=0;i<70;i++)
{
if(sprite[i].type>PLAYER)
{
sprite[i].x+=2*s;
}
}
}else if(player->x>1*s)
{
player->x-=2*s;
}
if(player->direction==RIGHT&&player->action!=TURN)
{
//改变方向
player->ctr=9;
player->action=TURN;
}
}
if((iSystem->KeyState( EStdKeyRightArrow )) || (iSystem->KeyState( 54 )))
{
if(player->x<screenWidth-player->width-1*s-32)
player->x+=2*s;
else if(offsetX>offsetXMin[level-1])
{
offsetX-=2*s;
for(TInt i=0;i<70;i++)
{
if(sprite[i].type>PLAYER)
{
//SP sp=sprite[i];
sprite[i].x-=2*s;
}
}
}else if(player->x<screenWidth-player->width-1*s)
{
player->x+=2*s;
}
if(player->direction==LEFT&&player->action!=TURN)
{
//改变方向
player->ctr=9;
player->action=TURN;
}
}
}
}
void CModelGame::UpdateEnemies()
{
if(freezeCtr>0)
{
freezeCtr--;
}
if(sharkCtr>0)
{
sharkCtr--;
}
else if(sharkCtr==0&&shark[level-1]>0)
{
RandomShark();
}
if(shuimu[level-1]>0)
RandomShuimu();
for(TInt i=0;i<70;i++)
{
if(sprite[i].type>PLAYER)
{
SP* enemy=&(sprite[i]);
if(enemy->ctr>0)
{
enemy->ctr--;
if(enemy->action==IDLE)
{
}
else if(enemy->action==MOVENEAR)
{
TInt r=(Math::Rand(seed))%10;
if(r>2)
{
if(enemy->x<player->x)
{
enemy->x++;
if(enemy->direction==LEFT)
{
enemy->ctr=9;
enemy->action=TURN;
}
}
else if(enemy->x>player->x)
{
enemy->x--;
if(enemy->direction==RIGHT)
{
enemy->ctr=9;
enemy->action=TURN;
}
}
}
if(r<8)
{
if(enemy->y<player->y)
enemy->y++;
else if(enemy->y>player->y)
enemy->y--;
}
}
else if(enemy->action==MOVEFAR)
{
TInt r=(Math::Rand(seed))%10;
if(r>2)
{
if(enemy->x>player->x)
{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?