diff options
author | rodri <rgl@antares-labs.eu> | 2023-03-03 11:18:16 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2023-03-03 11:18:16 +0000 |
commit | 9712ec712cc6a57d416ef2b1e86d15ef161016df (patch) | |
tree | b94613b42365f39f48bfaecf411c62a9da32ecaa | |
parent | 9b3fb3f39ab9bd2b86da35f000b35c28ccca51f5 (diff) | |
download | musw-9712ec712cc6a57d416ef2b1e86d15ef161016df.tar.gz musw-9712ec712cc6a57d416ef2b1e86d15ef161016df.tar.bz2 musw-9712ec712cc6a57d416ef2b1e86d15ef161016df.zip |
implemented toroidal warping. set a default font.
-rw-r--r-- | dat.h | 1 | ||||
-rw-r--r-- | musw.c | 3 | ||||
-rw-r--r-- | muswd.c | 4 | ||||
-rw-r--r-- | todo | 5 | ||||
-rw-r--r-- | universe.c | 33 |
5 files changed, 42 insertions, 4 deletions
@@ -141,6 +141,7 @@ struct Universe double t, timeacc; void (*step)(Universe*, double); + void (*collide)(Universe*); void (*reset)(Universe*); }; @@ -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"); @@ -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(); @@ -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 @@ -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; } |