puckman: new recipe (#4742)

This commit is contained in:
Crestwave
2020-08-15 00:40:57 +08:00
committed by GitHub
parent a710c2644f
commit ca5fb29d67
2 changed files with 131 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
diff --git a/puckman.c b/puckman.c
index ec9a669..57f59d5 100644
--- a/puckman.c
+++ b/puckman.c
@@ -29,7 +29,11 @@
#include <SDL_image.h>
#include <SDL_gfxPrimitives.h>
-#define PACPATH "/usr/share/puckman/"
+#include <FindDirectory.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
#define SCREEN_WIDTH 461
#define SCREEN_HEIGHT 580
#define RIGHT 0
@@ -1407,8 +1411,21 @@ void Game_init() {
free(str);
game->candy_index = 0;
game->candy_blow_delay = 0;
- char *scores_file = (char *) malloc((strlen(getenv("HOME")) + 25) * sizeof(char));
- snprintf(scores_file, strlen(getenv("HOME")) + 25, "%s/.puckman/highscores.txt", getenv("HOME"));
+
+ char buf[B_PATH_NAME_LENGTH];
+ char *scores_file;
+ if (find_directory(B_USER_SETTINGS_DIRECTORY, 0, false, buf, sizeof(buf)) == B_OK) {
+ char path[B_PATH_NAME_LENGTH];
+ snprintf(path, sizeof(path), "%s/puckman", buf);
+
+ struct stat st = {0};
+ if (stat(path, &st) == -1)
+ mkdir(path, 0755);
+
+ scores_file = (char *) malloc((strlen(path) + 25) * sizeof(char));
+ snprintf(scores_file, strlen(path) + 25, "%s/highscores.txt", path);
+ }
+
game->scores_file = scores_file;
FILE *f;
if ((f = fopen(game->scores_file, "r")) == NULL) {
@@ -1505,16 +1522,26 @@ void Game_process() {
}
}
SDL_Surface *getImage(char *str) {
- int size = strlen("images/") + strlen(str) + strlen(PACPATH) + 1;
- char *path = (char *) malloc(size * sizeof(char));
- snprintf(path, size, "%simages/%s", PACPATH, str);
- SDL_Surface *image = IMG_Load(path);
- if (!image) {
- printf("IMG_Load: %s\n", IMG_GetError());
- cleanUp(1);
- }
- free(path);
- return image;
+ char **paths;
+ size_t pathsCount;
+ if (find_paths(B_FIND_PATH_DATA_DIRECTORY, "puckman", &paths, &pathsCount) == B_OK) {
+ SDL_Surface *image;
+ for (size_t i = 0; i < pathsCount; ++i) {
+ int size = strlen("/images/") + strlen(str) + strlen(paths[i]) + 1;
+ char *path = (char *) malloc(size * sizeof(char));
+ snprintf(path, size, "%s/images/%s", paths[i], str);
+ image = IMG_Load(path);
+ free(path);
+ if (image)
+ break;
+ }
+ free(paths);
+ if (!image) {
+ printf("IMG_Load: %s\n", IMG_GetError());
+ cleanUp(1);
+ }
+ return image;
+ }
}
SDL_Surface *getLetter(int letter) {
char *str = (char *) malloc(13 * sizeof(char));

View File

@@ -0,0 +1,53 @@
SUMMARY="An unofficial clone of the original Namco's Pac-Man"
DESCRIPTION="This game is an unofficial clone of the original Pac-Man game \
and is not endorsed by the registered trademark owners Namco, Inc."
HOMEPAGE="https://github.com/patapizza/puckman"
COPYRIGHT="2009 Julien Odent
2009 Martin Meys"
LICENSE="GNU GPL v3"
REVISION="1"
srcGitRev="f5b809cc843daa99808dcad53da87208e0b67ffe"
SOURCE_URI="$HOMEPAGE/archive/$srcGitRev.tar.gz"
CHECKSUM_SHA256="630d3f08a631d97a798b094789e04f9a89fb9460b5725a8fc4e39630634800a2"
SOURCE_FILENAME="puckman-$srcGitRev.tar.gz"
SOURCE_DIR="puckman-$srcGitRev"
PATCHES="puckman-$portVersion.patch"
ARCHITECTURES="!x86_gcc2 ?x86 x86_64"
SECONDARY_ARCHITECTURES="?x86"
PROVIDES="
puckman$secondaryArchSuffix = $portVersion
app:Puck_Man = $portVersion
"
REQUIRES="
haiku$secondaryArchSuffix
lib:libSDL_1.2$secondaryArchSuffix
lib:libSDL_gfx$secondaryArchSuffix
lib:libSDL_image_1.2$secondaryArchSuffix
"
BUILD_REQUIRES="
haiku${secondaryArchSuffix}_devel
devel:libSDL_1.2$secondaryArchSuffix
devel:libSDL_gfx$secondaryArchSuffix
devel:libSDL_image_1.2$secondaryArchSuffix
"
BUILD_PREREQUIRES="
cmd:gcc$secondaryArchSuffix
"
BUILD()
{
includedir=$(finddir B_SYSTEM_HEADERS_DIRECTORY)$secondaryArchSubDir
gcc puckman.c -Wall -I"$includedir"/SDL -lSDL -lSDL_image -lSDL_gfx \
-o puckman
}
INSTALL()
{
install -m 755 -d "$appsDir" "$dataDir/puckman/images"
install -m 755 puckman "$appsDir/Puck-Man"
install -m 644 images/* "$dataDir/puckman/images"
addAppDeskbarSymlink "$appsDir/Puck-Man"
}