Please help with bounding box/sprite collision in darkBASIC pro

Posted by user1601163 on Game Development See other posts from Game Development or by user1601163
Published on 2012-09-01T02:44:31Z Indexed on 2012/09/01 3:50 UTC
Read the original article Hit count: 383

Filed under:
|

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.

  ///////////////////////////////////////////////////////////
  //
  //     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
load image "media\paddle1.png",1
load image "media\paddle2.png",2
load image "media\ball.png",3
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

//ball&paddle collision
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.

© Game Development or respective owner

Related posts about 2d

Related posts about bounding-boxes