aboutsummaryrefslogtreecommitdiff
path: root/universe.c
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2023-02-22 21:40:54 +0000
committerrodri <rgl@antares-labs.eu>2023-02-22 21:40:54 +0000
commitd40305baf8a0722cf6128520a5b792fc173c5a93 (patch)
treed55310d984f0b94ee1e22edcbc6ba1eb1ce52c01 /universe.c
parentecc7d34e9229524a8d4340f0e127f1421029141c (diff)
downloadmusw-d40305baf8a0722cf6128520a5b792fc173c5a93.tar.gz
musw-d40305baf8a0722cf6128520a5b792fc173c5a93.tar.bz2
musw-d40305baf8a0722cf6128520a5b792fc173c5a93.zip
take player input into account when stepping the simulations.
Diffstat (limited to 'universe.c')
-rw-r--r--universe.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/universe.c b/universe.c
index eea95a8..be481c9 100644
--- a/universe.c
+++ b/universe.c
@@ -8,10 +8,65 @@
#include "dat.h"
#include "fns.h"
+/* Ship */
+
+static void
+ship_forward(Ship *s, double Δt)
+{
+ Point2 v;
+ Matrix R = {
+ cos(s->θ), -sin(s->θ), 0,
+ sin(s->θ), cos(s->θ), 0,
+ 0, 0, 1,
+ };
+
+ v = mulpt2(xform(Vec2(1,0), R), THRUST*Δt);
+ s->v = addpt2(s->v, v);
+}
+
+static void
+ship_rotate(Ship *s, int dir, double Δt)
+{
+ s->θ += PI*dir*Δt;
+}
+
+static void
+ship_hyperjump(Ship *s)
+{
+ USED(s);
+ return;
+}
+
+static void
+ship_fire(Ship *s)
+{
+ int i;
+ Point2 bv;
+ Matrix R = {
+ cos(s->θ), -sin(s->θ), 0,
+ sin(s->θ), cos(s->θ), 0,
+ 0, 0, 1,
+ };
+
+ bv = mulpt2(xform(Vec2(1,0), R), 10*THRUST);
+
+ for(i = 0; i < nelem(s->rounds); i++)
+ if(!s->rounds[i].fired){
+ s->rounds[i].v = addpt2(s->v, bv);
+ s->rounds[i].θ = s->θ;
+ s->rounds[i].fired++;
+ break;
+ }
+}
+
+/* Universe */
+
static void
universe_step(Universe *u, double Δt)
{
integrate(u, u->t, Δt);
+ u->timeacc -= Δt;
+ u->t += Δt;
}
static void
@@ -59,6 +114,11 @@ inituniverse(Universe *u)
u->ships[1].mass = 40e3; /* 40 tons */
u->ships[1].kind = WEDGE;
u->ships[1].fuel = 200;
+
+ u->ships[0].forward = u->ships[1].forward = ship_forward;
+ u->ships[0].rotate = u->ships[1].rotate = ship_rotate;
+ u->ships[0].hyperjump = u->ships[1].hyperjump = ship_hyperjump;
+ u->ships[0].fire = u->ships[1].fire = ship_fire;
}
Universe *