aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2024-11-15 22:28:23 +0000
committerrodri <rgl@antares-labs.eu>2024-11-15 22:28:23 +0000
commit30ac819359e5d6de7f6622ba6c01e79457fe8277 (patch)
treee6cb97d446f753d403ed20c95a6a6d739d239656
parent671c2cac38ffada7f9185b87ec27b84566db8c2b (diff)
downloadbattleship-30ac819359e5d6de7f6622ba6c01e79457fe8277.tar.gz
battleship-30ac819359e5d6de7f6622ba6c01e79457fe8277.tar.bz2
battleship-30ac819359e5d6de7f6622ba6c01e79457fe8277.zip
bts: add a cover image.
-rwxr-xr-xassets/vfx/battleship.pngbin0 -> 131400 bytes
-rw-r--r--bts.c4
-rw-r--r--fns.h1
-rw-r--r--sprite.c39
4 files changed, 33 insertions, 11 deletions
diff --git a/assets/vfx/battleship.png b/assets/vfx/battleship.png
new file mode 100755
index 0000000..e085e83
--- /dev/null
+++ b/assets/vfx/battleship.png
Binary files differ
diff --git a/bts.c b/bts.c
index 9dec67c..ab5a6c8 100644
--- a/bts.c
+++ b/bts.c
@@ -135,6 +135,7 @@ char titlefontpath[] = "font/gunmetal/gunmetal.48.font";
Font *titlefont;
char winspec[32];
char uid[8+1], oid[8+1];
+Image *coverimg;
Sprite *spritetab[NVFX];
Vfx vfxqueue;
Channel *drawchan;
@@ -353,6 +354,7 @@ drawtitle(Image *dst)
static char s[] = "BATTLESHIP";
string(dst, Pt(SCRW/2 - stringwidth(titlefont, s)/2, 0), pal[PCWhite], ZP, titlefont, s);
+ draw(dst, rectaddpt(coverimg->r, subpt(dst->r.max, subpt(coverimg->r.max, coverimg->r.min))), coverimg, nil, ZP);
}
void
@@ -612,6 +614,8 @@ initvfx(void)
{
char aux[64];
+ snprint(aux, sizeof aux, "%s/%s", assetdir, "vfx/battleship.png");
+ coverimg = readpngimage(aux);
snprint(aux, sizeof aux, "%s/%s", assetdir, "vfx/hit.png");
spritetab[VFXHit] = readpngsprite(aux, ZP, Rect(0, 0, 32, 32), 12, 100);
snprint(aux, sizeof aux, "%s/%s", assetdir, "vfx/miss.png");
diff --git a/fns.h b/fns.h
index c8f8fde..0356537 100644
--- a/fns.h
+++ b/fns.h
@@ -40,6 +40,7 @@ void delmenulist(Menulist*);
*/
Sprite *newsprite(Image*, Point, Rectangle, int, ulong);
Sprite *readsprite(char*, Point, Rectangle, int, ulong);
+Image *readpngimage(char*);
Sprite *readpngsprite(char*, Point, Rectangle, int, ulong);
void delsprite(Sprite*);
diff --git a/sprite.c b/sprite.c
index 3766fe2..f9cbacf 100644
--- a/sprite.c
+++ b/sprite.c
@@ -90,27 +90,44 @@ decproc(void *arg)
close(pfd[1]);
execl("/bin/png", "png", "-t9", nil);
- threadexitsall("execl: %r");
+ sysfatal("execl: %r");
}
-Sprite *
-readpngsprite(char *sheetfile, Point sp, Rectangle r, int nframes, ulong period)
+Image *
+readpngimage(char *path)
{
- Image *sheet;
+ Image *i;
int fd, pfd[3];
if(pipe(pfd) < 0)
sysfatal("pipe: %r");
- fd = open(sheetfile, OREAD);
+ fd = open(path, OREAD);
if(fd < 0)
- sysfatal("readpngsprite: %r");
+ sysfatal("open: %r");
pfd[2] = fd;
- procrfork(decproc, pfd, mainstacksize, RFFDG|RFNAMEG|RFNOTEG);
- close(pfd[1]);
- sheet = readimage(display, pfd[0], 1);
- close(pfd[0]);
- close(fd);
+ switch(fork()){
+ case -1:
+ sysfatal("fork: %r");
+ case 0:
+ decproc(pfd);
+ default:
+ close(pfd[1]);
+ i = readimage(display, pfd[0], 1);
+ close(pfd[0]);
+ close(fd);
+ }
+
+ return i;
+}
+
+Sprite *
+readpngsprite(char *sheetfile, Point sp, Rectangle r, int nframes, ulong period)
+{
+ Image *sheet;
+ sheet = readpngimage(sheetfile);
+ if(sheet == nil)
+ sysfatal("readpngimage: %r");
return newsprite(sheet, sp, r, nframes, period);
}