Definition at line 307 of file main.cpp.
◆ PongGame()
| anonymous_namespace{main.cpp}::PongGame::PongGame |
( |
| ) |
|
|
inline |
Definition at line 309 of file main.cpp.
309: random_engine(std::random_device{}()) {
reset(); }
◆ ball()
| const mxvk::vec4D & anonymous_namespace{main.cpp}::PongGame::ball |
( |
| ) |
const |
|
inlinenodiscard |
Definition at line 359 of file main.cpp.
359{ return ball_position; }
◆ computer_position()
| float anonymous_namespace{main.cpp}::PongGame::computer_position |
( |
| ) |
const |
|
inlinenodiscard |
Definition at line 358 of file main.cpp.
358{ 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 360 of file main.cpp.
360{ return player_score; }
◆ move_player()
| void anonymous_namespace{main.cpp}::PongGame::move_player |
( |
float | movement | ) |
|
|
inline |
Definition at line 324 of file main.cpp.
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 311 of file main.cpp.
311 {
312 player_y = 0.0f;
313 computer_y = 0.0f;
314 player_score = 0;
315 computer_score = 0;
316 paused = false;
317 reset_ball(random_direction());
318 }
◆ right_score()
| int anonymous_namespace{main.cpp}::PongGame::right_score |
( |
| ) |
const |
|
inlinenodiscard |
Definition at line 361 of file main.cpp.
361{ return computer_score; }
◆ set_player_position()
| void anonymous_namespace{main.cpp}::PongGame::set_player_position |
( |
float | position | ) |
|
|
inline |
Definition at line 322 of file main.cpp.
322{ player_y = std::clamp(position, paddle_minimum_y(), paddle_maximum_y()); }
◆ toggle_pause()
| void anonymous_namespace{main.cpp}::PongGame::toggle_pause |
( |
| ) |
|
|
inline |
◆ update()
| void anonymous_namespace{main.cpp}::PongGame::update |
( |
float | delta_seconds | ) |
|
|
inline |
Definition at line 326 of file main.cpp.
326 {
327 if (paused) {
328 return;
329 }
330
331 const float target = ball_position.y;
332 const float difference = target - computer_y;
333 const float computer_movement = std::clamp(difference, -AI_SPEED * delta_seconds, AI_SPEED * delta_seconds);
334 computer_y = std::clamp(computer_y + computer_movement, paddle_minimum_y(), paddle_maximum_y());
335
336 ball_position += ball_velocity * delta_seconds;
339 ball_velocity.y = -std::abs(ball_velocity.y);
342 ball_velocity.y = std::abs(ball_velocity.y);
343 }
344
345 collide_with_paddle(-
PADDLE_X, player_y, 1.0f);
346 collide_with_paddle(
PADDLE_X, computer_y, -1.0f);
347
349 ++computer_score;
350 reset_ball(1.0f);
352 ++player_score;
353 reset_ball(-1.0f);
354 }
355 }
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: