Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / MY PONG BALLS

Author
Message
claudio
20
Years of Service
User Offline
Joined: 1st Jun 2003
Location:
Posted: 2nd Jun 2003 18:38
SORRY ABOUT THAT

I hit a wrong button while typing the code for the pong balls question.

I guess I should have mentioned before that this is a single player version.


here it is again
claudio
20
Years of Service
User Offline
Joined: 1st Jun 2003
Location:
Posted: 2nd Jun 2003 18:45
This is Claudio again.

I guess I lost the first entery that explained the problem. looks like the second entry made it, though there is no explaination. So here is the problem. If you look at the code you will first find that it is a modified single player pong demo that I downloaded from DBheaven. The only change I made was putting a platform in the middle of the screen as an obsticle. The problem here is that the ball doesn't bounce off of it correctly. when the ball collides with the platform, it returns the same exact path from wich it came. I have searched these forums for hours trying to find the answer, however there is nothing posted that satisfies my question.

could someone please let me know what I'm doing wrong?

thank you

SelethD
20
Years of Service
User Offline
Joined: 1st Jun 2003
Location:
Posted: 4th Jun 2003 18:04
Well, what exactly do you want the ball to do?

Do you want it to bounce in a random way, like when it hits the player paddle? or just in the opposite x value but continue the y value?

If you want a random response, use the same formula as in this section:
IF SPRITE COLLISION(player,ball)
ballyspeed# = 0 - (ABS(ballyspeed#) + speedinc#)
random# = (RND(10)-5)/10.0
ballxspeed# ballxspeed# + (playerspeed/2) + random#
score = score + 1
ENDIF

or try this if you just want it to bounce:
IF SPRITE COLLISION(platform,ball)
ballyspeed# = 0 - ballyspeed#
ballxspeed# = 0 + ballxspeed#
ENDIF

(I am assuming your ball is bouncing from left to right) if it is going from top to bottom, then just change the + and - in the code above.

Hope this helps
Happy Coding

claudio
20
Years of Service
User Offline
Joined: 1st Jun 2003
Location:
Posted: 5th Jun 2003 04:05
The second code you suggested WORKED! Thanks! However, there is still one slight glitch. Whenever the ball hits the side of the platform, it now shoots right through the platform from one side to the other.

Thanks for the suggestion.

claudio
20
Years of Service
User Offline
Joined: 1st Jun 2003
Location:
Posted: 5th Jun 2003 04:23
Okay, I worked out something simple. It does some freaky stuff to the speed of the ball, but I kinda like it. All I did was add a plus value of the opposite axis, like so.

IF SPRITE COLLISION (platform,ball)
ballyspeed# = 0 - ballyspeed# + ballxspeed#
ballxspeed# = 0 - ballxspeed# + ballyspeed#
ENDIF

The angle of the collision is fine.

Thank you for your reply SelethD

Login to post a reply

Server time is: 2024-03-28 11:42:23
Your offset time is: 2024-03-28 11:42:23