Desperately need help with Python programming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Brilliant Dynamite Neon
    nobody fiffers anymore.
    FFR Simfile Author
    • Dec 2006
    • 2440

    #1

    Desperately need help with Python programming

    Okay, hear me out. I know I don't have the "reputation points" or whatever to ask for help here, but I'm desperate and am going to try anything I can. this is basically my last stand for this class.

    I am taking a basic online class in Interactive Python Programming and this project to build a Pong clone is killing me. I already missed the last project and if I miss this one I don't know if I'll be able to pass.

    The worst thing about this all is, I have almost everything working.The paddles move properly and independently and don't go off the screen, the ball spawns at a randomized vector like it should and collides with the top and bottom of the screen, the score accrues like it should...but try as I might, I cannot get the ball to collide with the paddles. It just goes straight through them. I've been able to come up with only two collision paradigms that don't make the program crash at some point, and neither of them work.

    The problem is simply that in order to make the ball properly collide with the paddles, I need to test the ball's y-position against a range of y-values, which neither the lectures or the documentation cover.
    The class forums aren't helping either. I tried using the range() function, but it doesn't return floating point values, which is what I need to accurately test for collision.

    Here is my code: http://www.codeskulptor.org/#user5-SdhbTFrT0K-2.py

    It's on CodeSkulptor, which has the module SimpleGUI installed, which is what I need for this program.

    I'm pretty sure things are functional otherwise, if a little clumsy. If you have advice for structuring the program better, that would be appreciated too.

    Basics of CodeSkulptor:
    - The "Play" button in the top-left corner runs the code.
    - If you make any modifications to the code, the "Save" button next to it will become active, and you can save it. Notice the URL changes. If you have modified code that you want to show to me, you'll need to copy that URL and paste it here.

    That's all I have to say for now. Hope some of you can help!
    ~ OFFICIALLY RETIRED FROM FFR THE GAME AND FFR TWG ~

    Thanks for the memories, folks. u da bes
  • MarioNintendo
    Expect delays.
    FFR Simfile Author
    FFR Music Producer
    • Mar 2008
    • 4177

    #2
    Re: Desperately need help with Python programming

    I suck at coding and I know nothing about this but

    wow this is a cool little game! :3

    Comment

    • qqwref
      stepmania archaeologist
      FFR Simfile Author
      • Aug 2005
      • 4092

      #3
      Re: Desperately need help with Python programming

      First try fixing it:
      Code:
      def col_check_left(y):
          if y >= paddle1_pos - HALF_PAD_HEIGHT and y <= paddle1_pos + HALF_PAD_HEIGHT:
              ball_vel[0] = -ball_vel[0]
              ball_vel[0] += 1
          else:
              pass
      
      def col_check_right(y):
          if y >= paddle2_pos - HALF_PAD_HEIGHT and y <= paddle2_pos + HALF_PAD_HEIGHT:
              ball_vel[0] = -ball_vel[0]
              ball_vel[0] -= 1
          else:
              pass
      Best AAA: Policy In The Sky [Oni] (81)
      Best SDG: PANTS (86)
      Best FC: Future Invasion (93)

      Comment

      • Brilliant Dynamite Neon
        nobody fiffers anymore.
        FFR Simfile Author
        • Dec 2006
        • 2440

        #4
        Re: Desperately need help with Python programming

        Oh wow, qqwref, that worked just fine!
        And yes, the ball is meant to get faster with each collision.

        That was fast, thanks ref! Somehow I forgot about AND statements, because I was previously using one huge complicated one to make things work, back when I was trying to check both the x and y positions with one function. It didn't work, so I assumed it wasn't doing anything. But with a structure like this it does! Thanks very much.

        The last thing I wanna do is not actually part of the assignment, but it would make the game far more interesting. I want the ball's vertical velocity to change based on where it hits the paddle, so it can be strategically directed by the player, like Arkanoid. However, I have no doubt that implementing that would be very complicated, sooo, if no one wants to help me with that, that's fine! I'm just glad I have something good to submit now!
        ~ OFFICIALLY RETIRED FROM FFR THE GAME AND FFR TWG ~

        Thanks for the memories, folks. u da bes

        Comment

        • Reincarnate
          x'); DROP TABLE FFR;--
          • Nov 2010
          • 6332

          #5
          Re: Desperately need help with Python programming

          Python <3

          There are many ways to handle reflection mechanics. It's really up to you on that point. Different Pong clones handle them differently.

          Awesome job so far -- I've never actually played a Python game with graphics and everything. :O
          Last edited by Reincarnate; 11-16-2012, 08:51 PM.

          Comment

          • Brilliant Dynamite Neon
            nobody fiffers anymore.
            FFR Simfile Author
            • Dec 2006
            • 2440

            #6
            Re: Desperately need help with Python programming

            Originally posted by Reincarnate
            Python <3

            There are many ways to handle reflection mechanics. It's really up to you on that point. Different Pong clones handle them differently.

            Awesome job so far -- I've never actually played a Python game with graphics and everything. :O
            Really? Huh. I guess this isn't too bad then!

            The thing is, I can't make the ball not shoot off horizontally since random.randint() operates over a single range. A problem I discussed off-thread:

            "[If the ball has no y-velocity], you can put both paddles in the same position and have the ball bounce back and forth faster and faster until the program can't handle it and one player is randomly screwed out of a point."

            Controllable reflections would avoid that problem, the thing is, I have no idea where to start! Well I do, actually -- I know they'd have to be subsets of the collision checks themselves. Just, how would I implement it? It'd have to reassign the y-velocity {ball_vel[1]} dynamically based on distance from the center of the paddle {paddle_pos#}. Still, how? I know the players, but not the game, you know what I mean?

            EDIT: Neeevermind! I was able to figure it out by simply calculating the difference in pixels from the center of the paddle, and downscaling that to a reasonable reflect velocity.

            Code:
            ball_vel[1] = ((ball_pos[1] - paddle[COLOR=Red]#[/COLOR]_pos) / 10)
            Check it out!
            Last edited by Brilliant Dynamite Neon; 11-16-2012, 09:53 PM.
            ~ OFFICIALLY RETIRED FROM FFR THE GAME AND FFR TWG ~

            Thanks for the memories, folks. u da bes

            Comment

            • qqwref
              stepmania archaeologist
              FFR Simfile Author
              • Aug 2005
              • 4092

              #7
              Re: Desperately need help with Python programming

              Cool stuff! Just remember to multiply the vertical velocity by the horizontal velocity, so that the angle doesn't get flatter and flatter as the ball speed increases.
              Best AAA: Policy In The Sky [Oni] (81)
              Best SDG: PANTS (86)
              Best FC: Future Invasion (93)

              Comment

              Working...