📄 eros.c
字号:
*ppObj = NULL;
if( ClsId == AEECLSID_EROS )
{
// Create the applet and make room for the applet structure
if( AEEApplet_New(sizeof(eros),
ClsId,
pIShell,
po,
(IApplet**)ppObj,
(AEEHANDLER)eros_HandleEvent,
(PFNFREEAPPDATA)eros_FreeAppData) ) // the FreeAppData function is called after sending EVT_APP_STOP to the HandleEvent function
{
//added by wuhaoyong
#ifdef AEE_SIMULATOR
AEE_SetShell(pIShell);
#endif
//Initialize applet data, this is called before sending EVT_APP_START
// to the HandleEvent function
if(eros_InitAppData((eros*)*ppObj))
{
//Data initialized successfully
return(AEE_SUCCESS);
}
else
{
//Release the applet. This will free the memory allocated for the applet when
// AEEApplet_New was called.
IAPPLET_Release((IApplet*)*ppObj);
return EFAILED;
}
} // end AEEApplet_New
}
return(EFAILED);
}
/*===========================================================================
FUNCTION SampleAppWizard_HandleEvent
DESCRIPTION
This is the EventHandler for this app. All events to this app are handled in this
function. All APPs must supply an Event Handler.
PROTOTYPE:
boolean SampleAppWizard_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
PARAMETERS:
pi: Pointer to the AEEApplet structure. This structure contains information specific
to this applet. It was initialized during the AEEClsCreateInstance() function.
ecode: Specifies the Event sent to this applet
wParam, dwParam: Event specific data.
DEPENDENCIES
none
RETURN VALUE
TRUE: If the app has processed the event
FALSE: If the app did not process the event
SIDE EFFECTS
none
===========================================================================*/
static boolean eros_HandleEvent(eros* pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch (eCode)
{
// App is told it is starting up
case EVT_APP_START:
{
// Add your code here...
return Eros_Start(pMe);
}
case EVT_APP_STOP://exit
{
if(pMe->m_nState == STATE_RUNGAME)
{
//运行程序时退出,把信息写入文件
//以便重新进入时继续游戏
//保存map,pMe->current_block,pMe->next_block
Eros_SetBackLightAlwaysOn(FALSE);
ISHELL_CancelTimer(pMe->a.m_pIShell, (PFNNOTIFY) update_map, (eros *) pMe);
Eros_WriteScoreFile(pMe);//wuhaoyong add 中断时自动存储分数
pMe->m_continue=1;
return eros_SaveScene(pMe);
}
else//as EVT_APP_SUSPEND
{
Eros_SetBackLightAlwaysOn(FALSE);
ISHELL_CancelTimer(pMe->a.m_pIShell, (PFNNOTIFY) update_map, (eros *) pMe);
Eros_WriteScoreFile(pMe);//wuhaoyong add 中断时自动存储分数
{
IBitmap* pDeviceBitmap;
/* Create a bitmap that captures the current state of the screen */
if( IDISPLAY_GetDeviceBitmap( pMe->a.m_pIDisplay, &pDeviceBitmap ) != SUCCESS )
{
return FALSE;
}
if( IBITMAP_CreateCompatibleBitmap( pDeviceBitmap,
&pMe->m_pSuspendBitmap,
(uint16) ( pMe->m_nScrWidth ),
(uint16) ( pMe->m_nScrHeight )
)
!= SUCCESS )
{
IBITMAP_Release( pDeviceBitmap );
{
pDeviceBitmap=NULL;
return FALSE;
}
}
IBITMAP_BltIn( pMe->m_pSuspendBitmap,
0,
0,
(uint16) ( pMe->m_nScrWidth ),
(uint16) ( pMe->m_nScrHeight ),
pDeviceBitmap,
0,
0,
AEE_RO_COPY );
if(pDeviceBitmap!=NULL)
{
IBITMAP_Release( pDeviceBitmap );
pDeviceBitmap=NULL;
}
//wuhaoyong add without verify
//先保存画面再起动刷新图标区,否则保存的话面也带有图标区
//if(STATE_RUNGAME==pMe->m_nState)
//{
// IANNUNCIATOR_EnableAnnunciatorBar(pMe->m_pIAnnu,AEECLSID_DISPLAY1,TRUE);
//}
/* do the other work neccessary */
//add code here...
return TRUE;
}
return(TRUE);
}
}
// App is being suspended
case EVT_APP_SUSPEND:
//case EVT_APP_STOP:
{
Eros_SetBackLightAlwaysOn(FALSE);
ISHELL_CancelTimer(pMe->a.m_pIShell, (PFNNOTIFY) update_map, (eros *) pMe);
Eros_WriteScoreFile(pMe);//wuhaoyong add 中断时自动存储分数
{
IBitmap* pDeviceBitmap;
/* Create a bitmap that captures the current state of the screen */
if( IDISPLAY_GetDeviceBitmap( pMe->a.m_pIDisplay, &pDeviceBitmap ) != SUCCESS )
{
return FALSE;
}
if( IBITMAP_CreateCompatibleBitmap( pDeviceBitmap,
&pMe->m_pSuspendBitmap,
(uint16) ( pMe->m_nScrWidth ),
(uint16) ( pMe->m_nScrHeight )
)
!= SUCCESS )
{
if(pDeviceBitmap!=NULL)
{
IBITMAP_Release( pDeviceBitmap );
{
pDeviceBitmap=NULL;
return FALSE;
}
}
}
IBITMAP_BltIn( pMe->m_pSuspendBitmap,
0,
0,
(uint16) ( pMe->m_nScrWidth ),
(uint16) ( pMe->m_nScrHeight ),
pDeviceBitmap,
0,
0,
AEE_RO_COPY );
if(pDeviceBitmap!=NULL)
{
IBITMAP_Release( pDeviceBitmap );
pDeviceBitmap=NULL;
}
//wuhaoyong add without verify
//先保存画面再起动刷新图标区,否则保存的话面也带有图标区
//if(STATE_RUNGAME==pMe->m_nState)
//{
// IANNUNCIATOR_EnableAnnunciatorBar(pMe->m_pIAnnu,AEECLSID_DISPLAY1,TRUE);
//}
/* do the other work neccessary */
//add code here...
return TRUE;
}
return(TRUE);
}
// App is being resumed
case EVT_APP_RESUME:
// Add your code here...
//ISHELL_SetTimer(pMe->a.m_pIShell, 300, (PFNNOTIFY) update_map, (eros *) pMe);
if(pMe->m_nState == STATE_RUNGAME)
{
ISHELL_SetTimer(pMe->a.m_pIShell, pMe->m_nTimer, (PFNNOTIFY) update_map, (eros *) pMe);
restorememory(pMe);
if(pMe->pause)
{
ISHELL_PostEvent(pMe->a.m_pIShell, AEECLSID_EROS, EVT_USER, 0, 0);
}
}
if(pMe->m_nState == STATE_MAINMENU)
{
return Eros_Start(pMe);
}
if(pMe->m_nState == STATE_OPTION)
{
return Eros_DisplayOptionMenu(pMe);
}
if(pMe->m_nState == STATE_RECORD)
{
return Eros_ScoreHandleCommand(pMe,wParam,dwParam);
}
if(pMe->m_nState == STATE_HELP)
{
return Eros_DisplayHelpMenu(pMe,wParam,dwParam);
}
if(pMe->m_nState == STATE_GAMEOVER ||pMe->m_nState == STATE_GAMEPASS)//wuhaoyong add STATE_GAMEPASS
{
/* Copy the capture bitmap to the screen to restroe the display */
//wuhaoyong add without verify
IDISPLAY_BitBlt( pMe->a.m_pIDisplay,
0,
0,
pMe->m_nScrWidth,
pMe->m_nScrHeight,
pMe->m_pSuspendBitmap,
0,
0,
AEE_RO_COPY );
if(pMe->m_pSuspendBitmap!=NULL)
{
Eros_ReleaseObj( (void **)&pMe->m_pSuspendBitmap );
pMe->m_pSuspendBitmap=NULL;
}
/* do the other work neccessary */
//add code here...
return TRUE;
}
//add by wuhaoyong
#if 0
if(pMe->m_pIAnnu!=NULL)
{
IANNUNCIATOR_EnableAnnunciatorBar(pMe->m_pIAnnu,AEECLSID_DISPLAY1,TRUE);
}
#endif
return(TRUE);
// An SMS message has arrived for this app. Message is in the dwParam above as (char *)
// sender simply uses this format "//BREW:ClassId:Message", example //BREW:0x00000001:Hello World
case EVT_APP_MESSAGE:
// Add your code here...
return(TRUE);
case EVT_USER:
{
AECHAR szText[] ={0x0070,0x0061,0x0075,0x0073,0x0065,0x002f,0x6682,0x505c,'\0'};
pMe->pause=TRUE;
ISHELL_CancelTimer(pMe->a.m_pIShell, (PFNNOTIFY) update_map, (eros *) pMe);
//Eros_WriteScoreFile(pMe);//wuhaoyong add 自动存储分数
if(FALSE==Eros_WriteScoreFile(pMe))//wuhaoyong add 结束时自动存储分数
{
return Eros_Stop(pMe);
}
//ISHELL_CancelTimer(pMe->a.m_pIShell, (PFNNOTIFY) update_map, (eros *) pMe);
{
IBitmap* pDeviceBitmap;
/* Create a bitmap that captures the current state of the screen */
if( IDISPLAY_GetDeviceBitmap( pMe->a.m_pIDisplay, &pDeviceBitmap ) != SUCCESS )
{
return FALSE;
}
if( IBITMAP_CreateCompatibleBitmap( pDeviceBitmap,
&pMe->m_pSuspendBitmap,
(uint16) ( pMe->m_nScrWidth ),
(uint16) ( pMe->m_nScrHeight )
)
!= SUCCESS )
{
if(pDeviceBitmap!=NULL)
{
IBITMAP_Release( pDeviceBitmap );
{
pDeviceBitmap=NULL;
return FALSE;
}
}
}
IBITMAP_BltIn( pMe->m_pSuspendBitmap,
0,
0,
(uint16) ( pMe->m_nScrWidth ),
(uint16) ( pMe->m_nScrHeight ),
pDeviceBitmap,
0,
0,
AEE_RO_COPY );
if(pDeviceBitmap!=NULL)
{
IBITMAP_Release( pDeviceBitmap );
pDeviceBitmap=NULL;
}
}
//显示暂停提示
IDISPLAY_DrawText(pMe->a.m_pIDisplay, // Display instance
AEE_FONT_LARGE, // Use BOLD font
szText,//szText+5, // Text - Normally comes from resource
-1, // -1 = Use full string length
MAP_WIDTH*pMe->block_width/2-40, // x-cordinate
MAP_HEIGHT*pMe->block_height-188+pMe->block_height+BREW_APP_Y+MENU_TITLE_HEIGHT, // y-cordinate
NULL, // No clipping
IDF_TEXT_TRANSPARENT);//IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
IDISPLAY_Update(pMe->a.m_pIDisplay);
return(TRUE);
}
// A key was pressed. Look at the wParam above to see which key was pressed. The key
// codes are in AEEVCodes.h. Example "AVK_1" means that the "1" key was pressed.
#if 0
case EVT_KEY:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -