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

📄 game.c

📁 以BREW为开发平台,以C为开发语言的大鱼吃小鱼的游戏,容易理解思路简单
💻 C
📖 第 1 页 / 共 3 页
字号:
				{
					
					pMe->derection=1;
					if(pMe->IsNewLife!=1)
					{
						pMe->m_Sprite[0].y-=2;
					}
					
					if(pMe->score>=50)
					{
						pMe->m_Sprite[5].y=pMe->m_Sprite[0].y-20;
						pMe->m_Sprite[5].x=pMe->m_Sprite[0].x-30;
					}
					
				}
				
				if(wParam==AVK_DOWN && pMe->m_Sprite[0].y<130)

				{
					
				
					pMe->derection=2;
					if(pMe->IsNewLife!=1)
					{
						pMe->m_Sprite[0].y+=2;
					}
					
					if(pMe->score>=50)
					{
						pMe->m_Sprite[5].y=pMe->m_Sprite[0].y-20;
						pMe->m_Sprite[5].x=pMe->m_Sprite[0].x-30;
					}
					
				}
				if(wParam==AVK_LEFT && pMe->m_Sprite[0].x>0)

				{
					pMe->derection=3;
					
					if(pMe->IsNewLife!=1)
					{
						pMe->m_Sprite[0].x-=2;
					}
					
					if(pMe->score>=50)
					{
					pMe->m_Sprite         [5].unTransform=SPRITE_FLIP_Y;
					pMe->m_Sprite[5].x=pMe->m_Sprite[0].x-30;
					pMe->m_Sprite[5].y=pMe->m_Sprite[0].y-20;
					}
					
	                
				}
				
				if(wParam==AVK_RIGHT && pMe->m_Sprite[0].x<96 )

				{
					if(pMe->IsNewLife!=1)
					{
						pMe->m_Sprite[0].x+=2;
					}
					
					if(pMe->score>=50)
					{
					//pMe->m_Sprite[5].unTransform=0;
					pMe->m_Sprite[5].x=pMe->m_Sprite[0].x-30;
					pMe->m_Sprite[5].y=pMe->m_Sprite[0].y-20;
					}
					
					
	
				}
				if(wParam==AVK_CLR)

				{
					CALLBACK_Cancel(&pMe->cbtime); 
					IMENUCTL_SetActive(pMe->pIMenuCtl,TRUE);
	
				}

				
			
			}

      		return(TRUE);


        // If nothing fits up to this point then we'll just break out
        default:
            break;
   }

   return FALSE;
}












// this function is called when your application is starting up
boolean game_InitAppData(game* pMe)      //初始化 ,一般不改变的全局变量
{
    // Get the device information for this handset.
    // Reference all the data by looking at the pMe->DeviceInfo structure
    // Check the API reference guide for all the handy device info you can get
    pMe->DeviceInfo.wStructSize = sizeof(pMe->DeviceInfo);
    ISHELL_GetDeviceInfo(pMe->a.m_pIShell,&pMe->DeviceInfo);

    // The display and shell interfaces are always created by
    // default, so we'll asign them so that you can access
    // them via the standard "pMe->" without the "a."
    pMe->pIDisplay = pMe->a.m_pIDisplay;
    pMe->pIShell   = pMe->a.m_pIShell;
	pMe->fishtime  =0;
	pMe->fish1_x=90;
	pMe->fish1_y=20;
	pMe->fish2_x=90;
	pMe->fish2_y=80;
	pMe->fish3_x=90;
	pMe->fish3_y=120;
	pMe->bigfish_x=0;
	pMe->bigfish_y=-5;
//	pMe->pshow_score


    // Insert your code here for initializing or allocating resources...



    // if there have been no failures up to this point then return success
    return TRUE;
}

