From 75dfc00c40c6d811143b3dfaca865e3caa48db68 Mon Sep 17 00:00:00 2001 From: rodri Date: Sun, 1 Aug 2021 15:11:30 +0000 Subject: randomly position the ships, facing each other. --- musw.c | 2 +- universe.c | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/musw.c b/musw.c index 6b379a9..84bf4b9 100644 --- a/musw.c +++ b/musw.c @@ -124,7 +124,7 @@ drawship(Ship *ship, Image *dst) 0, 0, 1 }, R = { cos(ship->θ), -sin(ship->θ), 0, - sin(ship->θ), cos(ship->θ), 0, + sin(ship->θ), cos(ship->θ), 0, 0, 0, 1 }; diff --git a/universe.c b/universe.c index 32869b5..466c30d 100644 --- a/universe.c +++ b/universe.c @@ -28,20 +28,34 @@ universe_reset(Universe *u) void inituniverse(Universe *u) { - u->ships[0].p = Pt2(SCRW/2-50,SCRH/2-50,1); - u->ships[0].θ = (180+45)*DEG; + int i; + double θ; + Point2 aimstar; + + u->star.p = Pt2(0,0,1); + u->star.mass = 5.97e24; /* earth's mass */ + + θ = ntruerand(360)*DEG; + for(i = 0; i < nelem(u->ships); i++){ + θ += i*180*DEG; + Matrix R = { + cos(θ), -sin(θ), 0, + sin(θ), cos(θ), 0, + 0, 0, 1 + }; + + u->ships[i].p = addpt2(Pt2(0,0,1), mulpt2(xform(Vec2(1,0), R), 200)); + aimstar = subpt2(u->star.p, u->ships[i].p); + u->ships[i].θ = atan2(aimstar.y, aimstar.x); + } + u->ships[0].mass = 10e3; /* 10 tons */ u->ships[0].kind = NEEDLE; u->ships[0].fuel = 100; - u->ships[1].p = Pt2(-SCRW/2+50,-SCRH/2+50,1); - u->ships[1].θ = 45*DEG; u->ships[1].mass = 40e3; /* 40 tons */ u->ships[1].kind = WEDGE; u->ships[1].fuel = 200; - - u->star.p = Pt2(0,0,1); - u->star.mass = 5.97e24; /* earth's mass */ } Universe * -- cgit v1.2.3