SpaceInvaders: fire, move
This commit is contained in:
parent
d27214ae5e
commit
aef62ffc47
@ -26,6 +26,7 @@ private:
|
|||||||
uint8_t heroX = 0;
|
uint8_t heroX = 0;
|
||||||
bool heroLeft = false;
|
bool heroLeft = false;
|
||||||
uint8_t heroShoot = 0;
|
uint8_t heroShoot = 0;
|
||||||
|
bool randomEnabled = true;
|
||||||
|
|
||||||
uint8_t invadersCountX;
|
uint8_t invadersCountX;
|
||||||
uint8_t invadersCountY;
|
uint8_t invadersCountY;
|
||||||
@ -68,12 +69,24 @@ public:
|
|||||||
return "Space Invaders";
|
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:
|
protected:
|
||||||
|
|
||||||
void step(microseconds_t microseconds) override {
|
void step(microseconds_t microseconds) override {
|
||||||
stepRockets(microseconds);
|
stepRockets(microseconds);
|
||||||
stepInvaders(microseconds);
|
stepInvaders(microseconds);
|
||||||
stepHero(microseconds);
|
if (randomEnabled) {
|
||||||
|
randomStepHero(microseconds);
|
||||||
|
}
|
||||||
|
|
||||||
collide();
|
collide();
|
||||||
if (invadersAlive == 0) {
|
if (invadersAlive == 0) {
|
||||||
@ -148,7 +161,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void stepHero(microseconds_t microseconds) {
|
void randomStepHero(microseconds_t microseconds) {
|
||||||
heroRuntime += microseconds;
|
heroRuntime += microseconds;
|
||||||
if (heroRuntime >= 50000) {
|
if (heroRuntime >= 50000) {
|
||||||
heroRuntime = heroRuntime % 50000;
|
heroRuntime = heroRuntime % 50000;
|
||||||
@ -242,6 +255,7 @@ private:
|
|||||||
heroLeft = false;
|
heroLeft = false;
|
||||||
heroShoot = 0;
|
heroShoot = 0;
|
||||||
heroX = width / 2;
|
heroX = width / 2;
|
||||||
|
randomEnabled = true;
|
||||||
|
|
||||||
rocketRuntime = 0;
|
rocketRuntime = 0;
|
||||||
for (Rocket *rocket = rocketsBegin; rocket < rocketsEnd; rocket++) {
|
for (Rocket *rocket = rocketsBegin; rocket < rocketsEnd; rocket++) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user