ref: 9712ec712cc6a57d416ef2b1e86d15ef161016df
parent: 9b3fb3f39ab9bd2b86da35f000b35c28ccca51f5
author: rodri <rgl@antares-labs.eu>
date: Fri Mar 3 06:18:16 EST 2023
implemented toroidal warping. set a default font.
--- a/dat.h
+++ b/dat.h
@@ -141,6 +141,7 @@
double t, timeacc;
void (*step)(Universe*, double);
+ void (*collide)(Universe*);
void (*reset)(Universe*);
};
--- a/musw.c
+++ b/musw.c
@@ -41,6 +41,7 @@
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 @@
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");
--- a/muswd.c
+++ b/muswd.c
@@ -352,8 +352,10 @@
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();
--- 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
--- a/universe.c
+++ b/universe.c
@@ -71,6 +71,38 @@
}
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 @@
u = emalloc(sizeof(Universe));
memset(u, 0, sizeof *u);
u->step = universe_step;
+ u->collide = universe_collide;
u->reset = universe_reset;
return u;
}