aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-03-03 11:18:16 +0000
committerrodri <rgl@antares-labs.eu>2023-03-03 11:18:16 +0000
commit9712ec712cc6a57d416ef2b1e86d15ef161016df (patch)
treeb94613b42365f39f48bfaecf411c62a9da32ecaa
parent9b3fb3f39ab9bd2b86da35f000b35c28ccca51f5 (diff)
downloadmusw-9712ec712cc6a57d416ef2b1e86d15ef161016df.tar.gz
musw-9712ec712cc6a57d416ef2b1e86d15ef161016df.tar.bz2
musw-9712ec712cc6a57d416ef2b1e86d15ef161016df.zip
implemented toroidal warping. set a default font.
-rw-r--r--dat.h1
-rw-r--r--musw.c3
-rw-r--r--muswd.c4
-rw-r--r--todo5
-rw-r--r--universe.c33
5 files changed, 42 insertions, 4 deletions
diff --git a/dat.h b/dat.h
index 26755c5..9a27f17 100644
--- a/dat.h
+++ b/dat.h
@@ -141,6 +141,7 @@ struct Universe
double t, timeacc;
void (*step)(Universe*, double);
+ void (*collide)(Universe*);
void (*reset)(Universe*);
};
diff --git a/musw.c b/musw.c
index b7ea5e9..32bf155 100644
--- a/musw.c
+++ b/musw.c
@@ -41,6 +41,7 @@ Image *skymap;
Channel *ingress;
Channel *egress;
NetConn netconn;
+char deffont[] = "/lib/font/bit/pelm/unicode.9.font";
char winspec[32];
int doghosting;
int debug;
@@ -583,7 +584,7 @@ threadmain(int argc, char *argv[])
snprint(winspec, sizeof winspec, "-dx %d -dy %d", SCRWB, SCRHB);
if(newwindow(winspec) < 0)
sysfatal("newwindow: %r");
- if(initdraw(nil, nil, nil) < 0)
+ if(initdraw(nil, deffont, "musw") < 0)
sysfatal("initdraw: %r");
if((mc = initmouse(nil, screen)) == nil)
sysfatal("initmouse: %r");
diff --git a/muswd.c b/muswd.c
index 0813e48..fd4f183 100644
--- a/muswd.c
+++ b/muswd.c
@@ -352,8 +352,10 @@ partywalk:
player->oldkdown = player->kdown;
}
- while(p->u->timeacc >= Δt)
+ while(p->u->timeacc >= Δt){
p->u->step(p->u, Δt);
+ p->u->collide(p->u);
+ }
}
broadcaststate();
diff --git a/todo b/todo
index 6ebcaa8..bfc0a3d 100644
--- a/todo
+++ b/todo
@@ -1,7 +1,7 @@
[ ] collision detection
-[ ] toroidal warping
+[✓] toroidal warping
[ ] respect bullets's ttl
- [ ] communicate this event with the clients
+ [ ] communicate this event to the clients
[ ] explode when the time comes
[ ] fuel consumption
[ ] hyperjump
@@ -13,3 +13,4 @@
[ ] waiting for a player
[ ] main game
[ ] reduce the amount of data sent on every NSsimstate packet
+[ ] the client must try to connect continously
diff --git a/universe.c b/universe.c
index cf310ef..0b3028f 100644
--- a/universe.c
+++ b/universe.c
@@ -71,6 +71,38 @@ universe_step(Universe *u, double Δt)
}
static void
+warp(Particle *p)
+{
+ Rectangle r;
+
+ r = Rect(-SCRW/2, -SCRH/2, SCRW/2, SCRH/2);
+
+ if(p->p.x < r.min.x)
+ p->p.x = r.max.x;
+ if(p->p.y < r.min.y)
+ p->p.y = r.max.y;
+ if(p->p.x > r.max.x)
+ p->p.x = r.min.x;
+ if(p->p.y > r.max.y)
+ p->p.y = r.min.y;
+}
+
+/* collision resolution */
+static void
+universe_collide(Universe *u)
+{
+ Ship *s;
+ Bullet *b;
+
+ for(s = u->ships; s < u->ships+nelem(u->ships); s++){
+ for(b = s->rounds; b < s->rounds+nelem(s->rounds); b++){
+ warp(b);
+ }
+ warp(s);
+ }
+}
+
+static void
universe_reset(Universe *u)
{
int i, j;
@@ -130,6 +162,7 @@ newuniverse(void)
u = emalloc(sizeof(Universe));
memset(u, 0, sizeof *u);
u->step = universe_step;
+ u->collide = universe_collide;
u->reset = universe_reset;
return u;
}