This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
notes:cprog:spring2025:projects:mtb1 [2025/02/05 19:11] – created - external edit 127.0.0.1 | notes:cprog:spring2025:projects:mtb1 [2025/02/18 00:33] (current) – [Collision detection: ball and paddle] tstrickl | ||
---|---|---|---|
Line 19: | Line 19: | ||
====Paddle==== | ====Paddle==== | ||
+ | The Paddle should function identically to the moving box from mtb0, except restricted to only moving in one dimension (up + down, or left + right) | ||
====Ball==== | ====Ball==== | ||
+ | The ball needs to have collisions with both the walls and the paddle. The ball also needs to be constantly moving, with the ability to switch to opposite directions whenever it hits the wall or the paddle. This can be done through two variable possibly called ballXDirection and ballYDirection wherin both values can possibly be either -1 or 1. If ballXDirection is -1, then anytime the ball is being moved by some amount in the x direction, multiply it by the ballXDirection, | ||
====Paddle movement==== | ====Paddle movement==== | ||
====Ball movement==== | ====Ball movement==== | ||
+ | You can move the ball by updating it's position every frame of the main while loop of the program. | ||
+ | By creating variables for the balls position, speed, and xy vectors we can control the balls velocity. | ||
+ | By using speed and vector variables to calculate the x and y position we can make the ball bounce off of walls by negating the vector values. | ||
====Bounds deflection for ball==== | ====Bounds deflection for ball==== | ||
====Collision detection: ball and paddle==== | ====Collision detection: ball and paddle==== | ||
- | + | Create variable that represent the hitbox for the paddle. One could possibly make a yhitbox offset that represents the distance from the center of the paddle to it's extreme in one of the y direction. To represent the other direction just negate it. The same can be done for the x direction. |