diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | nyan.c | 90 | ||||
-rw-r--r-- | res/basic/bg0.png | bin | 247 -> 0 bytes | |||
-rw-r--r-- | res/basic/bg1.png | bin | 264 -> 0 bytes | |||
-rw-r--r-- | res/basic/bg2.png | bin | 271 -> 0 bytes | |||
-rw-r--r-- | res/basic/bg3.png | bin | 269 -> 0 bytes | |||
-rw-r--r-- | res/basic/bg4.png | bin | 282 -> 0 bytes |
7 files changed, 48 insertions, 44 deletions
@@ -1,7 +1,7 @@ RES = /usr/share/nyancat BIN = /usr/bin/nyancat LIBS = -lSDL -lSDL_image -lSDL_mixer -lX11 -FLAGS = -pedantic -Wall -O2 -std=c99 +FLAGS = -pedantic -Wall -O2 -std=c99 -D_GNU_SOURCE INCS = -I. -I/usr/include ${XINERAMAINC} XINERAMAINC = -I/usr/X11R6/include @@ -13,12 +13,14 @@ #include <stdio.h>
#include <stdlib.h>
#include <time.h>
+#include <string.h>
#ifdef XINERAMA
#include <X11/Xlib.h>
#include <X11/extensions/Xinerama.h>
#endif /* XINERAMA */
#define ANIM_FRAMES 5
+#define BUF_SZ 1024
/* Type definitions */
typedef struct {
@@ -93,6 +95,9 @@ static SDL_Surface* stretch_cat[ANIM_FRAMES]; static SDL_Surface** image_set = sparkle_img;
static sparkle_instance* sparkles_list = NULL;
static Uint32 bgcolor;
+static char* RESOURCE_PATH = NULL;
+static char* LOC_BASE_PATH = "res";
+static char* OS_BASE_PATH = "/usr/share/nyancat";
/* Function definitions */
static void
@@ -245,6 +250,9 @@ fillsquare(SDL_Surface* surf, int x, int y, int w, int h, Uint32 col) { static void
handle_args(int argc, char **argv) {
int i;
+
+ /* This REALLY needs to be replaced with getopt */
+
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-hw"))
SURF_TYPE = SDL_HWSURFACE;
@@ -282,6 +290,13 @@ handle_args(int argc, char **argv) { printf("Unrecognised scaling option: %s - please select either 'full' or 'small' cat size.\n", argv[i]);
}
}
+ else if(!strcmp(argv[i], "-r") || !strcmp(argv[i], "--resource")) {
+ if (++i < argc) {
+ if (RESOURCE_PATH)
+ free(RESOURCE_PATH);
+ RESOURCE_PATH = strdup(argv[i]);
+ }
+ }
else if((!strcmp(argv[i], "-r") && strcmp(argv[i], "--resolution")) && i < argc - 2) {
int dims[2] = { atoi(argv[++i]), atoi(argv[++i]) };
if (dims[0] >= 0 && dims[0] < 10000 && dims[1] >= 0 && dims[1] < 5000) { // Borrowed from PixelUnsticker, changed the variable name
@@ -294,6 +309,9 @@ handle_args(int argc, char **argv) { else
printf("Unrecognised option: %s\n", argv[i]);
}
+
+ if (!RESOURCE_PATH)
+ RESOURCE_PATH = "basic";
}
static void
@@ -369,52 +387,33 @@ init(void) { static void
load_images(void) {
int i;
-
- /* Local cat */
- static char *catimgpaths[] = {
- "res/basic/fg00.png",
- "res/basic/fg01.png",
- "res/basic/fg02.png",
- "res/basic/fg03.png",
- "res/basic/fg04.png"};
- /* Installed cat */
- static char *altcatimgpaths[] = {
- "/usr/share/nyancat/basic/fg00.png",
- "/usr/share/nyancat/basic/fg01.png",
- "/usr/share/nyancat/basic/fg02.png",
- "/usr/share/nyancat/basic/fg03.png",
- "/usr/share/nyancat/basic/fg04.png"};
- /* Local sparkles */
- static char *sparklepaths[] = {
- "res/basic/bg0.png",
- "res/basic/bg1.png",
- "res/basic/bg2.png",
- "res/basic/bg3.png",
- "res/basic/bg4.png"};
- /* Installed sparkles */
- static char *altsparklepaths[] = {
- "/usr/share/nyancat/basic/bg0.png",
- "/usr/share/nyancat/basic/bg1.png",
- "/usr/share/nyancat/basic/bg2.png",
- "/usr/share/nyancat/basic/bg3.png",
- "/usr/share/nyancat/basic/bg4.png"};
+ char buffer[1024];
/* Loading logic */
for (i = 0; i < ANIM_FRAMES; ++i) {
- /* Cat images */
- cat_img[i] = load_image(catimgpaths[i]);
- if (!cat_img[i])
- cat_img[i] = load_image(altcatimgpaths[i]);
+ snprintf(buffer, 1024, "%s/%s/fg%02d.png", LOC_BASE_PATH, RESOURCE_PATH, i);
+ cat_img[i] = load_image(buffer);
+ if (!cat_img[i]) {
+ snprintf(buffer, 1024, "%s/%s/fg%02d.png", OS_BASE_PATH, RESOURCE_PATH, i);
+ cat_img[i] = load_image(buffer);
+ }
+
+ snprintf(buffer, 1024, "%s/%s/bg%02d.png", LOC_BASE_PATH, RESOURCE_PATH, i);
+ sparkle_img[i] = load_image(buffer);
+ if (!sparkle_img[i]) {
+ snprintf(buffer, 1024, "%s/%s/bg%02d.png", OS_BASE_PATH, RESOURCE_PATH, i);
+ sparkle_img[i] = load_image(buffer);
+ }
+ }
+
+ /* Check everything loaded properly */
+ for (int i = 0; i < ANIM_FRAMES; ++i)
if (!cat_img[i])
- errout("Error loading foreground images!");
+ errout("Error loading foreground images.");
- /* Sparkle images */
- sparkle_img[i] = load_image(sparklepaths[i]);
- if (!sparkle_img[i])
- sparkle_img[i] = load_image(altsparklepaths[i]);
+ for (int i = 0; i < ANIM_FRAMES; ++i)
if (!sparkle_img[i])
- errout("Error loading background images!");
- }
+ errout("Error loading background images.");
}
static SDL_Surface*
@@ -432,9 +431,14 @@ load_image( const char* path ) { static void
load_music(void) {
- music = Mix_LoadMUS("res/basic/music.ogg");
- if (!music)
- music = Mix_LoadMUS("/usr/share/nyancat/basic/music.ogg");
+ char buffer[1024];
+
+ snprintf(buffer, 1024, "%s/%s/music.ogg", LOC_BASE_PATH, RESOURCE_PATH);
+ music = Mix_LoadMUS(buffer);
+ if (!music) {
+ snprintf(buffer, 1024, "%s/%s/music.ogg", OS_BASE_PATH, RESOURCE_PATH);
+ music = Mix_LoadMUS(buffer);
+ }
if (!music)
printf("Unable to load Ogg file: %s\n", Mix_GetError());
}
diff --git a/res/basic/bg0.png b/res/basic/bg0.png Binary files differdeleted file mode 100644 index 03ba5e9..0000000 --- a/res/basic/bg0.png +++ /dev/null diff --git a/res/basic/bg1.png b/res/basic/bg1.png Binary files differdeleted file mode 100644 index a151b55..0000000 --- a/res/basic/bg1.png +++ /dev/null diff --git a/res/basic/bg2.png b/res/basic/bg2.png Binary files differdeleted file mode 100644 index f83ccac..0000000 --- a/res/basic/bg2.png +++ /dev/null diff --git a/res/basic/bg3.png b/res/basic/bg3.png Binary files differdeleted file mode 100644 index c767724..0000000 --- a/res/basic/bg3.png +++ /dev/null diff --git a/res/basic/bg4.png b/res/basic/bg4.png Binary files differdeleted file mode 100644 index b3b08e4..0000000 --- a/res/basic/bg4.png +++ /dev/null |