From 00f7d8dd3dc47ed3cfa951325e809a92c37341b7 Mon Sep 17 00:00:00 2001 From: rodri Date: Thu, 13 Apr 2023 11:09:13 +0000 Subject: now using PNG files instead of image(6)s. bullet TTL taken into account during stepping. --- assets/spr/earth.pic | Bin 1931 -> 0 bytes assets/spr/earth.png | Bin 0 -> 2390 bytes assets/spr/intro.pic | Bin 74729 -> 0 bytes assets/spr/intro.png | Bin 0 -> 59615 bytes assets/spr/pulsar.pic | Bin 9294 -> 0 bytes assets/spr/pulsar.png | Bin 0 -> 2642 bytes dat.h | 2 +- fns.h | 1 + musw.c | 7 ++++--- sprite.c | 40 ++++++++++++++++++++++++++++++++++++++++ todo | 4 +++- universe.c | 13 ++++++++++++- 12 files changed, 61 insertions(+), 6 deletions(-) delete mode 100644 assets/spr/earth.pic create mode 100644 assets/spr/earth.png delete mode 100644 assets/spr/intro.pic create mode 100644 assets/spr/intro.png delete mode 100644 assets/spr/pulsar.pic create mode 100644 assets/spr/pulsar.png diff --git a/assets/spr/earth.pic b/assets/spr/earth.pic deleted file mode 100644 index 75d735b..0000000 Binary files a/assets/spr/earth.pic and /dev/null differ diff --git a/assets/spr/earth.png b/assets/spr/earth.png new file mode 100644 index 0000000..f76f9f8 Binary files /dev/null and b/assets/spr/earth.png differ diff --git a/assets/spr/intro.pic b/assets/spr/intro.pic deleted file mode 100644 index fba25c8..0000000 Binary files a/assets/spr/intro.pic and /dev/null differ diff --git a/assets/spr/intro.png b/assets/spr/intro.png new file mode 100644 index 0000000..483329c Binary files /dev/null and b/assets/spr/intro.png differ diff --git a/assets/spr/pulsar.pic b/assets/spr/pulsar.pic deleted file mode 100644 index 2444d31..0000000 Binary files a/assets/spr/pulsar.pic and /dev/null differ diff --git a/assets/spr/pulsar.png b/assets/spr/pulsar.png new file mode 100644 index 0000000..85fba7a Binary files /dev/null and b/assets/spr/pulsar.png differ diff --git a/dat.h b/dat.h index 2b3929d..3e8e703 100644 --- a/dat.h +++ b/dat.h @@ -124,7 +124,7 @@ struct Particle struct Bullet { Particle; - ulong ttl; /* in s */ + double ttl; /* in s */ int fired; /* XXX: |v| != 0 */ }; diff --git a/fns.h b/fns.h index 8743c71..039081d 100644 --- a/fns.h +++ b/fns.h @@ -46,6 +46,7 @@ void inituniverse(Universe*); */ Sprite *newsprite(Image*, Point, Rectangle, int, ulong); Sprite *readsprite(char*, Point, Rectangle, int, ulong); +Sprite *readpngsprite(char*, Point, Rectangle, int, ulong); void delsprite(Sprite*); /* diff --git a/musw.c b/musw.c index 019410a..75dea1a 100644 --- a/musw.c +++ b/musw.c @@ -526,7 +526,7 @@ redraw(void) case GSPlaying: drawship(&universe->ships[0], screenb); drawship(&universe->ships[1], screenb); - universe->star.spr->draw(universe->star.spr, screenb, subpt(toscreen(universe->star.p), Pt(16,16))); + universe->star.spr->draw(universe->star.spr, screenb, subpt(toscreen(universe->star.p), divpt(universe->star.spr->r.max, 2))); break; } @@ -659,9 +659,9 @@ threadmain(int argc, char *argv[]) sysfatal("readvmodel: %r"); universe->ships[0].mdl = needlemdl; universe->ships[1].mdl = wedgemdl; - universe->star.spr = readsprite("assets/spr/pulsar.pic", ZP, Rect(0,0,64,64), 9, 50); + universe->star.spr = readpngsprite("assets/spr/pulsar.png", ZP, Rect(0,0,64,64), 9, 50); - intro = readsprite("assets/spr/intro.pic", ZP, Rect(0,0,640,480), 1, 0); + intro = readpngsprite("assets/spr/intro.png", ZP, Rect(0,0,640,480), 28, 100); gamestates[GSIntro].δ = intro_δ; gamestates[GSConnecting].δ = connecting_δ; @@ -697,6 +697,7 @@ threadmain(int argc, char *argv[]) gamestate = gamestate->δ(gamestate, &frametime); universe->star.spr->step(universe->star.spr, frametime/1e6); + intro->step(intro, frametime/1e6); redraw(); diff --git a/sprite.c b/sprite.c index 22dd00b..d000768 100644 --- a/sprite.c +++ b/sprite.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include "dat.h" @@ -68,6 +69,45 @@ readsprite(char *sheetfile, Point sp, Rectangle r, int nframes, ulong period) return newsprite(sheet, sp, r, nframes, period); } +static void +decproc(void *arg) +{ + int fd, *pfd; + + pfd = arg; + fd = pfd[2]; + + close(pfd[0]); + dup(fd, 0); + close(fd); + dup(pfd[1], 1); + close(pfd[1]); + + execl("/bin/png", "png", "-t9", nil); + threadexitsall("execl: %r"); +} + +Sprite * +readpngsprite(char *sheetfile, Point sp, Rectangle r, int nframes, ulong period) +{ + Image *sheet; + int fd, pfd[3]; + + if(pipe(pfd) < 0) + sysfatal("pipe: %r"); + fd = open(sheetfile, OREAD); + if(fd < 0) + sysfatal("readpngsprite: %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); + + return newsprite(sheet, sp, r, nframes, period); +} + void delsprite(Sprite *spr) { diff --git a/todo b/todo index bccfa18..e7722ba 100644 --- a/todo +++ b/todo @@ -1,6 +1,6 @@ [ ] collision detection [✓] toroidal warping -[ ] respect bullets's ttl +[✓] respect bullets's ttl [ ] communicate this event to the clients [ ] explode when the time comes [ ] fuel consumption @@ -18,3 +18,5 @@ [ ] more realistic DEC Type 30 CRT emulation [ ] the right colors (fg: 0x3daaf7, fgblur: 0x0063eb, bg0: 0x79cc3e, bg1: 0x7eba1e) [ ] the right decay function +[✓] work with PNG files instead of 9 pics + > big compressed image(6) files can't be used because of the iounit limits. diff --git a/universe.c b/universe.c index 0b3028f..3984488 100644 --- a/universe.c +++ b/universe.c @@ -55,6 +55,7 @@ ship_fire(Ship *s) s->rounds[i].p = s->p; s->rounds[i].v = addpt2(s->v, bv); s->rounds[i].θ = s->θ; + s->rounds[i].ttl = 5; s->rounds[i].fired++; break; } @@ -65,7 +66,14 @@ ship_fire(Ship *s) static void universe_step(Universe *u, double Δt) { + Ship *s; + Bullet *b; + integrate(u, u->t, Δt); + for(s = u->ships; s < u->ships+nelem(u->ships); s++) + for(b = s->rounds; b < s->rounds+nelem(s->rounds); b++) + if(b->fired) + b->ttl -= Δt; u->timeacc -= Δt; u->t += Δt; } @@ -96,7 +104,10 @@ universe_collide(Universe *u) for(s = u->ships; s < u->ships+nelem(u->ships); s++){ for(b = s->rounds; b < s->rounds+nelem(s->rounds); b++){ - warp(b); + if(b->fired && b->ttl <= 0) + b->fired = 0; + if(b->fired) + warp(b); } warp(s); } -- cgit v1.2.3