diff --git a/src/mode/SpaceInvaders/SpaceInvaders.h b/src/mode/SpaceInvaders/SpaceInvaders.h index 031bfdf..b42f574 100644 --- a/src/mode/SpaceInvaders/SpaceInvaders.h +++ b/src/mode/SpaceInvaders/SpaceInvaders.h @@ -26,6 +26,7 @@ private: uint8_t heroX = 0; bool heroLeft = false; uint8_t heroShoot = 0; + bool randomEnabled = true; uint8_t invadersCountX; uint8_t invadersCountY; @@ -68,12 +69,24 @@ public: return "Space Invaders"; } + void move(int index, int x, int y) override { + randomEnabled = false; + heroX = max(1, min(width - 2, heroX + x)); + } + + void fire(int index) override { + randomEnabled = false; + shoot(); + } + protected: void step(microseconds_t microseconds) override { stepRockets(microseconds); stepInvaders(microseconds); - stepHero(microseconds); + if (randomEnabled) { + randomStepHero(microseconds); + } collide(); if (invadersAlive == 0) { @@ -148,7 +161,7 @@ private: } } - void stepHero(microseconds_t microseconds) { + void randomStepHero(microseconds_t microseconds) { heroRuntime += microseconds; if (heroRuntime >= 50000) { heroRuntime = heroRuntime % 50000; @@ -242,6 +255,7 @@ private: heroLeft = false; heroShoot = 0; heroX = width / 2; + randomEnabled = true; rocketRuntime = 0; for (Rocket *rocket = rocketsBegin; rocket < rocketsEnd; rocket++) {