aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrodri <rgl@antares-labs.eu>2021-08-01 15:11:30 +0000
committerrodri <rgl@antares-labs.eu>2021-08-01 15:11:30 +0000
commit75dfc00c40c6d811143b3dfaca865e3caa48db68 (patch)
tree11f062c74ec8de723952550410edda44eb7a2cb3
parent7ed124593ebda443fc4d0f1439d1fd8dc602ce72 (diff)
downloadmusw-75dfc00c40c6d811143b3dfaca865e3caa48db68.tar.gz
musw-75dfc00c40c6d811143b3dfaca865e3caa48db68.tar.bz2
musw-75dfc00c40c6d811143b3dfaca865e3caa48db68.zip
randomly position the ships, facing each other.
-rw-r--r--musw.c2
-rw-r--r--universe.c28
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 *