diff -Naur pacman-1.2/ChangeLog pacman-1.2a/ChangeLog --- pacman-1.2/ChangeLog 2006-12-13 23:03:51.000000000 -0600 +++ pacman-1.2a/ChangeLog 2008-08-08 11:00:42.000000000 -0500 @@ -1,5 +1,8 @@ Pacman for Console +2008-07-21 - 1.2a + - added wiimote support + 2006-12-12 - 1.2 - added a simple level editor diff -Naur pacman-1.2/Makefile pacman-1.2a/Makefile --- pacman-1.2/Makefile 2006-12-13 22:52:19.000000000 -0600 +++ pacman-1.2a/Makefile 2008-07-21 04:53:39.000000000 -0500 @@ -1,6 +1,6 @@ all: - gcc -lncurses pacman.c -o pacman - gcc -lncurses pacmanedit.c -o pacmanedit + gcc -lwiiuse -lncurses pacman.c -o pacman + gcc -lwiiuse -lncurses pacmanedit.c -o pacmanedit install: all cp pacman /usr/local/bin diff -Naur pacman-1.2/README pacman-1.2a/README --- pacman-1.2/README 2006-12-12 18:49:03.000000000 -0600 +++ pacman-1.2a/README 2008-08-08 11:09:01.000000000 -0500 @@ -8,12 +8,26 @@ ---------------------- See COPYING for details on the GNU/GPL + +For Wiimote Support +------------------- +Wiiuse must be installed first +http://sourceforge.net/project/showfiles.php?group_id=187194 + +Use the directional pad to move around +HOME button is to exit + +If no wiimote dectected, +keyboard will be used to play the game + + Compile/Install --------------- To make... gee... let's see. type 'make' To install... type 'make install' To run...type 'pacman [level_#]' where # is 1-9, for a premade level OR type 'pacmac [level_file_name]' for a custom level you made + To uninstall... type 'make uninstall' i.e.: make && su -c "make install" diff -Naur pacman-1.2/pacman.c pacman-1.2a/pacman.c --- pacman-1.2/pacman.c 2006-12-13 22:51:58.000000000 -0600 +++ pacman-1.2a/pacman.c 2008-08-08 11:13:38.000000000 -0500 @@ -3,6 +3,10 @@ * By: Rev. Dr. Mike Billars (doctormike@gmail.com) * * Date: 2006-12-12 * * * +* Pacman For Console Wiimote Support Patch * +* By: Juan Antonio Sauceda (5k18ur@gmail.com) * +* Date: 2008-7-21 * +* * * Please see file COPYING for details on licensing * * and redistribution of this program * * * @@ -10,11 +14,15 @@ #include #include +#include +#include #include #include #include #include "pacman.h" +#define MAX_WIIMOTES 1 + void IntroScreen(); //Show introduction screen and menu void CheckCollision(); //See if Pacman and Ghosts collided void CheckScreenSize(); //Make sure resolution is at least 32x29 @@ -48,8 +56,39 @@ int GhostsInARow = 0; //Keep track of how many points to give for eating ghosts int tleft = 0; //How long left for invincibility +int wiimote_in_use = 0; + +wiimote** wiimotes; + int main(int argc, char *argv[100]) { + int found, connected; + + wiimotes = wiiuse_init(MAX_WIIMOTES); + + printf ("Press 1 + 2 to connect wiimote.\n"); + + found = wiiuse_find(wiimotes, MAX_WIIMOTES, 5); + if (!found) { + printf ("No wiimotes found.\n"); + } + + connected = wiiuse_connect(wiimotes, MAX_WIIMOTES); + if (connected) + {printf("Connected to %i wiimotes (of %i found).\n", connected, found); + wiimote_in_use = 1; + + //Rumble wiimote once connected + wiiuse_set_leds(wiimotes[0], WIIMOTE_LED_1); + wiiuse_rumble(wiimotes[0], 1); + usleep(1500000); + wiiuse_rumble(wiimotes[0], 0); + } + else { + printf("Failed to connect to any wiimote.\n"); + printf("Using Keyboard\n"); + usleep(2000000);} + int j = 0; srand( (unsigned)time( NULL ) ); @@ -84,7 +123,6 @@ } } - ExitProgram("Good bye!"); } @@ -140,7 +178,7 @@ void CheckScreenSize() { //Make sure the window is big enough int h, w; getmaxyx(stdscr, h, w); - if((h < 32) || (w < 29)) { + if((h < 25) || (w < 29)) { endwin(); fprintf(stderr, "\nSorry.\n"); fprintf(stderr, "To play Pacman for Console, your console window must be at least 32x29\n"); @@ -219,11 +257,15 @@ void ExitProgram(char message[255]) { endwin(); + if(wiimote_in_use == 1) wiiuse_cleanup(wiimotes, MAX_WIIMOTES); printf("%s\n", message); exit(0); } void GetInput() { + +if (wiimote_in_use == 0){ + int ch; static int chtmp; @@ -232,7 +274,8 @@ //Buffer input if(ch == ERR) ch = chtmp; chtmp = ch; - + + //Using keyboard switch switch (ch) { case KEY_UP: case 'w': case 'W': if((Level[Loc[4][0] - 1][Loc[4][1]] != 1) @@ -264,12 +307,26 @@ break; case 'q': case 'Q': - ExitProgram("Bye"); + ExitProgram("Good Bye"); break; } } +//Using Wiimote switch +else if (wiimote_in_use == 1){ + int i = 0; + if (wiiuse_poll(wiimotes, MAX_WIIMOTES)) { + switch (wiimotes[i]->event) { + case WIIUSE_EVENT: + /* a generic event occured */ + handle_event(wiimotes[i]); + break;} + } + + } +} + void InitCurses() { initscr(); start_color(); @@ -559,3 +616,39 @@ } while (chtmp == ERR); } + + +void handle_event(struct wiimote_t* wm) { + + if ((IS_PRESSED(wm, WIIMOTE_BUTTON_UP)) || + (IS_HELD(wm, WIIMOTE_BUTTON_UP)) || + (IS_RELEASED(wm, WIIMOTE_BUTTON_UP))) + {if((Level[Loc[4][0] - 1][Loc[4][1]] != 1) + && (Level[Loc[4][0] - 1][Loc[4][1]] != 4)) + { Dir[4][0] = -1; Dir[4][1] = 0; } + } + if ((IS_PRESSED(wm, WIIMOTE_BUTTON_DOWN)) || + (IS_HELD(wm, WIIMOTE_BUTTON_DOWN)) || + (IS_RELEASED(wm, WIIMOTE_BUTTON_DOWN))) + {if((Level[Loc[4][0] + 1][Loc[4][1]] != 1) + && (Level[Loc[4][0] + 1][Loc[4][1]] != 4)) + { Dir[4][0] = 1; Dir[4][1] = 0; } + } + if ((IS_PRESSED(wm, WIIMOTE_BUTTON_LEFT)) || + (IS_HELD(wm, WIIMOTE_BUTTON_LEFT)) || + (IS_RELEASED(wm, WIIMOTE_BUTTON_LEFT))) + {if((Level[Loc[4][0]][Loc[4][1] - 1] != 1) + && (Level[Loc[4][0]][Loc[4][1] - 1] != 4)) + { Dir[4][0] = 0; Dir[4][1] = -1; } + } + if ((IS_PRESSED(wm, WIIMOTE_BUTTON_RIGHT)) || + (IS_HELD(wm, WIIMOTE_BUTTON_RIGHT)) || + (IS_RELEASED(wm, WIIMOTE_BUTTON_RIGHT))) + {if((Level[Loc[4][0]][Loc[4][1] + 1] != 1) + && (Level[Loc[4][0]][Loc[4][1] + 1] != 4)) + { Dir[4][0] = 0; Dir[4][1] = 1; } + } + if (IS_PRESSED(wm, WIIMOTE_BUTTON_HOME)) + ExitProgram("Good Bye"); +} +