SpaceInvaders: some randomness for hero
This commit is contained in:
parent
87f4ac40af
commit
5dbfdbb129
@ -26,4 +26,8 @@ double step(double valueCurrent, double valueMin, double valueMax, microseconds_
|
|||||||
return valueNew;
|
return valueNew;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool randomBool(int uncertainty) {
|
||||||
|
return random(uncertainty) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -22,7 +22,7 @@ enum ModeId {
|
|||||||
|
|
||||||
Display display(32, 8);
|
Display display(32, 8);
|
||||||
|
|
||||||
ModeId newModeId = GAME_OF_LIFE_GRAYSCALE;
|
ModeId newModeId = SPACE_INVADERS;
|
||||||
|
|
||||||
ModeId currentModeId = NONE;
|
ModeId currentModeId = NONE;
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ microseconds_t lastMicros = 0;
|
|||||||
|
|
||||||
Mode *mode = nullptr;
|
Mode *mode = nullptr;
|
||||||
|
|
||||||
double speed = 1.0;
|
double speed = 4.0;
|
||||||
|
|
||||||
bool connected = false;
|
bool connected = false;
|
||||||
|
|
||||||
|
|||||||
@ -141,18 +141,18 @@ public:
|
|||||||
heroRuntime -= 50000;
|
heroRuntime -= 50000;
|
||||||
if (heroLeft) {
|
if (heroLeft) {
|
||||||
heroX--;
|
heroX--;
|
||||||
if (heroX <= 1) {
|
if (heroX <= 1 || randomBool(20)) {
|
||||||
heroLeft = false;
|
heroLeft = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
heroX++;
|
heroX++;
|
||||||
if (heroX >= display->width - 2) {
|
if (heroX >= display->width - 2 || randomBool(20)) {
|
||||||
heroLeft = true;
|
heroLeft = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
heroShoot++;
|
heroShoot++;
|
||||||
if (heroShoot >= 10) {
|
if (heroShoot >= 20 || randomBool(5)) {
|
||||||
heroShoot = 0;
|
heroShoot = 0;
|
||||||
shoot();
|
shoot();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user