//*****************************************************************************
//
// This task provides overall control of the spiders, spawning and killing them
// in response to presses on the touch screen.
//
//*****************************************************************************
static void
ControlTask(void *pvParameters)
{
    uint32_t ui32Message;
    int32_t i32X, i32Y, i32Spider;

    //
    // Initialize the touch screen driver and register a callback function.
    //
    TouchScreenInit(g_ui32SysClock);
    TouchScreenCallbackSet(ControlTouchCallback);

    //
    // Lower the priority of the touch screen interrupt handler.  This is
    // required so that the interrupt handler can safely call the interrupt-
    // safe FreeRTOS functions (specifically to send messages to the queue).
    //
    IntPrioritySet(INT_ADC0SS3, 0xc0);

    //
    // Loop forever.
    //
    while(1)
    {
        //
        // Read the next message from the queue.
        //
        if(xQueueReceive(g_pControlQueue, &ui32Message, portMAX_DELAY) ==
           pdPASS)
        {
            //
            // Extract the position of the screen touch from the message.
            //
            i32X = ui32Message >> 16;
            i32Y = ui32Message & 65535;

            //
            // Ignore this screen touch if it is not inside the spider area.
            //
            if((i32X >= AREA_X) && (i32X < (AREA_X + AREA_WIDTH)) &&
               (i32Y >= AREA_Y) && (i32Y < (AREA_Y + AREA_HEIGHT)))
            {
                //
                // See if this position collides with any of the spiders.
                //
                i32Spider = SpiderTouchCollide(i32X, i32Y);
                if(i32Spider == -1)
                {
                    //
                    // There is no collision, so create a new spider (if
                    // possible) at this position.
                    //
                    CreateSpider(i32X, i32Y);
                }
                else
                {
                    //
                    // There is a collision, so kill this spider.
                    //
                    HWREGBITW(&g_ui32SpiderDead, i32Spider) = 1;
                }
            }
        }
    }
Beispiel #2
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
    static int nWidth, nHeight;

    switch (iMsg)
    {
        case WM_CREATE:
        {
            SpiderWnd.Create(hwnd, 0, WS_CHILD | WS_VISIBLE, 0, 0, 100, 100);
            dwDifficulty = IDC_DIF_ONECOLOR;
            CreateSpider();

            SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOZORDER);

            dwAppStartTime = GetTickCount();

            return 0;
        }

        case WM_DESTROY:
            PostQuitMessage(0);
            return 0;

        case WM_SIZE:
            nWidth  = LOWORD(lParam);
            nHeight = HIWORD(lParam);

            MoveWindow(SpiderWnd, 0, 0, nWidth, nHeight, TRUE);
            return 0;

        case WM_GETMINMAXINFO:
        {
            MINMAXINFO *mmi;

            mmi = (MINMAXINFO *)lParam;
            mmi->ptMinTrackSize.x = NUM_STACKS * __cardwidth + (NUM_STACKS + 3) * X_BORDER + 12; // Border left and right of 6px
            mmi->ptMinTrackSize.y = GetSystemMetrics(SM_CYCAPTION) +
                                    GetSystemMetrics(SM_CYMENU) +
                                    2 * Y_BORDER +
                                    3 * __cardheight +
                                    6 * yRowStackCardOffset;
            return 0;
        }

        case WM_COMMAND:
            switch (LOWORD(wParam))
            {
                case IDM_GAME_NEW:
                    NewGame();
                    return 0;

                case IDM_GAME_DECK:
                    ShowDeckOptionsDlg(hwnd);
                    return 0;

                case IDM_HELP_CONTENTS:
                    WinHelp(hwnd, szHelpPath, HELP_CONTENTS, 0);//HELP_KEY, (DWORD)"How to play");
                    return 0;

                case IDM_HELP_ABOUT:
                    MessageBox(hwnd, MsgAbout, szAppName, MB_OK|MB_ICONINFORMATION);
                    return 0;

                case IDM_GAME_EXIT:
                    PostMessage(hwnd, WM_CLOSE, 0, 0);
                    return 0;
            }

            return 0;

        case WM_CLOSE:
            if (fGameStarted == false)
            {
                DestroyWindow(hwnd);
                return 0;
            }
            else
            {
                int ret;

                ret = MessageBox(hwnd, MsgQuit, szAppName, MB_YESNO|MB_ICONQUESTION);
                if (ret == IDYES)
                {
                    WinHelp(hwnd, szHelpPath, HELP_QUIT, 0);
                    DestroyWindow(hwnd);
                }
            }
            return 0;
    }
    return DefWindowProc (hwnd, iMsg, wParam, lParam);
}