Definition at line 350 of file main.cpp.
◆ PongGame()
| anonymous_namespace{main.cpp}::PongGame::PongGame |
( |
| ) |
|
|
inline |
Definition at line 352 of file main.cpp.
353 : random_engine(std::random_device{}()) {
355 }
◆ ball()
| const mxvk::vec4D & anonymous_namespace{main.cpp}::PongGame::ball |
( |
| ) |
const |
|
inlinenodiscard |
Definition at line 411 of file main.cpp.
411{ return ball_position; }
◆ computer_position()
| float anonymous_namespace{main.cpp}::PongGame::computer_position |
( |
| ) |
const |
|
inlinenodiscard |
Definition at line 410 of file main.cpp.
410{ return computer_y; }
◆ is_paused()
| bool anonymous_namespace{main.cpp}::PongGame::is_paused |
( |
| ) |
const |
|
inlinenodiscard |
◆ left_score()
| int anonymous_namespace{main.cpp}::PongGame::left_score |
( |
| ) |
const |
|
inlinenodiscard |
Definition at line 412 of file main.cpp.
412{ return player_score; }
◆ move_player()
| void anonymous_namespace{main.cpp}::PongGame::move_player |
( |
float | movement | ) |
|
|
inline |
Definition at line 374 of file main.cpp.
374 {
376 }
void set_player_position(float position)
◆ player_position()
| float anonymous_namespace{main.cpp}::PongGame::player_position |
( |
| ) |
const |
|
inlinenodiscard |
◆ reset()
| void anonymous_namespace{main.cpp}::PongGame::reset |
( |
| ) |
|
|
inline |
Definition at line 357 of file main.cpp.
357 {
358 player_y = 0.0f;
359 computer_y = 0.0f;
360 player_score = 0;
361 computer_score = 0;
362 paused = false;
363 reset_ball(random_direction());
364 }
◆ right_score()
| int anonymous_namespace{main.cpp}::PongGame::right_score |
( |
| ) |
const |
|
inlinenodiscard |
Definition at line 413 of file main.cpp.
413{ return computer_score; }
◆ set_player_position()
| void anonymous_namespace{main.cpp}::PongGame::set_player_position |
( |
float | position | ) |
|
|
inline |
Definition at line 370 of file main.cpp.
370 {
371 player_y = std::clamp(position, paddle_minimum_y(), paddle_maximum_y());
372 }
◆ toggle_pause()
| void anonymous_namespace{main.cpp}::PongGame::toggle_pause |
( |
| ) |
|
|
inline |
Definition at line 366 of file main.cpp.
366 {
367 paused = !paused;
368 }
◆ update()
| void anonymous_namespace{main.cpp}::PongGame::update |
( |
float | delta_seconds | ) |
|
|
inline |
Definition at line 378 of file main.cpp.
378 {
379 if (paused) {
380 return;
381 }
382
383 const float target = ball_position.y;
384 const float difference = target - computer_y;
385 const float computer_movement = std::clamp(difference, -AI_SPEED * delta_seconds, AI_SPEED * delta_seconds);
386 computer_y = std::clamp(computer_y + computer_movement, paddle_minimum_y(), paddle_maximum_y());
387
388 ball_position += ball_velocity * delta_seconds;
391 ball_velocity.y = -std::abs(ball_velocity.y);
394 ball_velocity.y = std::abs(ball_velocity.y);
395 }
396
397 collide_with_paddle(-
PADDLE_X, player_y, 1.0f);
398 collide_with_paddle(
PADDLE_X, computer_y, -1.0f);
399
401 ++computer_score;
402 reset_ball(1.0f);
404 ++player_score;
405 reset_ball(-1.0f);
406 }
407 }
constexpr float BALL_RADIUS
constexpr float COURT_HALF_HEIGHT
constexpr float COURT_HALF_WIDTH
The documentation for this class was generated from the following file: