/*
          __
         / /_______________  ____  ___
        / __/ ___/ ___/ __ \/ __ \/ _ \
       / /_(__  ) /__/ /_/ / /_/ /  __/
       \__/____/\___/\____/ .___/\___/
                         /_/

    testjoystick.c
*/

#include <tscope.h>

int main()
{
    // initialize the screen
    ts_debug(DEBUG0);
    ts_scrsize(SIZE1);
    ts_init();

    // define the response keys
    ts_defkey(J1);
    ts_defkey(J2);
    ts_defkey(J3);
    ts_defkey(J4);
    ts_defkey(J5);
    ts_defkey(J6);
    ts_defkey(J7);
    ts_defkey(J8);
    ts_defkey(J9);
    ts_defkey(J10);
    int space = ts_defkey(KEY_SPACE);

    // some instructions
    ts_printf(-XMAX + 20, YMAX - 40, "testjoystick.c");
    ts_printf(-XMAX + 20, YMAX - 50,
              "When a keypress is detected the corresponding code will be highlighted");
    ts_printf(-XMAX + 20, YMAX - 60, "Press space to exit");

    // draw the button array
    int i, r;
    for (i = 1; i <= 10; i++)
        ts_printf_centre(0 + i * 30 - 165, 0, "M%d", i);

    // update the button array
    do {
        r = ts_respstatus();
        if (r) {
            for (i = 1; i <= 10; i++) {
                if (i == r) {
                    ts_fgcolor(RED);
                    ts_printf_centre(0 + i * 30 - 165, 0, "M%d", i);
                    ts_wait(mtt(1000));
                    ts_fgcolor(WHITE);
                    ts_printf_centre(0 + i * 30 - 165, 0, "M%d", i);
                }
            }
        }
    } while (r != space);

    // exit
    return 0;
}

END_OF_MAIN();


top
Persoonlijke pagina Universiteit GentTscope
Allegro | Cygwin | Gcc
© See license.html for copyright information