From: Matthew Mondor Date: Tue, 11 Apr 2023 22:36:56 +0000 (+0000) Subject: Apply patches from pacman4console_1.3-1build3.debian.tar.xz X-Git-Url: http://git.pulsar-zone.net/?a=commitdiff_plain;h=5075a34f235ad1e0f3b5e50924063fc180c00a01;p=pacman.git Apply patches from pacman4console_1.3-1build3.debian.tar.xz --- diff --git a/Makefile b/Makefile index d60ec49..6d0bd53 100755 --- a/Makefile +++ b/Makefile @@ -1,30 +1,27 @@ -prefix=/usr/local -bindir=$(prefix)/bin -datarootdir=$(prefix)/share +PREFIX=/usr/local +BINDIR=$(PREFIX)/bin +DATAROOTDIR=$(PREFIX)/share all: - gcc pacman.c -o pacman -DDATAROOTDIR=\"$(datarootdir)\" $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -lncurses - gcc pacmanedit.c -o pacmanedit -DDATAROOTDIR=\"$(datarootdir)\" $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -lncurses + gcc pacman.c -o pacman -DDATAROOTDIR=\"$(DATAROOTDIR)\" $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -lncurses + gcc pacmanedit.c -o pacmanedit -DDATAROOTDIR=\"$(DATAROOTDIR)\" $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -lncurses install: all - mkdir -p $(DESTDIR)$(bindir) - mkdir -p $(DESTDIR)$(datarootdir)/pacman - cp -fR Levels/ $(DESTDIR)$(datarootdir)/pacman/ - -chown root:games $(DESTDIR)$(bindir)/pacman - -chown root:games $(DESTDIR)$(datarootdir)/pacman -R - chmod 750 $(DESTDIR)$(bindir)/pacman - chmod 750 $(DESTDIR)$(bindir)/pacmanedit - chmod 750 $(DESTDIR)$(datarootdir)/pacman/ -R + install -D pacman $(DESTDIR)/usr/games/pacman4console + install -D pacmanedit $(DESTDIR)/usr/bin/pacman4consoleedit + install -d $(DESTDIR)/usr/share/pacman4console/Levels + install -m 644 Levels/*dat $(DESTDIR)/usr/share/pacman4console/Levels/ + uninstall: - rm -f $(DESTDIR)$(bindir)/pacman - rm -f $(DESTDIR)$(bindir)/pacmanedit - rm -f $(DESTDIR)$(datarootdir)/pacman/Levels/level0[1-9].dat - rm -f $(DESTDIR)$(datarootdir)/pacman/Levels/README - rm -f $(DESTDIR)$(datarootdir)/pacman/Levels/template.dat - if [ -e $(DESTDIR)$(datarootdir)/pacman/Levels/ ] ; then rmdir $(DESTDIR)$(datarootdir)/pacman/Levels/ ; fi - if [ -e $(DESTDIR)$(datarootdir)/pacman/ ] ; then rmdir $(DESTDIR)$(datarootdir)/pacman/ ; fi + rm -f $(DESTDIR)$(BINDIR)/pacman + rm -f $(DESTDIR)$(BINDIR)/pacmanedit + rm -f $(DESTDIR)$(DATAROOTDIR)/pacman/Levels/level0[1-9].dat + rm -f $(DESTDIR)$(DATAROOTDIR)/pacman/Levels/README + rm -f $(DESTDIR)$(DATAROOTDIR)/pacman/Levels/template.dat + if [ -e $(DESTDIR)$(DATAROOTDIR)/pacman/Levels/ ] ; then rmdir $(DESTDIR)$(DATAROOTDIR)/pacman/Levels/ ; fi + if [ -e $(DESTDIR)$(DATAROOTDIR)/pacman/ ] ; then rmdir $(DESTDIR)$(DATAROOTDIR)/pacman/ ; fi -clean: uninstall +clean: rm -f pacman rm -f pacmanedit diff --git a/pacman.c b/pacman.c index fda4a6d..f75b993 100755 --- a/pacman.c +++ b/pacman.c @@ -31,7 +31,7 @@ * PROTOTYPES * *************/ void IntroScreen(); //Show introduction screen and menu -void CheckCollision(); //See if Pacman and Ghosts collided +int CheckCollision(); //See if Pacman and Ghosts collided void CheckScreenSize(); //Make sure resolution is at least 32x29 void CreateWindows(int y, int x, int y0, int x0); //Make ncurses windows void Delay(); //Slow down game for better control @@ -40,11 +40,11 @@ void ExitProgram(const char *message); //Exit and display somet void GetInput(); //Get user input void InitCurses(); //Start up ncurses void LoadLevel(char *levelfile); //Load level into memory -void MainLoop(); //Main program function +int MainLoop(); //Main program function void MoveGhosts(); //Update Ghosts' location void MovePacman(); //Update Pacman's location void PauseGame(); //Pause - +void PrintHelp(char* name); //Print help and exit /******************* * GLOBAL VARIABLES * @@ -76,41 +76,71 @@ int tleft = 0; //How long left for invincibility ****************************************************************/ int main(int argc, char *argv[100]) { - int j = 0; + int loop = 1; //loop program? 0 = no, 1 = yes + char* level = NULL; //level to load + int j = 1; + int i; + for(i = 1; i < argc; ++i) { + if(strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) { + PrintHelp(argv[0]); + return 0; + } + else if(strncmp(argv[i], "--level=", 8) == 0) { + level = argv[i]; + level += 8; + int len = strlen(level); + if(len == 0) { + level = NULL; + } + else if(len == 1) { + for(LevelNumber = '1'; LevelNumber <= '9'; LevelNumber++) { + if(LevelNumber == level[0]) { + j = LevelNumber - '0'; + level = NULL; + break; + } + } + } + } + else { + PrintHelp(argv[0]); + return 0; + } + } + srand( (unsigned)time( NULL ) ); InitCurses(); //Must be called to start ncurses CheckScreenSize(); //Make sure screen is big enough CreateWindows(29, 28, 1, 1); //Create the main and status windows - //If they specified a level to load - if((argc > 1) && (strlen(argv[1]) > 1)) { - argv[1][99] = '\0'; - LoadLevel(argv[1]); //Load it and... - MainLoop(); //Start the game - } - - //If they did not enter a level, display intro screen then use default levels - else { - IntroScreen(); //Show intro "movie" - j = 1; //Set initial level to 1 - - if(argc > 1) j = argv[1][0] - '0'; //They specified a level on which to start (1-9) - - //Load 9 levels, 1 by 1, if you can beat all 9 levels in a row, you're awesome - for(LevelNumber = j; LevelNumber < 10; LevelNumber++) { - - //Replace level string underscore with the actual level number (see pacman.h) - LevelFile[strlen(LevelFile) - 6] = '0'; - LevelFile[strlen(LevelFile) - 5] = LevelNumber + '0'; - - LoadLevel(LevelFile); //Load level into memory - Invincible = 0; //Reset invincibility with each new level - MainLoop(); //Start the level + IntroScreen(); //Show intro "movie" + int start_lives = Lives; + int start_points = Points; + do { + Lives = start_lives; + Points = start_points; + if(level == NULL) { + //j = 1; + //Load levels, 1 by 1, if you can beat all 9 levels in a row, you're awesome + for(LevelNumber = j; LevelNumber < 10; LevelNumber++) { + LevelFile[strlen(LevelFile) - 6] = '0'; + LevelFile[strlen(LevelFile) - 5] = LevelNumber + '0'; + LoadLevel(LevelFile); + Invincible = 0; //Reset invincibility + if(MainLoop() == 1) break; + } } + else { + //Load special non-standard level + LoadLevel(level); + Invincible = 0; //Reset invincibility + MainLoop(); + } - } + if(GameOverScreen() == 1) loop = 0; + } while(loop == 1); //Game has ended, deactivate and end program ExitProgram(EXIT_MSG); @@ -125,7 +155,7 @@ int main(int argc, char *argv[100]) { * Returns: none * * Description: Check and handle if Pacman collided with a ghost * ****************************************************************/ -void CheckCollision() { +int CheckCollision() { //Temporary variable int a = 0; @@ -165,7 +195,7 @@ void CheckCollision() { usleep(1000000); //If no more lives, game over - if(Lives == -1) ExitProgram(END_MSG); + if(Lives == -1) return 1; //If NOT game over... @@ -187,6 +217,7 @@ void CheckCollision() { } } } + return 0; } /**************************************************************** @@ -203,13 +234,41 @@ void CheckScreenSize() { if((h < 32) || (w < 29)) { endwin(); fprintf(stderr, "\nSorry.\n"); - fprintf(stderr, "To play Pacman for Console, your console window must be at least 32x29\n"); + fprintf(stderr, "To play Pacman for Console, your console window must be at least 29x32\n"); fprintf(stderr, "Please resize your window/resolution and re-run the game.\n\n"); exit(0); } } +int GameOverScreen() { + char chr = ' '; + int a, b; + for(a = 0; a < 29; a++) for(b = 0; b < 28; b++) { + mvwaddch(win, a, b, chr); + } + + wattron(win, COLOR_PAIR(Pacman)); + mvwprintw(win, 8, 11, "Game Over"); + + wattron(win, COLOR_PAIR(Normal)); + mvwprintw(win, 14, 2, "Press q to quit ..."); + mvwprintw(win, 16, 2, "... or any other key"); + mvwprintw(win, 17, 6, "to play again"); + + wrefresh(win); + + //And wait + int chtmp; + do { + chtmp = getch(); + } while (chtmp == ERR); + + if(chtmp == 'q' || chtmp == 'Q') + return 1; + return 0; +} + /**************************************************************** * Function: CreateWindows() * * Parameters: y, x, y0, x0 (coords and size of window) * @@ -494,7 +553,7 @@ void IntroScreen() { * Returns: none * * Description: Open level file and load it into memory * ****************************************************************/ -void LoadLevel(char levelfile[100]) { +void LoadLevel(char* levelfile) { int a = 0; int b = 0; size_t l; @@ -555,7 +614,7 @@ void LoadLevel(char levelfile[100]) { * Returns: none * * Description: Control the main execution of the game * ****************************************************************/ -void MainLoop() { +int MainLoop() { DrawWindow(); //Draw the screen wrefresh(win); wrefresh(status); //Refresh it just to make sure @@ -564,15 +623,15 @@ void MainLoop() { /* Move Pacman. Move ghosts. Check for extra life awarded from points. Pause for a brief moment. Repeat until all pellets are eaten */ do { - MovePacman(); DrawWindow(); CheckCollision(); - MoveGhosts(); DrawWindow(); CheckCollision(); + MovePacman(); DrawWindow(); if (CheckCollision() == 1) return 1; + MoveGhosts(); DrawWindow(); if (CheckCollision() == 1) return 1; if(Points > FreeLife) { Lives++; FreeLife *= 2;} Delay(); } while (Food > 0); DrawWindow(); //Redraw window and... usleep(1000000); //Pause, level complete - + return 0; } /**************************************************************** @@ -748,3 +807,12 @@ void PauseGame() { } while (chtmp == ERR); } + +void PrintHelp(char* name) { + printf("Usage: %s [OPTION]\n\n", name); + printf("Options:\n"); + printf(" -h, --help print help\n"); + printf(" --level=[1..9] start at specified standard level\n"); + printf(" --level=LEVEL play specified non-standard LEVEL\n"); +} + diff --git a/pacman.h b/pacman.h index b460e42..008c141 100755 --- a/pacman.h +++ b/pacman.h @@ -1,9 +1,7 @@ // Some variables that you may want to change -#ifndef DATAROOTDIR -# define DATAROOTDIR "/usr/local/share" -#endif -#define LEVELS_FILE DATAROOTDIR "/pacman/Levels/level__.dat" +#define DATAROOTDIR "/usr/share" +#define LEVELS_FILE DATAROOTDIR "/pacman4console/Levels/level__.dat" char LevelFile[] = LEVELS_FILE; //Locations of default levels int FreeLife = 1000; //Starting points for free life int Points = 0; //Initial points