0

I'm making a basic pong game and right now, I need to figure out how to get the value of the paddle (with respect to x) when it's on the left and on the right.

I have an idea of what I might be able to do, but I need some help (I'm new to Python). So here's what I'm thinking:

The width and height of the entire screen that the game would be displayed on is 600 by 600. This I know for a fact. So to get the value of the paddle, in terms of x if it's on the left side, would it look something like this?

   def get_left(self):
      if (self.x < 300):
         return self.x

My reasoning behind this was that if the paddle were on the left side, that would mean that the x value would be LESS THAN the halfway mark of the entire playing screen. Is this on the right track? And I was thinking that for the right side, it would be something similar except, it would be "self.x > 300" in the if statement.

I'm not sure if this is the correct reasoning, but I would appreciate it if I got some feedback!

Jonathan Leffler
  • 698,132
  • 130
  • 858
  • 1,229
  • That is absolutely fine. Especially since the pong game screen is split down the center. – sshashank124 Apr 06 '14 at 03:54
  • Cool! Thanks! I thought about it a little and I was wondering, what would happen if the paddle was perfectly in the center location? –  Apr 06 '14 at 03:55
  • Highly unlikely, but if it was, it doesn't really matter which side you assign it so you can add an equals in one of the loops as `if (self.x <= 300):` blablabla – sshashank124 Apr 06 '14 at 03:56
  • @Karen you have to make a choice as to what you define the center to be left or right. You could `self.x < 300` and `self.x >= 300` for your left and right respectively. – Victory Apr 06 '14 at 03:56
  • Thanks for all the feedback guys! –  Apr 06 '14 at 04:00
  • Note that if the display is 600x600, then values 0..299 are on the left and 300..599 are on the right (assuming you count from 0). If you're counting from 1..600, then you need 1..300 on the left (so `self.x <= 300`) and 301..600 are on the right. It's only if you have a screen with odd dimensions (601x601) that you have an indeterminate centreline that could be left or right with equal justification. – Jonathan Leffler Apr 06 '14 at 04:34

0 Answers0