im currently trying to create the Pong Game in Pycharm using the turtle module. I decieded to go as far as can myself, once i got stuck i actually realized that the course is using the x and y pos and the goto() function, whereas i was using a while loop and a forward() function to move the ball. So feeling i have failed completely as i was not supoused to do it like this, i want to believe there can be a way to change the ball heading using the degrees as the input. Allow me to share my Code.
def bottom_wall_whack(self):
self.core_difference = 0
if self.heading() > 90:
self.core_difference = self.heading() - 90
self.og_heading = 90 + self.core_difference
self.setheading(self.og_heading)
elif self.heading() < 90:
self.core_difference = 90 - self.heading()
self.og_heading = 90 + self.core_difference
self.setheading(self.og_heading)
def top_wall_whack(self):
if self.heading() < 90:
self.og_heading -= 90
self.setheading(self.og_heading)
self.forward(10)
elif self.heading() > 90:
self.og_heading += 90
self.setheading(self.og_heading)
self.forward(10)
So for the arguments sake, lets say the ball is heading from the left side of the screen towards the right, going downwards.. lets say at an 135 degree angle, if it whacks the bottom floor of the screen and triggers the bottom_wall_whack
, that should change the self.og_heading
to be 45 degrees so it can go up.
So the real question is, how do i get bottom_wall_whack and top_wall_whack respectably to give back a value which would mirror the current angle its coliding with the wall onto the opposing quadrant of the square?