// this function is called when your application is exiting
void game_FreeAppData(game* pMe)
{
    // insert your code here for freeing any resources you have allocated...

    // example to use for releasing each interface:
    // if ( pMe->pIMenuCtl != NULL )         // check for NULL first
    // {
    //    IMENUCTL_Release(pMe->pIMenuCtl)   // release the interface
    //    pMe->pIMenuCtl = NULL;             // set to NULL so no problems trying to free later
    // }
    //
	 if ( pMe->pIMenuCtl != NULL )         // check for NULL first
					  {
					     IMENUCTL_Release(pMe->pIMenuCtl);   // release the interface
					     pMe->pIMenuCtl = NULL;             // set to NULL so no problems trying to free later
					  }
					   if ( pMe->pIImage != NULL )         // check for NULL first
					  {
					     IIMAGE_Release(pMe->pIImage);   // release the interface
					     pMe->pIImage = NULL;             // set to NULL so no problems trying to free later
					  }
					   if ( pMe->pISprite != NULL )         // check for NULL first
					  {
					     ISPRITE_Release(pMe->pISprite);   // release the interface
					     pMe->pISprite = NULL;             // set to NULL so no problems trying to free later
					  }
					   if ( pMe->pISoundPlayer != NULL )         // check for NULL first
					  {
					     ISOUNDPLAYER_Release(pMe->pISoundPlayer);   // release the interface
					     pMe->pISoundPlayer = NULL;             // set to NULL so no problems trying to free later
					  }
					   if ( pMe->pIMenuCtl != NULL )         // check for NULL first
					  {
					     IMENUCTL_Release(pMe->pIMenuCtl);   // release the interface
					     pMe->pIMenuCtl = NULL;             // set to NULL so no problems trying to free later
					  }
						if ( pMe->pIMenuCtl != NULL )         // check for NULL first
					  {
					     IMENUCTL_Release(pMe->pIMenuCtl);   // release the interface
					     pMe->pIMenuCtl = NULL;             // set to NULL so no problems trying to free later
					  }

}


void ExSprite_loadResource(game * pMe)
{
	
	IBitmap * pbmScreen=NULL;
	IBitmap * pbmDib=NULL;
	IBitmap * pbmDdb=NULL;
	NativeColor color;
	AEEBitmapInfo bi;
	
	pbmScreen=IDISPLAY_GetDestination(pMe->pIDisplay);
	//加载大鱼精灵
	pbmDib=ISHELL_LoadBitmap(pMe->pIShell,"bigfish.bmp");
	IBITMAP_GetInfo(pbmDib,&bi,sizeof(bi));
	IBITMAP_CreateCompatibleBitmap(pbmScreen,&pbmDdb,(uint16)bi.cx,(uint16)bi.cy);
	IBITMAP_BltIn(pbmDdb,0,0,(uint16)bi.cx,(uint16)bi.cy,pbmDib,0,0,AEE_RO_COPY);
	IBITMAP_Release(pbmDib);
	pbmDib=NULL;
	IBITMAP_GetPixel(pbmDdb,0,0,&color);
	IBITMAP_SetTransparencyColor(pbmDdb,color);
	ISPRITE_SetSpriteBuffer(pMe->pISprite,SPRITE_SIZE_64X64,pbmDdb);
	IBITMAP_Release(pbmDdb);

//	ISHELL_CreateInstance(pMe->pIShell,AEECLSID_SPRITE,(void**)&pMe->pISprite);
	pbmDib=ISHELL_LoadBitmap(pMe->pIShell,"sprite.bmp");
	IBITMAP_GetInfo(pbmDib,&bi,sizeof(bi));
	IBITMAP_CreateCompatibleBitmap(pbmScreen,&pbmDdb,(uint16)bi.cx,(uint16)bi.cy);
	IBITMAP_BltIn(pbmDdb,0,0,(uint16)bi.cx,(uint16)bi.cy,pbmDib,0,0,AEE_RO_COPY);
    //IBITMAP_GetTransparencyColor();

	
	IBITMAP_Release(pbmDib);
	pbmDib=NULL;
	IBITMAP_GetPixel(pbmDdb,0,0,&color);
	IBITMAP_SetTransparencyColor(pbmDdb,color);
	ISPRITE_SetSpriteBuffer(pMe->pISprite,SPRITE_SIZE_32X32,pbmDdb);
	IBITMAP_Release(pbmDdb);

	
	pbmDib=ISHELL_LoadBitmap(pMe->pIShell,"bg32'.bmp");
	IBITMAP_GetInfo(pbmDib,&bi,sizeof(bi));
	IBITMAP_CreateCompatibleBitmap(pbmScreen,&pbmDdb,(uint16)bi.cx,(uint16)bi.cy);
	IBITMAP_BltIn(pbmDdb,0,0,(uint16)bi.cx,,(uint16)bi.cy,pbmDib,0,0,AEE_RO_COPY);
	IBITMAP_Release(pbmDib);
	pbmDib=NULL;
	IBITMAP_GetPixel(pbmDdb,0,0,&color);
	ISPRITE_SetTileBuffer(pMe->pISprite,TILE_SIZE_32X32,pbmDdb);
	IBITMAP_Release(pbmDdb);
	ISPRITE_SetDestination(pMe->pISprite,pbmScreen);
	IBITMAP_Release(pbmScreen);

}

