This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
notes:cprog:spring2025:projects:mtb2 [2025/02/25 03:29] – [score storage] tstrickl | notes:cprog:spring2025:projects:mtb2 [2025/02/25 22:07] (current) – [score display] bdildine | ||
---|---|---|---|
Line 23: | Line 23: | ||
Make two integers to represent Player 1 and Player 2's scores. Every time that the ball hits the sides, determine who gets the point, and add that to the respective variable of the player who scored. | Make two integers to represent Player 1 and Player 2's scores. Every time that the ball hits the sides, determine who gets the point, and add that to the respective variable of the player who scored. | ||
====score display==== | ====score display==== | ||
+ | Within the video.h header file, there is a series of print functions, which prints characters to the screen based on the string that is provided to it. | ||
+ | You can use the itoa(); function included in the string.h header file to convert your score from and integer to a string if that's the method you are using. | ||
====computer operated player==== | ====computer operated player==== | ||
+ | To allow for the paddle to track the ball, it would be recommended to find a linear equation to represent the balls path, that which changes everytime it bounces of the roof, floor, or paddle. After finding the y-intercept, | ||
+ | note: slope intercept form y = m(x - x1) + y1 | ||
+ | |||
+ | y1 = y-intercept. | ||
+ | x = desired x location to return the projected y position of the ball. (AI paddle' | ||
====determining computer paddle movement==== | ====determining computer paddle movement==== | ||
+ | Now that equations are set up to represent the movement of the ball every time it switches directions, just make the paddle move up or down based on whether it is less than or greater that the predicted y coordinate of the ball while on the x coordinate of the paddle. | ||
====difficulty of computer player==== | ====difficulty of computer player==== | ||
+ | an integer can be made to represent the difficulty of the player. The difficulty can control how fast the player moves or maybe how accurate it is. This example will only make it move faster. After making the integer to represent difficulty, one could make either a switch statement, or if statements to change the speed at which the paddle moves based on the condition of difficulty. eg. if(difficulty == 1) { paddleSpeed = 2}. |