SpaceInvaders: some randomness for hero

This commit is contained in:
Patrick Haßel 2021-12-27 13:41:03 +01:00
parent 87f4ac40af
commit 5dbfdbb129
3 changed files with 9 additions and 5 deletions

View File

@ -26,4 +26,8 @@ double step(double valueCurrent, double valueMin, double valueMax, microseconds_
return valueNew;
}
bool randomBool(int uncertainty) {
return random(uncertainty) == 0;
}
#endif

View File

@ -22,7 +22,7 @@ enum ModeId {
Display display(32, 8);
ModeId newModeId = GAME_OF_LIFE_GRAYSCALE;
ModeId newModeId = SPACE_INVADERS;
ModeId currentModeId = NONE;
@ -30,7 +30,7 @@ microseconds_t lastMicros = 0;
Mode *mode = nullptr;
double speed = 1.0;
double speed = 4.0;
bool connected = false;

View File

@ -141,18 +141,18 @@ public:
heroRuntime -= 50000;
if (heroLeft) {
heroX--;
if (heroX <= 1) {
if (heroX <= 1 || randomBool(20)) {
heroLeft = false;
}
} else {
heroX++;
if (heroX >= display->width - 2) {
if (heroX >= display->width - 2 || randomBool(20)) {
heroLeft = true;
}
}
heroShoot++;
if (heroShoot >= 10) {
if (heroShoot >= 20 || randomBool(5)) {
heroShoot = 0;
shoot();
}