Go Back   Flash Flash Revolution > General Discussion > Technology

Reply
 
Thread Tools Display Modes
Old 11-16-2012, 08:15 PM   #1
Brilliant Dynamite Neon
nobody fiffers anymore.
FFR Simfile AuthorFFR Veteran
 
Brilliant Dynamite Neon's Avatar
 
Join Date: Dec 2006
Location: 6-arrow land
Age: 31
Posts: 2,440
Send a message via MSN to Brilliant Dynamite Neon Send a message via Yahoo to Brilliant Dynamite Neon
Default 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
Brilliant Dynamite Neon is offline   Reply With Quote
Old 11-16-2012, 08:27 PM   #2
MarioNintendo
Expect delays.
Retired StaffFFR Simfile AuthorFFR Music ProducerFFR Veteran
 
MarioNintendo's Avatar
 
Join Date: Mar 2008
Location: Montreal, QC
Age: 31
Posts: 4,119
Default 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
__________________
Click here to download my complete works!




Quote:
Originally Posted by macgravel View Post
Mario's files are top notch, so every time he submits a file I get excited in my pants.
Quote:
Originally Posted by hi19hi19 View Post
This guy, MarioNintendo?
Click the bricks


MarioNintendo is offline   Reply With Quote
Old 11-16-2012, 08:28 PM   #3
qqwref
stepmania archaeologist
Retired StaffFFR Simfile AuthorFFR Veteran
 
qqwref's Avatar
 
Join Date: Aug 2005
Age: 34
Posts: 4,090
Default 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)
qqwref is offline   Reply With Quote
Old 11-16-2012, 08:52 PM   #4
Brilliant Dynamite Neon
nobody fiffers anymore.
FFR Simfile AuthorFFR Veteran
 
Brilliant Dynamite Neon's Avatar
 
Join Date: Dec 2006
Location: 6-arrow land
Age: 31
Posts: 2,440
Send a message via MSN to Brilliant Dynamite Neon Send a message via Yahoo to Brilliant Dynamite Neon
Default 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
Brilliant Dynamite Neon is offline   Reply With Quote
Old 11-16-2012, 09:48 PM   #5
Reincarnate
x'); DROP TABLE FFR;--
Retired StaffFFR Veteran
 
Reincarnate's Avatar
 
Join Date: Nov 2010
Posts: 6,332
Default 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..
Reincarnate is offline   Reply With Quote
Old 11-16-2012, 10:27 PM   #6
Brilliant Dynamite Neon
nobody fiffers anymore.
FFR Simfile AuthorFFR Veteran
 
Brilliant Dynamite Neon's Avatar
 
Join Date: Dec 2006
Location: 6-arrow land
Age: 31
Posts: 2,440
Send a message via MSN to Brilliant Dynamite Neon Send a message via Yahoo to Brilliant Dynamite Neon
Default Re: Desperately need help with Python programming

Quote:
Originally Posted by Reincarnate View Post
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#_pos) / 10)
Check it out!
__________________
~ 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..
Brilliant Dynamite Neon is offline   Reply With Quote
Old 11-16-2012, 11:25 PM   #7
qqwref
stepmania archaeologist
Retired StaffFFR Simfile AuthorFFR Veteran
 
qqwref's Avatar
 
Join Date: Aug 2005
Age: 34
Posts: 4,090
Default 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)
qqwref is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 07:27 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution