📄 game.c
字号:
MAP_HEIGHT*pMe->block_height/2,// y-cordinate
NULL, // No clipping
IDF_ALIGN_CENTER | IDF_ALIGN_MIDDLE);
}
static void update_map(CGametype * pMe)
{
int timer=100;
if(!pMe->gameover)
{
pMe->block_y++;
if(CanPut(pMe)){
DrawMap(pMe);
}
else
{
pMe->block_y--;
PutBlock(pMe);
GenerateNew(pMe);
DrawMap(pMe);
}
timer=300-pMe->dels*4;
timer=timer>100?timer:100;
ISHELL_SetTimer(pMe->a.m_pIShell, 300, (PFNNOTIFY) update_map, (CGametype *) pMe);
}
else
{
Gameover(pMe,pMe->r_color,pMe->g_color,pMe->b_color);
if(pMe->b_color==0&&pMe->g_color==0&&pMe->r_color==0)
{
ISHELL_CancelTimer(pMe->a.m_pIShell, (PFNNOTIFY) update_map, (CGametype *) pMe);
}
else
{
pMe->r_color=pMe->r_color*4/5;
pMe->g_color=pMe->g_color*4/5;
pMe->b_color=pMe->b_color*4/5;
ISHELL_SetTimer(pMe->a.m_pIShell, 200, (PFNNOTIFY) update_map, (CGametype *) pMe);
}
}
IDISPLAY_Update (pMe->a.m_pIDisplay);
}
//=======================================
/*===========================================================================
FUNCTION: AEEClsCreateInstance
DESCRIPTION
This function is invoked while the app is being loaded. All Modules must provide this
function. Ensure to retain the same name and parameters for this function.
In here, the module must verify the ClassID and then invoke the CGametype_New() function
that has been provided in AEEAppGen.c.
After invoking AEEApplet_New(), this function can do app specific initialization. In this
example, a generic structure is provided so that app developers need not change app specific
initialization section every time except for a call to InitAppData(). This is done as follows:
InitAppData() is called to initialize AppletData instance. It is app developers
responsibility to fill-in app data initialization code of InitAppData(). App developer
is also responsible to release memory allocated for data contained in AppletData -- this can be
done in FreeAppData().
PROTOTYPE:
int AEEAppCreateInstance(AEECLSID clsID, IShell* pIShell, IModule* pIModule,IApplet** ppApplet)
PARAMETERS:
clsID: [in]: Specifies the ClassID of the applet which is being loaded
pIShell: [in]: Contains pointer to the IShell interface.
pIModule: pin]: Contains pointer to the IModule interface to the current module to which
this app belongs
ppApplet: [out]: On return, *ppApplet must point to a valid AEEApplet structure. Allocation
of memory for this structure and initializing the base data members is done by AEEApplet_New().
DEPENDENCIES
none
RETURN VALUE
SUCCESS: If the app needs to be loaded and if AEEApplet_New() invocation was successful
EFAILED: If the app does not need to be loaded or if errors occurred in AEEApplet_New().
If this function returns FALSE, the app will not be loaded.
SIDE EFFECTS
none
===========================================================================*/
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * pMod,void ** ppObj)
{
CGametype *pMe;
*ppObj = NULL;
if(AEEApplet_New( sizeof(CGametype), // Size of our private class
ClsId, // Our class ID
pIShell, // Shell interface
pMod, // Module instance
(IApplet**)ppObj, // Return object
(AEEHANDLER)game_HandleEvent, // Our event handler
NULL)) // No special "cleanup" function
{
pMe=*ppObj;
if(game_InitApp(pMe))
return(AEE_SUCCESS);
}
return (EFAILED);
}
/*===========================================================================
FUNCTION game_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.
Note - The switch statement in the routine is to demonstrate how event handlers are
generally structured. However, realizing the simplicity of the example, the code could
have been reduced as follows:
if(eCode == EVT_APP_START){
IDISPLAY_DrawText();
IDISPLAY_Update();
return(TRUE);
}
return(FALSE);
However, while doing so would have demonstrated how BREW apps can be written in about 8
lines of code (including the app creation function), it might have confused those who wanted
a bit more practical example.
Also note that the use of "szText" below is provided only for demonstration purposes. As
indicated in the documentation, a more practical approach is to load text resources
from the applicaton's resource file.
Finally, note that the ONLY event that an applet must process is EVT_APP_START. Failure
to return TRUE from this event will indicate that the app cannot be started and BREW
will close the applet.
PROTOTYPE:
boolean game_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 AppCreateInstance() 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 game_HandleEvent(CGametype * pMe, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch (eCode){
case EVT_APP_START:
initialmemory(pMe);
GenerateNew(pMe);
DrawMap(pMe);
IDISPLAY_Update (pMe->a.m_pIDisplay);
ISHELL_SetTimer(pMe->a.m_pIShell, 300, (PFNNOTIFY) update_map, (CGametype *) pMe);
return(TRUE);
case EVT_APP_RESUME:
ISHELL_SetTimer(pMe->a.m_pIShell, 300, (PFNNOTIFY) update_map, (CGametype *) pMe);
restorememory(pMe);
return(TRUE);
case EVT_APP_SUSPEND:
case EVT_APP_STOP:
ISHELL_CancelTimer(pMe->a.m_pIShell, (PFNNOTIFY) update_map, (CGametype *) pMe);
return(TRUE);
case EVT_KEY:
switch (wParam)
{
case AVK_CLR:
ISHELL_CancelTimer(pMe->a.m_pIShell, (PFNNOTIFY) update_map, (CGametype *) pMe);
return(FALSE);
case AVK_UP:
if(!pMe->gameover)
{
pMe->a0++;
RotateBlock(pMe);
DrawMap(pMe);
}
break;
case AVK_DOWN:
if(pMe->gameover)
break;
else
{
while (CanPut(pMe))
{
//DrawMap(pMe);
pMe->block_y++;
//IDISPLAY_Update (pMe->a.m_pIDisplay);
};
pMe->block_y--;
PutBlock(pMe);
GenerateNew(pMe);
DrawMap(pMe);
}
break;
case AVK_LEFT:
if(!pMe->gameover)
{
pMe->a0++;
pMe->block_x--;
if (!CanPut(pMe)) pMe->block_x++;
DrawMap(pMe);
}
break;
case AVK_RIGHT:
if(!pMe->gameover)
{
pMe->a0++;
pMe->block_x++;
if (!CanPut(pMe)) pMe->block_x--;
DrawMap(pMe);
}
break;
}
IDISPLAY_Update (pMe->a.m_pIDisplay);
return(TRUE);
default:
break;
}
return(FALSE);
}
static boolean game_InitApp(CGametype * pMe)
{
AEEDeviceInfo devInfo;
ISHELL_GetDeviceInfo(pMe->a.m_pIShell,&devInfo);
pMe->block_width=devInfo.cxScreen/(MAP_WIDTH+8);
pMe->block_height=devInfo.cyScreen/(MAP_HEIGHT+4);
pMe->block_width=pMe->block_height=pMe->block_width>pMe->block_height?pMe->block_height:pMe->block_width;
if(devInfo.nColorDepth>2)
#ifdef COLOR_DISPLAY
pMe->frame_color=GREY_COLOR;
#else
pMe->frame_color=RGB_BLACK;
#endif
pMe->difficult_level=7;
SETAEERECT(&pMe->m_Rect,0,0,devInfo.cxScreen,devInfo.cyScreen);
pMe->a0=0;
pMe->dels=0;
pMe->next_block=1;
pMe->map_line=MAP_WIDTH;
pMe->map_col=MAP_HEIGHT;
pMe->block_x=0;
pMe->block_y=5;
pMe->gameover=0;
pMe->score=0;
pMe->pause=FALSE;
#ifdef COLOR_DISPLAY
pMe->color_table[0]=RGB_NONE;
pMe->color_table[1]=RED_COLOR;
pMe->color_table[2]=BLUE_COLOR;
pMe->color_table[3]=GREEN_COLOR;
pMe->color_table[4]=LIGHT_RED_COLOR;
pMe->color_table[5]=LIGHT_BLUE_COLOR;
pMe->color_table[6]=DARK_GREEN_COLOR;
pMe->color_table[7]=ORANGE_COLOR;
pMe->color_table[8]=PURPLE_COLOR;
pMe->color_table[9]=YELLOW_GREEN_COLOR;
pMe->r_color=0;
pMe->g_color=128;
pMe->b_color=255;
#else
pMe->color_table[0]=RGB_BLACK;
pMe->color_table[1]=RGB_BLACK;
pMe->color_table[2]=RGB_BLACK;
pMe->color_table[3]=RGB_BLACK;
pMe->color_table[4]=RGB_BLACK;
pMe->color_table[5]=RGB_BLACK;
pMe->color_table[6]=RGB_BLACK;
pMe->color_table[7]=RGB_BLACK;
pMe->color_table[8]=RGB_BLACK;
pMe->color_table[9]=RGB_BLACK;
pMe->r_color=225;
pMe->g_color=225;
pMe->b_color=225;
#endif
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -