diff options
author | rodri <rgl@antares-labs.eu> | 2021-08-01 15:11:30 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2021-08-01 15:11:30 +0000 |
commit | 75dfc00c40c6d811143b3dfaca865e3caa48db68 (patch) | |
tree | 11f062c74ec8de723952550410edda44eb7a2cb3 | |
parent | 7ed124593ebda443fc4d0f1439d1fd8dc602ce72 (diff) | |
download | musw-75dfc00c40c6d811143b3dfaca865e3caa48db68.tar.gz musw-75dfc00c40c6d811143b3dfaca865e3caa48db68.tar.bz2 musw-75dfc00c40c6d811143b3dfaca865e3caa48db68.zip |
randomly position the ships, facing each other.
-rw-r--r-- | musw.c | 2 | ||||
-rw-r--r-- | universe.c | 28 |
2 files changed, 22 insertions, 8 deletions
@@ -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 }; @@ -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 * |