pacman4console: add package

This commit is contained in:
Henrik Grimler 2019-08-11 11:51:28 +02:00
parent 1dba518c7a
commit bddfdacb44
7 changed files with 416 additions and 0 deletions

View File

@ -0,0 +1,30 @@
--- ../pacman.c.orig 2019-08-11 11:04:35.143786214 +0200
+++ ./pacman.c 2019-08-11 11:10:17.706727190 +0200
@@ -17,7 +17,7 @@
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
-#include <sys/timeb.h>
+#include <sys/time.h>
#include "pacman.h"
#define EXIT_MSG "Good bye!"
@@ -231,14 +231,14 @@
void Delay() {
//Needed to get time
- struct timeb t_start, t_current;
- ftime(&t_start);
+ struct timeval t_start, t_current;
+ gettimeofday(&t_start, NULL);
//Slow down the game a little bit
do {
GetInput(); //Still get the input from keyboard
- ftime(&t_current); //Update time and check if enough time has overlapped
- } while (abs(t_start.millitm - t_current.millitm) < SpeedOfGame);
+ gettimeofday(&t_current, NULL); //Update time and check if enough time has overlapped
+ } while (labs(t_start.tv_usec - t_current.tv_usec)/1000 < SpeedOfGame);
}
/****************************************************************

View File

@ -0,0 +1,260 @@
Subject: Fix some problems and add features.
- Problems fixed:
* Changed screen/window resolution error message.
* Bugfix for possible buffer overflow when choosing a
level. (Closes #641652)
* Bugfix for possible index out of bound when going through
a border while playing. (Closes #641657)
- Feature to allow create a menu icon for X (Closes: #737997):
* Game Over screen which allows to exit or to restart.
- Another features:
* Added a help option (documents before undocumented level
choosing option).
* Changed option syntax for level choosing.
Author: Yannic Scheper <ys42@cd42.de>
Author: Alexandre Dantas <eu@alexdantas.net>
Last-Update: 2014-08-13
--- pacman4console.orig/pacman.c
+++ pacman4console/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);
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;
****************************************************************/
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");
+}
+

View File

@ -0,0 +1,10 @@
--- ./pacman.c~ 2019-08-11 11:40:25.424773750 +0200
+++ ./pacman.c 2019-08-11 11:46:32.051044212 +0200
@@ -33,6 +33,7 @@
void IntroScreen(); //Show introduction screen and menu
int CheckCollision(); //See if Pacman and Ghosts collided
void CheckScreenSize(); //Make sure resolution is at least 32x29
+int GameOverScreen();
void CreateWindows(int y, int x, int y0, int x0); //Make ncurses windows
void Delay(); //Slow down game for better control
void DrawWindow(); //Refresh display

View File

@ -0,0 +1,31 @@
--- ../Makefile.orig 2019-08-11 10:45:43.818342372 +0200
+++ ./Makefile 2019-08-11 11:22:54.202576206 +0200
@@ -1,20 +1,18 @@
-prefix=/usr/local
-bindir=$(prefix)/bin
-datarootdir=$(prefix)/share
+CC?=gcc
+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
+ $(CC) pacman.c -o pacman -DDATAROOTDIR=\"$(datarootdir)\" $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) -lncurses
+ $(CC) 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 -Dm755 pacman pacmanedit $(DESTDIR)$(bindir)/
+ chmod 755 $(DESTDIR)$(datarootdir)/pacman/ -R
uninstall:
rm -f $(DESTDIR)$(bindir)/pacman

View File

@ -0,0 +1,14 @@
TERMUX_PKG_HOMEPAGE=https://sites.google.com/site/doctormike/pacman.html
TERMUX_PKG_DESCRIPTION="A 9 level ncurses pacman game with editor"
TERMUX_PKG_LICENSE="GPL-2.0"
TERMUX_PKG_VERSION=1.3
TERMUX_PKG_SRCURL=https://sites.google.com/site/doctormike/pacman-${TERMUX_PKG_VERSION}.tar.gz
TERMUX_PKG_SHA256=9a5c4a96395ce4a3b26a9896343a2cdf488182da1b96374a13bf5d811679eb90
TERMUX_PKG_DEPENDS="ncurses"
TERMUX_PKG_BUILD_IN_SRC=yes
termux_step_post_make_install() {
mkdir -p "$TERMUX_PREFIX"/share/man/man1 "$TERMUX_PREFIX"/share/man/man6
install -Dm600 $TERMUX_PKG_BUILDER_DIR/pacmanedit.1 "$TERMUX_PREFIX"/share/man/man1/
install -Dm600 $TERMUX_PKG_BUILDER_DIR/pacman.6 "$TERMUX_PREFIX"/share/man/man6/
}

View File

@ -0,0 +1,24 @@
.TH PACMAN 6 "december 8, 2006"
.SH NAME
pacman \- a console based pacman game
.SH SYNOPSIS
.B pacman
.RB [
.I OPTION
.RB ]
.SH DESCRIPTION
This manual page documents briefly the
.B pacman.
.PP
\fBpacman\fP is an ASCII character based game. This game haves nine levels.
.SH OPTION
.B n
- Start level n
.SH SEE ALSO
pacmanedit(1)
.SH AUTHOR
pacman was written by Michael Billars (aka Dr. Mike) and is available at http://doctormike.googlepages.com/pacman.html.
.PP
.nh
.ad l
This manual page was written by Joao Eriberto Mota Filho <eriberto@eriberto.pro.br>, for the Debian project (but may be used by others).

View File

@ -0,0 +1,47 @@
.TH PACMANEDIT 1 "january 4, 2007"
.SH NAME
pacmanedit \- an editor to make pacman mazes
.SH SYNOPSIS
.B pacmanedit
file
.SH DESCRIPTION
This manual page documents briefly the
.B pacmanedit.
.PP
\fBpacmanedit\fP is an editor used to make new pacman mazes.
.SH KEYS
0 Insert space (way)
.br
1 Insert wall
.br
2 Insert pill
.br
3 Insert vitamin
.br
4 Insert an exit for fantasms
.br
5 Change position of the red fantasm
.br
6 Change position of the cyan fantasm
.br
7 Change position of the magenta fantasm
.br
8 Change position of the orange fantasm
.br
9 Change position of the Pacman
.br
f Change all spaces to pills
.br
c Change all pills to spaces
.br
q Save and exit
.SH MAZE FILE LOCATION
The maze files are localized at /usr/share/pacman/Levels.
.SH SEE ALSO
pacman(6)
.SH AUTHOR
pacman was written by Michael Billars (aka Dr. Mike) and is available at http://doctormike.googlepages.com/pacman.html.
.PP
.nh
.ad l
This manual page was written by Joao Eriberto Mota Filho <eriberto@eriberto.pro.br>, for the Debian project (but may be used by others).