11-16-2012, 08:15 PM | #1 |
nobody fiffers anymore.
|
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 |
11-16-2012, 08:27 PM | #2 |
Expect delays.
Join Date: Mar 2008
Location: Montreal, QC
Age: 31
Posts: 4,128
|
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 |
11-16-2012, 08:28 PM | #3 |
stepmania archaeologist
Join Date: Aug 2005
Age: 34
Posts: 4,090
|
Re: Desperately need help with Python programming
First try fixing it:
__________________
Best AAA: Policy In The Sky [Oni] (81) Best SDG: PANTS (86) Best FC: Future Invasion (93) |
11-16-2012, 08:52 PM | #4 |
nobody fiffers anymore.
|
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 |
11-16-2012, 09:48 PM | #5 |
x'); DROP TABLE FFR;--
Join Date: Nov 2010
Posts: 6,332
|
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 at 09:51 PM.. |
11-16-2012, 10:27 PM | #6 | |
nobody fiffers anymore.
|
Re: Desperately need help with Python programming
Quote:
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#_pos) / 10)
__________________
~ OFFICIALLY RETIRED FROM FFR THE GAME AND FFR TWG ~
Thanks for the memories, folks. u da bes Last edited by Brilliant Dynamite Neon; 11-16-2012 at 10:53 PM.. |
|
11-16-2012, 11:25 PM | #7 |
stepmania archaeologist
Join Date: Aug 2005
Age: 34
Posts: 4,090
|
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) |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|