examples

Toy examples in single C files.
git clone git://henryandlizzy.uk/examples
Log | Files | Refs

commit 615c5952424b909f6d243b57dc28d70dc59dab84
parent feb37900a804a5727cab6165bf3d35f47dade0f6
Author: Henry Wilson <henry@henryandlizzy.uk>
Date:   Sat,  9 Apr 2022 13:52:07 +0100

gl-asteroids: Shooting powerups destroys them

Diffstat:
Msrc/gl-asteroids.cpp | 29+++++++++++++++++++++++++----
1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/src/gl-asteroids.cpp b/src/gl-asteroids.cpp @@ -459,11 +459,32 @@ int main(int argc, char* argv[]) bang: continue; } - if (powerups && is_colliding(s, powerups->p)) + if (powerups) { - powerups.reset(); - score += 10; - ++firerate; + for (auto b = bullets.begin(); b < bullets.end(); ++b) + { + if (not is_colliding(b->p, powerups->p)) + continue; + + for (unsigned j = 0; j < 4; ++j) + { + entity debris = *powerups; + debris.p.vel.x += .3 * dis_p(gen); + debris.p.vel.y += .3 * dis_p(gen); + debris.p.scale *= 1.5 * dis_s(gen); + particle::make_particle(debris, .7); + } + powerups.reset(); + score -= 10; + bullets.erase(b); + break; + } + if (is_colliding(s, powerups->p)) + { + powerups.reset(); + score += 10; + ++firerate; + } } if(any_of(rocks.begin(), rocks.end(), [](auto& r) { return is_colliding(s, r.p); }))