So I just recently learned BASIC and figured I would try making a clone of pong on my own in darkBASIC pro, and I made everything else work just fine except for the part that makes the ball bounce off the paddle. And yes I'm aware that the game is not yet finished. The error is on lines 39-51 EVERYTHING IS 2D. The problem i am having is that when the ball hits the paddle it gets like stuck(itll move away like 3 pixels and the back onto the paddle), and will move up or down until it finally gets to the edge of the paddle, or it gets sucked into the inside of the paddle, or it does the same thing where it gets stuck on the paddle, but it does it from behind.

``````  ///////////////////////////////////////////////////////////
//
//     Project: Pong
//     Created: Friday, August 31, 2012
//     Code: Brandon Spaulding
//     Art: Brandon Spaulding
//     Made in CIS lab at CPAVTS
//     Pong art and code © Brandon Spaulding 2012-2013
//
//////////////////////////////////////////////////////////
y=150
x=0
ay=150
ax=612
ballx=300
bally=200
ballx_DIR=1
bally_DIR=1
hide mouse
set global collision on
//objectnumber=10
//make object box objectnumber,5,150,0
do
sprite 1,x,y,1
sprite 2,ax,ay,2
sprite 3,ballx,bally,3
if upkey()=1 then y = y - 4
if downkey()=1 then y = y + 4

//num_1 = sprite collision(1,0)
//num_2 = sprite collision(2,0)
num_3 = sprite collision(3,0)

for t=1 to 2

if num_3 > 0
if bally_DIR=1
bally_DIR=0
else
bally_DIR=1
endif
if ballx_DIR=0
ballx_DIR=1
else
ballx_DIR=0
endif
endif

//if bally > 1 and bally < 500 then bally=bally + 2.5
if bally_DIR=1
bally=bally-2.5
if bally<-2.5
bally_DIR=0
endif
else
bally=bally+2.5
if bally>452.5
bally_DIR=1
endif

endif
if ballx_DIR=1
ballx=ballx-2.5
if ballx<-2.5
ballx_DIR=0
endif
else
ballx=ballx+2.5
if ballx>612
ballx_DIR=1
endif

endif
//bally = bally + t
//if bally < 600 or bally > 1 then bally = bally - 2.5
//if ballx < 400 or ballx > 1 then ballx = ballx + 2.5
//move sprite 3,1

next t
if escapekey()=1 then exit
loop
end
``````

Thank you in advance for the help.

-

## closed as too localized by doppelgreener, michael.bartnett, Byte56♦, Trevor Powell, jcoraSep 29 '12 at 14:36

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

You should really describe the problem you are having instead of the line numbers (which we can't see without counting) on which the error occurs. – Seth Battin Sep 1 '12 at 3:46

You're reloading your images on every frame. Don't do this. Also, you'll be doing yourself and others who read your code a favor if you clean it up. Make sure it's indented properly and don't use raw numbers for image or sprite or whatever other type of object ID. Also, don't use extremely short variable names such as `x` and `ax`. I was able to work out what these referred to, but I had to put some time and brain power into it, which is less brain power I can give toward helping you with your collision problem.

``````paddle1y = 150

ballx = 300
bally = 200
ballx_DIR = 1
bally_DIR = 1

hide mouse
set global collision on

ballImg = 3

ballSprite = 3

do
sprite ballImage, ballx, bally, ballSprite