📄 games_lightup.c
字号:
if(gamesApp_data.popupwin != OP_NULL)
{
close_old_popup();
}
OPUS_Stop_Timer(OPUS_TIMER_GAME_TIMING);
APP_Lightup_Init();
break;
case KEY_SOFT_RIGHT:
case KEY_CLEAR:
if(gamesApp_data.popupwin != OP_NULL)
{
close_old_popup();
}
inGame=OP_FALSE;
OPUS_Stop_Timer(OPUS_TIMER_GAME_TIMING);
Games_change_state((OP_UINT8) APP_GAMES_STATE_MENU);
break;
case KEY_END:
inGame=OP_FALSE;
OPUS_Stop_Timer(OPUS_TIMER_GAME_TIMING);
break;
default:
break;
}
}
/*==================================================================================================
FUNCTION: moveCursor
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void moveCursor(DIRECTION direct)
{
DrawCursor(OP_FALSE);
switch(direct)
{
case DOWN:
if (cursorI<totalRow-1)
{
cursorI++;
}
break;
case UP:
if (cursorI >0)
{
cursorI--;
}
break;
case LEFT:
if ( cursorJ > 0)
{
cursorJ--;
}
break;
case RIGHT:
if (cursorJ < totalCol-1)
{
cursorJ++;
}
break;
default:
break;
}
DrawCursor(OP_TRUE);
ds_refresh();
}
/*==================================================================================================
FUNCTION: switchLights
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void switchLights(void)
{
if (gamesApp_data.audio_on == OP_TRUE)
{
SP_Audio_play_request(sound_list[1], gamesApp_data.volume, OP_FALSE);
}
if (map[cursorI][cursorJ] == ON)
{
map[cursorI][cursorJ] = OFF;
on_lights--;
}
else
{
map[cursorI][cursorJ] = ON;
on_lights++;
}
DrawSquare(cursorI, cursorJ);
if (cursorI>0)
{
if (map[cursorI-1][cursorJ] == ON)
{
map[cursorI-1][cursorJ] = OFF;
on_lights--;
}
else
{
map[cursorI-1][cursorJ] = ON;
on_lights++;
}
DrawSquare((OP_UINT8)(cursorI-1), cursorJ);
}
if (cursorI<totalRow-1)
{
if (map[cursorI+1][cursorJ] == ON)
{
map[cursorI+1][cursorJ] = OFF;
on_lights--;
}
else
{
map[cursorI+1][cursorJ] = ON;
on_lights++;
}
DrawSquare((OP_UINT8)(cursorI+1), cursorJ);
}
if (cursorJ>0)
{
if (map[cursorI][cursorJ-1] == ON)
{
map[cursorI][cursorJ-1] = OFF;
on_lights--;
}
else
{
map[cursorI][cursorJ-1] = ON;
on_lights++;
}
DrawSquare(cursorI, (OP_UINT8)(cursorJ-1));
}
if (cursorJ<totalCol-1)
{
if (map[cursorI][cursorJ+1] == ON)
{
map[cursorI][cursorJ+1] = OFF;
on_lights--;
}
else
{
map[cursorI][ cursorJ+1] = ON;
on_lights++;
}
DrawSquare(cursorI, (OP_UINT8)(cursorJ+1));
}
DrawCursor(OP_TRUE);
ShowStatus();
ds_refresh();
if (on_lights== totalRow * totalCol)
ShowGameOver(step);
}
/*==================================================================================================
FUNCTION: Paint
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void Paint(void)
{
OP_UINT8 i,j;
for (i=0;i<totalRow;i++)
for (j=0;j<totalCol;j++)
{
DrawSquare(i,j);
}
ShowStatus();
DrawCursor(OP_TRUE);
ds_set_softkeys_rm( PMPT_SKEY_RESTART,PMPT_SKEY_EMPTY, PMPT_SKEY_BACK);
ds_refresh();
}
/*==================================================================================================
FUNCTION: DrawSquare
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void DrawSquare(OP_UINT8 row, OP_UINT8 col)
{
OP_INT16 x,y;
RM_RESOURCE_ID_T bitmapid;
x = (OP_INT16) (xoffset+col*square_width);
y = (OP_INT16) (yoffset+row*square_width);
if(square_width == 30 )
{
if (map[row][col]==ON)
{
bitmapid = BMP_GAME_LIGHTUP_ON;
}
else
{
bitmapid = BMP_GAME_LIGHTUP_OFF;
}
}
else
{
if(square_width == 44)
{
if (map[row][col]==ON)
{
bitmapid = BMP_GAME_LIGHTUP_ON_SECOND;
}
else
{
bitmapid = BMP_GAME_LIGHTUP_OFF_SECOND;
}
}
else
{
if (map[row][col]==ON)
{
bitmapid = BMP_GAME_LIGHTUP_ON_THIRD;
}
else
{
bitmapid = BMP_GAME_LIGHTUP_OFF_THIRD;
}
}
}
ds_draw_bitmap_image_rm(x,y, bitmapid);
}
/*==================================================================================================
FUNCTION: DrawCursor
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void DrawCursor(OP_BOOLEAN on_off)
{
OP_INT16 x,y;
OP_INT16 x1,y1;
DS_COLOR color;
if (on_off == OP_TRUE)
{
color = COLOR_RED;
}
else
{
color = COLOR_TRANS;
}
x = (OP_INT16) xoffset+cursorJ*square_width + square_width/2;
x1 = (OP_INT16) xoffset+cursorJ*square_width + square_width/4;
y = (OP_INT16) yoffset+cursorI*square_width + square_width/4;
y1 = (OP_INT16) yoffset+cursorI*square_width + square_width/2;
ds_draw_line_forward(x, y, x, (OP_INT16)(y+square_width/2), color);
ds_draw_line_forward(x1, y1, (OP_INT16)(x1+square_width/2), y1, color);
}
/*==================================================================================================
FUNCTION: ShowStatus
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void ShowStatus(void)
{
OP_UINT8 str_length;
ds_fill_rect(3, 155, 173, 175, COLOR_DARK_BLUE);
util_cnvrt_res_into_text(PMPT_TEXT_STEP,text_str);
if (text_str != OP_NULL)
{
draw_text(AREAMASK_BITMAP, 15, 157, LCD_MAX_X-1, text_str, FONT_SIZE_SMALL, COLOR_BLUE_VIOLET, COLOR_DARK_BLUE);
str_length = (OP_UINT8)ds_get_string_width(text_str, FONT_SIZE_SMALL);
drawDigit(step, (OP_INT16)(15 + str_length), 157);
}
util_cnvrt_res_into_text(PMPT_TEXT_ON,text_str);
if (text_str != OP_NULL)
{
draw_text(AREAMASK_BITMAP, 107, 157, LCD_MAX_X-1, text_str, FONT_SIZE_SMALL, COLOR_BLUE_VIOLET, COLOR_DARK_BLUE);
str_length = (OP_UINT8)ds_get_string_width(text_str, FONT_SIZE_SMALL);
drawDigit(on_lights, (OP_INT16)(107 + str_length), 157);
}
}
/*==================================================================================================
FUNCTION: LightupRun
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void LightupRun(void )
{
OPUS_Stop_Timer(OPUS_TIMER_GAME_TIMING);
state= 1-state;
if (state)
{
DrawCursor(OP_TRUE);
}
else
{
DrawCursor(OP_FALSE);
}
ds_refresh();
OPUS_Start_Timer(OPUS_TIMER_GAME_TIMING, 500, 0, PERIODIC);
}
/*==================================================================================================
FUNCTION: drawDigit
DESCRIPTION:
Description of this specific function.
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void drawDigit(OP_UINT16 wInteger,OP_INT16 x, OP_INT16 y)
{
OP_UINT8 buffer[8];
OP_UINT8 strINT[16];
op_sprintf((char *)buffer, "%d", wInteger);
AtoU(strINT, buffer);
draw_text(AREAMASK_BITMAP, x, y, LCD_MAX_X-1, strINT, FONT_SIZE_SMALL, COLOR_BLUE_VIOLET, COLOR_DARK_BLUE);
}
/*==================================================================================================
FUNCTION: ShowGameOver
DESCRIPTION:
ARGUMENTS PASSED:
RETURN VALUE:
IMPORTANT NOTES:
==================================================================================================*/
static void ShowGameOver(OP_UINT16 wScore)
{
char ss[4];
OP_UINT8 ustr[MAX_STRING_LENGTH];
OP_UINT8 tmpstr[MAX_STRING_LENGTH];
APP_GAMES_ID_ENUM_T game_id;
switch(gamesApp_data.select_item)
{
case 1:
game_id = APP_GAMES_LIGHTUP_3;
break;
case 2:
game_id = APP_GAMES_LIGHTUP_4;
break;
case 3:
game_id = APP_GAMES_LIGHTUP_5;
break;
default:
break;
}
inGame=OP_FALSE;
if (gamesApp_data.audio_on == OP_TRUE)
{
SP_Audio_play_request(sound_list[2], gamesApp_data.volume, OP_FALSE);
}
op_memset((void*)ustr, 0, MAX_STRING_LENGTH);
op_memset((void*)tmpstr, 0, MAX_STRING_LENGTH);
OPUS_Stop_Timer(OPUS_TIMER_GAME_TIMING);
if (wScore > 0 && gamesApp_data.select_item>0 && is_new_highscore(game_id, wScore))
{
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_STEP,tmpstr,MAX_STRING_LENGTH);
}
Ustrcat(ustr,tmpstr);
op_sprintf(ss,"%d",wScore);
AtoU(tmpstr,(OP_UINT8 *)ss);
Ustrcat(ustr,tmpstr);
gamesApp_data.popupwin=ds_popup_message(OP_NULL, ustr, DS_POPUP_DEFAULT_MSG_TIME);
}
/*==================================================================================================
GLOBAL FUNCTIONS
==================================================================================================*/
/*================================================================================================*/
#endif
#ifdef __cplusplus
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -