Pong: move
This commit is contained in:
parent
9ea1eddd57
commit
d27214ae5e
@ -15,6 +15,8 @@ public:
|
|||||||
|
|
||||||
bool moveUp = false;
|
bool moveUp = false;
|
||||||
|
|
||||||
|
bool random = true;
|
||||||
|
|
||||||
void randomMove(uint8_t height) {
|
void randomMove(uint8_t height) {
|
||||||
if (moveUp) {
|
if (moveUp) {
|
||||||
y--;
|
y--;
|
||||||
@ -28,7 +30,6 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@ -40,6 +40,24 @@ public:
|
|||||||
return "Pong";
|
return "Pong";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void move(int index, int x, int y) override {
|
||||||
|
if (index == 0) {
|
||||||
|
player0.random = false;
|
||||||
|
player0.y = min(height - player0.size, max(0, player0.y + y));
|
||||||
|
} else if (index == 1) {
|
||||||
|
player1.random = false;
|
||||||
|
player1.y = min(height - player1.size, max(0, player1.y + y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void fire(int index) override {
|
||||||
|
if (index == 0) {
|
||||||
|
player0.random = false;
|
||||||
|
} else if (index == 1) {
|
||||||
|
player1.random = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void tick(uint8_t index, microseconds_t microseconds) override {
|
void tick(uint8_t index, microseconds_t microseconds) override {
|
||||||
@ -52,8 +70,12 @@ protected:
|
|||||||
break;
|
break;
|
||||||
case PLAY:
|
case PLAY:
|
||||||
ball = ball.plus(velocity);
|
ball = ball.plus(velocity);
|
||||||
|
if (player0.random) {
|
||||||
player0.randomMove(height);
|
player0.randomMove(height);
|
||||||
|
}
|
||||||
|
if (player1.random) {
|
||||||
player1.randomMove(height);
|
player1.randomMove(height);
|
||||||
|
}
|
||||||
topBottomBounce();
|
topBottomBounce();
|
||||||
paddleBounce();
|
paddleBounce();
|
||||||
checkScoring();
|
checkScoring();
|
||||||
@ -105,9 +127,11 @@ private:
|
|||||||
player0.size = 3;
|
player0.size = 3;
|
||||||
player0.score = 0;
|
player0.score = 0;
|
||||||
player0.y = (height - player0.size) / 2;
|
player0.y = (height - player0.size) / 2;
|
||||||
|
player0.random = true;
|
||||||
player1.size = 3;
|
player1.size = 3;
|
||||||
player1.score = 0;
|
player1.score = 0;
|
||||||
player1.y = (height - player1.size) / 2;
|
player1.y = (height - player1.size) / 2;
|
||||||
|
player1.random = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void topBottomBounce() {
|
void topBottomBounce() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user