commit 45f10eb2c52687daf0d6dee9f27c8080c0112bb3
parent 615c5952424b909f6d243b57dc28d70dc59dab84
Author: Henry Wilson <henry@henryandlizzy.uk>
Date: Sat, 9 Apr 2022 17:43:30 +0100
gl-asteroids: Improve rock collision
Diffstat:
1 file changed, 26 insertions(+), 8 deletions(-)
diff --git a/src/gl-asteroids.cpp b/src/gl-asteroids.cpp
@@ -104,6 +104,11 @@ coord operator - (coord lhs, coord rhs)
return lhs + -rhs;
}
+coord& operator -=(coord& lhs, coord rhs)
+{
+ return lhs = lhs - rhs;
+}
+
coord operator *(coord lhs, coord rhs)
{
return {lhs.x * rhs.x, lhs.y * rhs.y};
@@ -299,7 +304,9 @@ int main(int argc, char* argv[])
std::default_random_engine gen(rd());
std::uniform_real_distribution<float> dis_p(-1,1);
std::uniform_real_distribution<float> dis_s(0.05,0.25);
+ std::uniform_real_distribution<float> dis_ds(0.005,0.025);
std::uniform_real_distribution<float> dis_v(0.02,0.05);
+ std::uniform_real_distribution<float> dis_z(.3,.6);
std::uniform_int_distribution<int> dis_d(0,7);
std::uniform_real_distribution<float> dis_a(-3,3);
@@ -431,19 +438,30 @@ int main(int argc, char* argv[])
debris.v = &random_rock_visual();
debris.p.vel.x += .3 * dis_p(gen);
debris.p.vel.y += .3 * dis_p(gen);
- debris.p.scale *= 1.5 * dis_s(gen);
+ debris.p.scale = dis_ds(gen);
particle::make_particle(debris, .7);
}
- if (r->p.scale > .1f)
+ if (r->p.scale > .13f)
{
+ coord split{dis_v(gen), dis_v(gen)};
+
+ auto nr = *r;
+
+ float sf = dis_z(gen);
+
+ r->p.scale *= sf;
+ nr.p.scale *= .9 - sf;
+
r->v = &random_rock_visual();
- r->p.vel *= 1.5f;
- r->p.scale /= 2;
- rocks.push_back(*r);
- rocks.back().p.vel *= -1;
- rocks.back().p.ang_mom *= -1.5f;
- rocks.back().v = &random_rock_visual();
+ nr.v = &random_rock_visual();
+
+ r->p.vel += 2*split;
+ nr.p.vel -= split;
+
+ nr.p.ang_mom *= -1.5f;
+
+ rocks.push_back(nr);
++i;
}
else