void ExSprite_Init(game * pMe)
{int i=0;
pMe->flag=0;//标记
//pMe->bigfish_flag=0;//标记是否是吃够50分 可以变成大鱼
//设置非玩家控制精灵的坐标



    pMe->m_Sprite[0].unComposite=COMPOSITE_KEYCOLOR;
	pMe->m_Sprite[0].unLayer=SPRITE_LAYER_0;
	pMe->m_Sprite[0].unSpriteIndex=0;
	pMe->m_Sprite[0].unSpriteSize=SPRITE_SIZE_32X32;
	pMe->m_Sprite[0].unTransform=0;
	pMe->m_Sprite[0].x=5;
	pMe->m_Sprite[0].y=60;

	pMe->m_Sprite[1].unComposite=COMPOSITE_KEYCOLOR;
	pMe->m_Sprite[1].unLayer=SPRITE_LAYER_0;
	pMe->m_Sprite[1].unSpriteIndex=4;
	pMe->m_Sprite[1].unSpriteSize=SPRITE_SIZE_32X32;
	pMe->m_Sprite[1].unTransform=0 ;//pMe->m_Sprite[1].unTransform=TRANSFORM_ROTATE_90;
	pMe->m_Sprite[1].x=pMe->fish1_x;
	pMe->m_Sprite[1].y=pMe->fish1_y;

	pMe->m_Sprite[2].unComposite=COMPOSITE_KEYCOLOR;
	pMe->m_Sprite[2].unLayer=SPRITE_LAYER_0;
	pMe->m_Sprite[2].unSpriteIndex=5;
	pMe->m_Sprite[2].unSpriteSize=SPRITE_SIZE_32X32;
	pMe->m_Sprite[2].unTransform=0 ;//pMe->m_Sprite[1].unTransform=TRANSFORM_ROTATE_90;
	pMe->m_Sprite[2].x=pMe->fish2_x;
	pMe->m_Sprite[2].y=pMe->fish2_y;

	pMe->m_Sprite[3].unComposite=COMPOSITE_KEYCOLOR;
	pMe->m_Sprite[3].unLayer=SPRITE_LAYER_0;
	pMe->m_Sprite[3].unSpriteIndex=6;
	pMe->m_Sprite[3].unSpriteSize=SPRITE_SIZE_32X32;
	pMe->m_Sprite[3].unTransform=0 ;//pMe->m_Sprite[1].unTransform=TRANSFORM_ROTATE_90;
	pMe->m_Sprite[3].x=pMe->fish3_x;
	pMe->m_Sprite[3].y=pMe->fish3_y;

	pMe->m_Sprite[4].unComposite=COMPOSITE_KEYCOLOR;
	pMe->m_Sprite[4].unLayer=SPRITE_LAYER_0;
	pMe->m_Sprite[4].unSpriteIndex=0;
	pMe->m_Sprite[4].unSpriteSize=SPRITE_SIZE_64X64;
	pMe->m_Sprite[4].unTransform=0;
	pMe->m_Sprite[4].x=pMe->bigfish_x;
	pMe->m_Sprite[4].y=pMe->bigfish_y;

	pMe->m_Sprite[5].unComposite=COMPOSITE_KEYCOLOR;
	pMe->m_Sprite[5].unLayer=SPRITE_LAYER_0;
	pMe->m_Sprite[5].unSpriteIndex=4;
	pMe->m_Sprite[5].unSpriteSize=SPRITE_SIZE_64X64;
	pMe->m_Sprite[5].unTransform=0;
	pMe->m_Sprite[5].x=-100;
	pMe->m_Sprite[5].y=-100;
	
	pMe->m_Sprite[6].unComposite=COMPOSITE_KEYCOLOR;
	pMe->m_Sprite[6].unLayer=SPRITE_LAYER_0;
	pMe->m_Sprite[6].unSpriteIndex=9;
	pMe->m_Sprite[6].unSpriteSize=SPRITE_SIZE_32X32;
	pMe->m_Sprite[6].unTransform=0 ;//pMe->m_Sprite[1].unTransform=TRANSFORM_ROTATE_90;
	pMe->m_Sprite[6].x=0;
	pMe->m_Sprite[6].y=-10;

	pMe->m_Sprite[7].unComposite=COMPOSITE_KEYCOLOR;
	pMe->m_Sprite[7].unLayer=SPRITE_LAYER_0;
	pMe->m_Sprite[7].unSpriteIndex=9;
	pMe->m_Sprite[7].unSpriteSize=SPRITE_SIZE_32X32;
	pMe->m_Sprite[7].unTransform=0 ;//pMe->m_Sprite[1].unTransform=TRANSFORM_ROTATE_90;
	pMe->m_Sprite[7].x=20;
	pMe->m_Sprite[7].y=-10;

	pMe->m_Sprite[8].unComposite=COMPOSITE_KEYCOLOR;
	pMe->m_Sprite[8].unLayer=SPRITE_LAYER_0;
	pMe->m_Sprite[8].unSpriteIndex=9;
	pMe->m_Sprite[8].unSpriteSize=SPRITE_SIZE_32X32;
	pMe->m_Sprite[8].unTransform=0 ;//pMe->m_Sprite[1].unTransform=TRANSFORM_ROTATE_90;
	pMe->m_Sprite[8].x=40;
	pMe->m_Sprite[8].y=-10;
/*	for(i;i<3;i++)
	{
	pMe->m_Sprite[i].unComposite=COMPOSITE_KEYCOLOR;
	pMe->m_Sprite[i].unLayer=SPRITE_LAYER_0;
	pMe->m_Sprite[i].unSpriteIndex=i;
	pMe->m_Sprite[i].unSpriteSize=SPRITE_SIZE_32X32;
	pMe->m_Sprite[i].unTransform=0;
	pMe->m_Sprite[i].x=i+5;
	pMe->m_Sprite[i].y=i+60;
	}*/
	pMe->m_Sprite[9].unSpriteSize=SPRITE_SIZE_END;//??????????????

	pMe->m_Maps[0].pMapArray=(uint16 *)map;
	pMe->m_Maps[0].unFlags=MAP_FLAG_WRAP;
	pMe->m_Maps[0].unTileSize=TILE_SIZE_32X32;
	pMe->m_Maps[0].h=MAP_SIZE_16;//hang
	pMe->m_Maps[0].w=MAP_SIZE_16;//lei 
//	pMe->m_Maps[0].y=pMe->DeviceInfo.cyScreen-256;
	pMe->m_Maps[0].y=0;
	pMe->m_Maps[0].x=0;
}

