Skip to content

Commit 26a094d

Browse files
committed
Fixed enter not resetting game in 2 player pong
1 parent 91d4940 commit 26a094d

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

examples/pong/pong.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void Pong::resetGame() {
1616
this->paddle_x = this->width/2.0 - this->paddle_width/2.0;
1717

1818
const double start_speed = 200.0/1000.0;
19-
double start_dir = rand()%360;
19+
double start_dir = rand()%90 - 90;
2020
double start_dir_rad = start_dir * M_PI/180;
2121

2222
this->ball_velocity_x = start_speed*cos(start_dir_rad);
@@ -44,7 +44,8 @@ Pong::Pong(double width, double height, colorRGB_t border_color, colorRGB_t back
4444
assert(image_loaded);
4545
#endif
4646
//initialized random number generator
47-
srand(time(NULL));
47+
48+
srand(twr_epoch_timems());
4849

4950
this->resetGame();
5051
}

examples/pong/two-player-pong.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ void TwoPlayerPong::keyDownEvent(long keycode) {
274274
paddleOne.dir = PaddleDir::DOWN;
275275
break;
276276

277+
case KeyCode::enter:
278+
if(!this->running)
279+
this->resetGame();
280+
277281
default:
278282
break;
279283
}

0 commit comments

Comments
 (0)