📄 games_fallball.c
字号:
util_get_text_from_res_w_max_len(PMPT_TEXT_CONGRATULATION,ustr,MAX_STRING_LENGTH);
util_get_text_from_res_w_max_len(PMPT_TEXT_NEW_HIGHSCORE,tmpstr,MAX_STRING_LENGTH);
}
else
{
util_get_text_from_res_w_max_len(PMPT_TEXT_GAME_OVER,ustr,MAX_STRING_LENGTH);
util_get_text_from_res_w_max_len(PMPT_TEXT_YOUR_SCORE,tmpstr,MAX_STRING_LENGTH);
}
Ustrcat(ustr,tmpstr);
op_sprintf(strscore,"%d",score);
AtoU(tmpstr,(OP_UINT8 *)strscore);
Ustrcat(ustr,tmpstr);
gamesApp_data.popupwin=ds_popup_message(OP_NULL, ustr, DS_POPUP_DEFAULT_MSG_TIME);
}
op_debug(DEBUG_MED,"FallNewBall:exit!\n");
}
/*==================================================================================================
FUNCTION: FallballPenProcess
DESCRIPTION:
When the pen clicks ,select or move one ball.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void FallballPenProcess(OP_INT16 x,OP_INT16 y)
{
if(FallballCurPath != (OP_INT8)(MAX_LINE*MAX_COLUMN))
{
op_debug(DEBUG_MED,"FallballPenProcess():returned,not entered.\n");
return;
}
OPUS_Stop_Timer(OPUS_TIMER_GAME_TIMING);
SP_Audio_stop();
if(x < 0 || y < 0)
{
op_debug(DEBUG_MED,"FallballPenProcess():not entered.\n");
return;
}
op_debug(DEBUG_MED,"FallballPenProcess():\n");
if(cur_box[y][x] == FLOOR)
{
if(selected_pos != -1)
{
selected_pos = -1;
MoveBall(x,y);
}
state = 1;
}
else
{
selected_pos = y*MAX_COLUMN+x;
cur_x = x;
cur_y = y;
OPUS_Start_Timer(OPUS_TIMER_GAME_TIMING,200,0,ONE_SHOT);
}
}
/*==================================================================================================
FUNCTION: OnTwingklingTimer
DESCRIPTION:
Twinkling the focus ball.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void OnTwingklingTimer()
{
op_debug(DEBUG_MED,"OnTwingklingTimer():\n");
state = 1 - state;
if(state)
{
DrawSquare(cur_x,cur_y,cur_box[cur_y][cur_x]*2);
}
else
{
DrawSquare(cur_x,cur_y,cur_box[cur_y][cur_x]*2-OFFSET);
}
ds_refresh();
}
/*==================================================================================================
FUNCTION: APP_Fallball_handler
DESCRIPTION:
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
void APP_Fallball_handler(OPUS_EVENT_ENUM_TYPE event,void *pMess,OP_BOOLEAN *handle)
{
TP_PEN_EVENT_STRUCTURE_T *pPen;
KEYEVENT_STRUCT *pKey;
TPO_OPERATION_PARAM_STRUCTURE_T * pOperation_param;
*handle = OP_TRUE;
pPen = pMess;
switch(event)
{
case OPUS_FOCUS_CUST_PAINT:
if ((pMess != OP_NULL) && (*((OP_BOOLEAN *)pMess) == OP_TRUE))
{
if (ds_get_screen_mode() != SCREEN_GENERAL)
ds_set_screen_mode( SCREEN_GENERAL);
ds_set_softkeys_rm( PMPT_SKEY_RESTART,PMPT_SKEY_EMPTY, PMPT_SKEY_BACK);
Repaint();
OPUS_Start_Timer(OPUS_TIMER_GAME_TIMING,200,0,ONE_SHOT);
TPO_SetCurrent_RPU(TPO_RUI_GAMES);
if(FallballCurPath != (OP_INT8)(MAX_LINE*MAX_COLUMN))
{
OPUS_Start_Timer(OPUS_TIMER_GAME_PEN,30,0,ONE_SHOT);
}
op_debug(DEBUG_MED,"APP_Fallball_handler:OPUS_FOCUS_CUST_PAINT has come!\n");
}
else
ds_refresh();
break;
case OPUS_TIMER_POPUP_MSG:
if (gamesApp_data.popupwin != OP_NULL)
{
close_old_popup();
}
Games_change_state((OP_UINT16) APP_GAMES_STATE_MENU);
op_debug(DEBUG_MED,"APP_Fallball_handler:OPUS_TIMER_POPUP_MSG has come.\n");
break;
case OPUS_FOCUS_CUST_APP_PAUSE:
//gamePause=OP_TRUE;
OPUS_Stop_Timer(OPUS_TIMER_GAME_TIMING);
OPUS_Stop_Timer(OPUS_TIMER_GAME_PEN);
if (gamesApp_data.popupwin!= OP_NULL)
{
close_old_popup();
Games_change_state((OP_UINT16) APP_GAMES_STATE_MENU);
}
op_debug(DEBUG_MED,"APP_Fallball_handler:OPUS_FOCUS_CUST_APP_PAUSE has come!\n");
break;
case OPUS_FOCUS_KEYPAD :
pKey = (KEYEVENT_STRUCT *)pMess;
if(pKey->state == UHKEY_RELEASE)
break;
switch(pKey->code)
{
case KEY_SIDE_UP:
SP_Audio_stop();
if (gamesApp_data.volume < VOLUME_LEVEL_SIZE-1)
{
gamesApp_data.volume++;
}
break;
case KEY_SIDE_DOWN:
SP_Audio_stop();
if (gamesApp_data.volume > 0)
{
gamesApp_data.volume--;
}
break;
default:
break;
}
op_debug(DEBUG_MED,"ok!!!key pressed.");
break;
case OPUS_FOCUS_OPERATION:
pOperation_param = (TPO_OPERATION_PARAM_STRUCTURE_T *)pMess;
switch (pOperation_param->op)
{
case OPERATION_ID_SK_CONFIRM:
switch(pOperation_param->id)
{
case COMMAND_SOFTKEY_LEFT:
OPUS_Stop_Timer(OPUS_TIMER_GAME_TIMING);
OPUS_Stop_Timer(OPUS_TIMER_GAME_PEN);
InitFallball();
break;
case COMMAND_SOFTKEY_OK:
break;
case COMMAND_SOFTKEY_RIGHT:
Games_change_state((OP_INT16) APP_GAMES_STATE_MENU);
break;
default:
break;
}
break;
default:
break;
}
op_debug(DEBUG_MED,"APP_Fallball_handler:OPUS_FOCUS_OPERATION has come!\n");
break;
case OPUS_TIMER_GAME_TIMING:
if(selected_pos != -1)
{
OnTwingklingTimer();
OPUS_Start_Timer(OPUS_TIMER_GAME_TIMING,200,0,ONE_SHOT);
}
op_debug(DEBUG_MED,"APP_Fallball_handler:OPUS_TIMER_GAME_TIMING has come!\n");
break;
case OPUS_TIMER_GAME_PEN:
RouteMove(FallballPath);
op_debug(DEBUG_MED,"APP_Fallball_handler:OPUS_TIMER_GAME_PEN has come!\n");
break;
case OPUS_FOCUS_PEN:
if(pPen->state == TP_PEN_STATE_PENDN)
{
FallballPenProcess(pPen->x/SQUARELENGTH,(pPen->y-40)/SQUARELENGTH);
}
op_debug(DEBUG_MED,"APP_Fallball_handler:OPUS_FOCUS_PEN has come!\n");
break;
default:
*handle = OP_FALSE;
break;
}
}
/*==================================================================================================
FUNCTION: APP_Fallball_entry
DESCRIPTION:
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
void APP_Fallball_entry(void)
{
op_debug(DEBUG_MED,"APP_Fallball_entry:entrance of this function!\n");
ds_set_screen_mode(SCREEN_GENERAL);
gamesApp_data.popupwin=OP_NULL;
InitFallball();
TPO_SetCurrent_RPU(TPO_RUI_GAMES); /*Games pen process.*/
op_debug(DEBUG_MED,"APP_Fallball_entry:exit of this function!\n");
}
/*==================================================================================================
FUNCTION: APP_Fallball_exit
DESCRIPTION:
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
void APP_Fallball_exit(void)
{
op_debug(DEBUG_MED,"APP_Fallball_exit:entrance!\n");
OPUS_Stop_Timer(OPUS_TIMER_GAME_TIMING);
OPUS_Stop_Timer(OPUS_TIMER_GAME_PEN);
close_old_popup();
ds_set_softkeys_rm(PMPT_SKEY_EMPTY, PMPT_SKEY_EMPTY, PMPT_SKEY_EMPTY);
SP_Audio_stop();
op_debug(DEBUG_MED,"APP_Fallball_exit:exit!\n");
}
/*==================================================================================================
FUNCTION: Repaint
DESCRIPTION:
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void Repaint()
{
OP_INT16 i,j;
op_debug(DEBUG_MED,"Repaint():\n");
ds_draw_bitmap_image_rm_forward(0,0,BMP_BALL_BACKGROUND);
for(i=0;i<MAX_LINE;i++)
{
for(j=0;j<MAX_COLUMN;j++)
{
if(cur_box != FLOOR)
{
DrawSquare(j,i,cur_box[i][j]*2);
}
}
}
ShowScore();
ds_refresh();
}
/*==================================================================================================
FUNCTION: DrawSquare
DESCRIPTION:
Draw one ball or one empty square.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void DrawSquare(OP_INT16 x,OP_INT16 y,OP_INT16 ball_type)
{
OP_INT8 scorewidth;
OP_INT8 skey_high;
op_debug(DEBUG_MED,"DrawSquare():\n");
if(ds_get_extend_softkey())
{
skey_high = LCD_EXT_SKEY_HIGH;
}
else
{
skey_high = LCD_SKEY_HIGH;
}
scorewidth=LCD_MAX_Y-LCD_ANNUN_HIGH-skey_high-SQUARELENGTH*MAX_LINE;
if(ball_type == FLOOR && (x+y)%2 == 1)
{
ds_draw_icon_rm(x*SQUARELENGTH,y*SQUARELENGTH+scorewidth,ICON_EMPTY_SQUARE_LIGHT+ball_type);
}
else
{
if((x+y)%2 == 1)
{
ds_draw_icon_rm(x*SQUARELENGTH,y*SQUARELENGTH+scorewidth,ICON_EMPTY_SQUARE_LIGHT);
}
else
{
ds_draw_icon_rm(x*SQUARELENGTH,y*SQUARELENGTH+scorewidth,ICON_EMPTY_SQUARE_DEEP);
}
ds_draw_icon_rm(x*SQUARELENGTH,y*SQUARELENGTH+scorewidth,ICON_EMPTY_SQUARE_DEEP+ball_type);
}
}
/*==================================================================================================
FUNCTION: ShowScore
DESCRIPTION:
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void ShowScore(void)
{
OP_UINT8 text_str[MAX_STRING_LENGTH];
OP_UINT8 str_length;
op_debug(DEBUG_MED,"ShowScore():\n");
util_cnvrt_res_into_text(PMPT_TEXT_SCORE,text_str);
if (text_str != OP_NULL)
{
draw_text(AREA_TEXT, 96, 1, LCD_MAX_X-1, text_str, FONT_SIZE_SMALL, COLOR_DARK_GREEN, FOCUS_SKY_LIGHT_BLUE);
str_length = (OP_INT8)ds_get_string_width(text_str, FONT_SIZE_SMALL);
drawDigit(score, (OP_INT16)(96 + str_length), 1);
}
}
/*==================================================================================================
FUNCTION: drawDigit
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void drawDigit(OP_INT16 wInteger,OP_INT16 x, OP_INT16 y)
{
OP_UINT8 buffer[8]={0};
OP_UINT8 strINT[16]={0};
op_debug(DEBUG_MED,"GAME_Fallball:drawDight() for score:score=%d\n",wInteger);
op_sprintf((char *)buffer, "%d", wInteger);
AtoU(strINT, buffer);
op_debug(DEBUG_MED,"strINTbuffer=%s\n",strINT);
draw_text(AREA_TEXT, x, y, LCD_MAX_X-1, strINT, FONT_SIZE_SMALL, COLOR_DARK_GREEN, FOCUS_SKY_LIGHT_BLUE);
}
#endif
#ifdef __cplusplus
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -