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;
|
||||
}
|
||||
|
||||
bool randomBool(int uncertainty) {
|
||||
return random(uncertainty) == 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user