![]() |
The NEW Pong Game V13.2.1
An interesting implemnettaion of the pong game
|
Artificial Intelligence for controlling a paddle. More...
#include <ai.hpp>
Public Member Functions | |
| AI (Paddle *controlledPaddle) | |
| Constructor for AI class. | |
| void | set_difficulty (int difficulty) |
| Sets the AI difficulty level. | |
| void | updateAI (BallBase *ball, float dt) |
| Updates the AI-controlled paddle's position. | |
Private Attributes | |
| int | ai_difficulty |
| Paddle * | racket |
Artificial Intelligence for controlling a paddle.
This class manages computer-controlled paddles, providing different difficulty levels to adjust how well the AI tracks and responds to the ball.
| AI::AI | ( | Paddle * | controlledPaddle | ) |
| void AI::set_difficulty | ( | int | difficulty | ) |
Sets the AI difficulty level.
| difficulty | The difficulty level (0=easy, 1=normal, 2=hard) |
| void AI::updateAI | ( | BallBase * | ball, |
| float | dt ) |
Updates the AI-controlled paddle's position.
Updates the AI-controlled paddle's position based on the ball.
Called each frame in AI mode to move the paddle to attempt to hit the ball based on the current difficulty setting
| ball | Pointer to the ball to track |
| dt | Time delta since last update (in seconds) |
This method calculates where to move the paddle based on the ball's position and the current difficulty setting. Higher difficulty makes the AI react faster.
| ball | Pointer to the ball to track |
| dt | Time delta since last update (in seconds) |
Adjust reaction speed based on difficulty level
Easy: 60% speed - easier for player to win Normal: 100% speed - balanced Hard: 140% speed - more challenging for the player
Move the paddle based on ball position
Keep the paddle within screen bounds
|
private |
Current difficulty level (0=easy, 1=normal, 2=hard)