aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-04-13 11:09:13 +0000
committerrodri <rgl@antares-labs.eu>2023-04-13 11:09:13 +0000
commit00f7d8dd3dc47ed3cfa951325e809a92c37341b7 (patch)
treebfe2916f4c3d4f0b5f659563bb61586633e7578b
parent42ea627853d79a54ef956a831e2f8badff5bfdb8 (diff)
downloadmusw-00f7d8dd3dc47ed3cfa951325e809a92c37341b7.tar.gz
musw-00f7d8dd3dc47ed3cfa951325e809a92c37341b7.tar.bz2
musw-00f7d8dd3dc47ed3cfa951325e809a92c37341b7.zip
now using PNG files instead of image(6)s. bullet TTL taken into account during stepping.
-rw-r--r--assets/spr/earth.picbin1931 -> 0 bytes
-rw-r--r--assets/spr/earth.pngbin0 -> 2390 bytes
-rw-r--r--assets/spr/intro.picbin74729 -> 0 bytes
-rw-r--r--assets/spr/intro.pngbin0 -> 59615 bytes
-rw-r--r--assets/spr/pulsar.picbin9294 -> 0 bytes
-rw-r--r--assets/spr/pulsar.pngbin0 -> 2642 bytes
-rw-r--r--dat.h2
-rw-r--r--fns.h1
-rw-r--r--musw.c7
-rw-r--r--sprite.c40
-rw-r--r--todo4
-rw-r--r--universe.c13
12 files changed, 61 insertions, 6 deletions
diff --git a/assets/spr/earth.pic b/assets/spr/earth.pic
deleted file mode 100644
index 75d735b..0000000
--- a/assets/spr/earth.pic
+++ /dev/null
Binary files differ
diff --git a/assets/spr/earth.png b/assets/spr/earth.png
new file mode 100644
index 0000000..f76f9f8
--- /dev/null
+++ b/assets/spr/earth.png
Binary files differ
diff --git a/assets/spr/intro.pic b/assets/spr/intro.pic
deleted file mode 100644
index fba25c8..0000000
--- a/assets/spr/intro.pic
+++ /dev/null
Binary files differ
diff --git a/assets/spr/intro.png b/assets/spr/intro.png
new file mode 100644
index 0000000..483329c
--- /dev/null
+++ b/assets/spr/intro.png
Binary files differ
diff --git a/assets/spr/pulsar.pic b/assets/spr/pulsar.pic
deleted file mode 100644
index 2444d31..0000000
--- a/assets/spr/pulsar.pic
+++ /dev/null
Binary files differ
diff --git a/assets/spr/pulsar.png b/assets/spr/pulsar.png
new file mode 100644
index 0000000..85fba7a
--- /dev/null
+++ b/assets/spr/pulsar.png
Binary files 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 <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)
{
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);
}