📄 nec_pingpong.c
字号:
/*********************************************************************
*
* _DrawStopLight
*/
static void _DrawStopLight(int x, int y, int w, int h, int State) {
int Border, i, xL, yL, r;
Border = w / 11;
GUI_SetBkColor(0xE0E0E0);
GUI_SetColor(GUI_BLACK);
_DrawRoundRect(x, y, w, h, 2 * Border);
GUI_SetBkColor(0x686868);
_DrawRoundRect(x + Border, y + Border, w - (2 * Border), h - (2 * Border), Border * 8 / 5);
xL = x + (w >> 1);
r = (h - (2 * Border)) / 6;
for (i = 0; i < 3; i++) {
yL = y + Border + ((h - (2 * Border)) * ((i << 1) + 1) / 6);
GUI_SetColor(GUI_BLACK);
GUI_FillCircle(xL, yL, r - 3);
if ((State >> i) & 1) {
if (i == 0) {
GUI_SetColor(0x0040FF);
} else if (i == 1) {
GUI_SetColor(0x00E0FF);
} else {
GUI_SetColor(0x00FF60);
}
} else {
GUI_SetColor(0x383838);
}
GUI_FillCircle(xL, yL, r - 6);
}
}
/*********************************************************************
*
* _DrawSeggerLogo
*/
static void _DrawMicriumLogo(void) {
int x, y, w, h;
w = (_MicriumLogo.XSize * LOGOMULX / 1000) + 1;
h = (_MicriumLogo.YSize * LOGOMULY / 1000) + 1;
x = LCD_GetXSize() - w - 6;
y = LCD_GetYSize() - h - 6;
GUI_SetBkColor(GUI_BLACK);
GUI_ClearRect(x, y, x + w - 1, y + h - 1);
GUI_DrawBitmapEx(&_MicriumLogo, x + w / 2, y + h / 2,
(_MicriumLogo.XSize / 2) - 1, (_MicriumLogo.YSize / 2) - 1, _MicriumLogoMulX, LOGOMULY);
}
/*********************************************************************
*
* Static code, callbacks
*
**********************************************************************
*/
/*********************************************************************
*
* _OnPaintBkWin
*/
static void _OnPaintBkWin(void) {
char ac[32];
int Time, Winner;
_DrawMicriumLogo();
GUI_SetBkColor(GUI_BLACK);
GUI_SetColor(GUI_YELLOW);
GUI_SetFont(&GUI_Font32_ASCII);
GUI_DispStringHCenterAt("Speed Ball", LCD_GetXSize() * 5 / 6, 8);
GUI_SetFont(&GUI_Font32B_ASCII);
GUI_SetColor(GUI_WHITE);
switch (_GameState) {
case SHOW_MENU:
GUI_ClearRect(0, 40, 639, 439);
GUI_DispStringHCenterAt("Menu", 320, 200);
break;
case SHOW_REDLIGHT:
GUI_ClearRect(260, 80, 500, 400);
GUI_DispStringHCenterAt("On Your Marks !", 380, 200);
_DrawStopLight(40, 40, 180, 400, 1);
break;
case SHOW_YELLOWLIGHT:
GUI_ClearRect(260, 160, 500, 240);
GUI_DispStringHCenterAt("SET..!", 380, 200);
_DrawStopLight(40, 40, 180, 400, 2);
break;
case SHOW_GREENLIGHT:
GUI_ClearRect(260, 160, 500, 240);
GUI_DispStringHCenterAt("GO !", 380, 200);
_DrawStopLight(40, 40, 180, 400, 4);
break;
case SHOW_STOPWATCH:
Time = GUI_GetTime() - _StopWatchTime;
sprintf(ac, "Time: %.2d:%.2d.%.2d", Time / 60000, (Time / 1000) % 60, (Time / 10) % 100);
GUI_ClearRect(0, 40, 639, 439);
GUI_DispStringHCenterAt(ac, 320, 200);
break;
case SHOW_WINNER:
Winner = WINNER(_PlayerTime[0], _PlayerTime[1], _PlayerTime[2]);
GUI_ClearRect(0, 40, 639, 439);
GUI_DispStringHCenterAt("!! WINNER !!", 320, 200);
sprintf(ac, "Player %d", Winner + 1);
GUI_DispStringHCenterAt(ac, 320, 240);
break;
case SHOW_STATISTICS:
GUI_ClearRect(0, 40, 639, 439);
GUI_DispStringHCenterAt("Statistics", 320, 200);
GUI_DispStringAt("1. Player 1 Time: 00:15.63", 120, 250);
GUI_DispStringAt("2. Player 3 Time: 00:18.22", 120, 290);
GUI_DispStringAt("3. Player 2 Time: 00:21.95", 120, 330);
break;
}
}
/*********************************************************************
*
* _cbBkWindow
*/
static void _cbBkWindow(WM_MESSAGE* pMsg) {
switch (pMsg->MsgId) {
case WM_PAINT:
_OnPaintBkWin();
break;
case WM_NOTIFY_PARENT:
if (pMsg->Data.v == WM_NOTIFICATION_RELEASED) {
int Id = WM_GetId(pMsg->hWinSrc);
if (Id == ID_BUTTON_START) {
_NextStep(0);
}
}
break;
case WM_KEY:
case WM_TOUCH:
case WM_PID_STATE_CHANGED:
#if GUI_SUPPORT_MOUSE
case WM_MOUSEOVER:
#endif
_ScreenSaverOff();
break;
default:
WM_DefaultProc(pMsg);
}
}
/*********************************************************************
*
* _cbScreenSaver
*/
static void _cbScreenSaver(WM_MESSAGE* pMsg) {
switch (pMsg->MsgId) {
case WM_PAINT:
GUI_SetBkColor(GUI_BLACK);
GUI_Clear();
_DrawMicriumLogo();
GUI_DrawBitmap(&_LogoNEC, _NECLogoX, _NECLogoY);
break;
case WM_KEY:
case WM_TOUCH:
case WM_PID_STATE_CHANGED:
#if GUI_SUPPORT_MOUSE
case WM_MOUSEOVER:
#endif
_ScreenSaverOff();
break;
default:
WM_DefaultProc(pMsg);
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void);
void MainTask(void) {
GUI_Init();
WM_SetCallback(WM_HBKWIN, &_cbBkWindow);
//_GameState = SHOW_MENU;
GUI_Clear();
while (1) {
_HandleCompanyLogo();
_HandleScreenSaver();
_HandleGame();
GUI_Delay(5);
}
}
/*************************** End of file ****************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -