diff options
-rw-r--r-- | assets/spr/earth.pic | bin | 1931 -> 0 bytes | |||
-rw-r--r-- | assets/spr/earth.png | bin | 0 -> 2390 bytes | |||
-rw-r--r-- | assets/spr/intro.pic | bin | 74729 -> 0 bytes | |||
-rw-r--r-- | assets/spr/intro.png | bin | 0 -> 59615 bytes | |||
-rw-r--r-- | assets/spr/pulsar.pic | bin | 9294 -> 0 bytes | |||
-rw-r--r-- | assets/spr/pulsar.png | bin | 0 -> 2642 bytes | |||
-rw-r--r-- | dat.h | 2 | ||||
-rw-r--r-- | fns.h | 1 | ||||
-rw-r--r-- | musw.c | 7 | ||||
-rw-r--r-- | sprite.c | 40 | ||||
-rw-r--r-- | todo | 4 | ||||
-rw-r--r-- | universe.c | 13 |
12 files changed, 61 insertions, 6 deletions
diff --git a/assets/spr/earth.pic b/assets/spr/earth.pic Binary files differdeleted file mode 100644 index 75d735b..0000000 --- a/assets/spr/earth.pic +++ /dev/null diff --git a/assets/spr/earth.png b/assets/spr/earth.png Binary files differnew file mode 100644 index 0000000..f76f9f8 --- /dev/null +++ b/assets/spr/earth.png diff --git a/assets/spr/intro.pic b/assets/spr/intro.pic Binary files differdeleted file mode 100644 index fba25c8..0000000 --- a/assets/spr/intro.pic +++ /dev/null diff --git a/assets/spr/intro.png b/assets/spr/intro.png Binary files differnew file mode 100644 index 0000000..483329c --- /dev/null +++ b/assets/spr/intro.png diff --git a/assets/spr/pulsar.pic b/assets/spr/pulsar.pic Binary files differdeleted file mode 100644 index 2444d31..0000000 --- a/assets/spr/pulsar.pic +++ /dev/null diff --git a/assets/spr/pulsar.png b/assets/spr/pulsar.png Binary files differnew file mode 100644 index 0000000..85fba7a --- /dev/null +++ b/assets/spr/pulsar.png @@ -124,7 +124,7 @@ struct Particle struct Bullet { Particle; - ulong ttl; /* in s */ + double ttl; /* in s */ int fired; /* XXX: |v| != 0 */ }; @@ -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*); /* @@ -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(); @@ -3,6 +3,7 @@ #include <ip.h> #include <mp.h> #include <libsec.h> +#include <thread.h> #include <draw.h> #include <geometry.h> #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) { @@ -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. @@ -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); } |