aboutsummaryrefslogtreecommitdiff
path: root/universe.c
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 /universe.c
parent9b3fb3f39ab9bd2b86da35f000b35c28ccca51f5 (diff)
downloadmusw-9712ec712cc6a57d416ef2b1e86d15ef161016df.tar.gz
musw-9712ec712cc6a57d416ef2b1e86d15ef161016df.tar.bz2
musw-9712ec712cc6a57d416ef2b1e86d15ef161016df.zip
implemented toroidal warping. set a default font.
Diffstat (limited to 'universe.c')
-rw-r--r--universe.c33
1 files changed, 33 insertions, 0 deletions
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;
}