//回调函数
static void ballup(game *pMe)
{  
		int n=5;
		AECHAR score[]={'S','c','o','r','e',':','\0'};
		AECHAR sscore[50]={' ','\0'};
		//自调用回调函数
		ISHELL_SetTimerEx(pMe->pIShell,100,&pMe->cbtime);
		 
		/*
		IDISPLAY_EraseRgn (pMe->pIDisplay, 0,0, pMe->DeviceInfo.cxScreen, 16 );
		IDISPLAY_DrawText(
						pMe->pIDisplay,
						AEE_FONT_NORMAL,
						score,
						-1,
						30,3,
						NULL  ,
						NULL
					);
					*/
		
		
		//自减地图横坐标
        pMe->m_Maps[0].x=pMe->m_Maps[0].x-1;
		ISPRITE_DrawTiles(pMe->pISprite,pMe->m_Maps);//画地图

		pMe->fishtime++;
		
		pMe->m_Sprite[0].unSpriteIndex=(pMe->fishtime)%4;
		pMe->m_Sprite[4].unSpriteIndex=(pMe->fishtime)%4;
		pMe->m_Sprite[5].unSpriteIndex=(pMe->fishtime)%4+4;
		
		if(pMe->derection==1)
		{
			pMe->m_Sprite[0].unSpriteIndex=7;
			pMe->m_Sprite[5].unSpriteIndex=8;
		}
		if(pMe->derection==2)
		{
		pMe->m_Sprite[0].unSpriteIndex=8;
		pMe->m_Sprite[5].unSpriteIndex=9;
		}
		if(pMe->derection==3)
		{
			pMe->m_Sprite[0].unTransform=SPRITE_FLIP_Y;
		}
		pMe->derection=0;
		 //IDISPLAY_ClearScreen(pMe->pIDisplay);
		 
		 
		 //IDISPLAY_Update(pMe->pIDisplay);
		
			

		pMe->fish1_x-=2;
		pMe->fish2_x-=3;
		pMe->fish3_x-=4;

//设置大鱼轨迹

⌨️ 快捷键说明

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