Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Text-based Pong
#1
For certain reasons, i've decided to make a text-based pong in basic (using just print and locate :o ). I've written up most of it, but im stuck at the part where the ball should bounce off the paddle, any ideas on how to add in this 'collision' info to my paddles?

Also, I know the PaddleRow looks like it needs an array, but i thought this would slow down the paddles even more than they already are...

This is really my first attempt at writing a simple game and useful program in basic, so any help would be greatly appreciated!

Code:
cls
print "***Program by: RJ***"
print "Play some pong!!!"
input "Hit anykey to continue.";p
cls

let PaddleRow1=5:PaddleRow2=6:PaddleRow3=7:PaddleRow4=8
let LeftColumn=3:RightColumn=78

let x=10:y=10
let xadj=1:yadj=1
do
'game

      'top outline
      let r= 1
      let c= 1
      for c = 1 to 80
        locate r,c
        print Chr$(177)
      next c

      'bottom outline
      let r= 22
      let c=1
      for c = 1 to 80
        locate r,c
        print Chr$(177)
      next c

      'left outline
      let c=1
      let r=1
      for r=1 to 22
        locate r,c
        print Chr$(177)
      next r

      'right outline
      let c=80
      let r=1
      for r = 1 to 22
        locate r,c
        print Chr$(177)
      next r


      'black to erase ball because cls sux
      locate x,y
      print Chr$(255)

      'bouncy ball

      IF y <= 2 THEN yadj = 1
      IF y >= 79 THEN yadj = -1
      IF x >= 21 THEN xadj = -1
      IF x <= 2 THEN xadj = 1
      x = x + xadj
      y = y + yadj
     locate x,y
     print Chr$(2)
    
     'paddle
     key$=inkey$
     if key$<>"" then
         'use black to erase paddle
         locate PaddleRow1,LeftColumn
         print Chr$(255)
         locate PaddleRow2,LeftColumn
         print Chr$(255)
         locate PaddleRow3,LeftColumn
         print Chr$(255)
         locate PaddleRow4,LeftColumn
         print Chr$(255)
         locate PaddleRow1,RightColumn
         print Chr$(255)
         locate PaddleRow2,RightColumn
         print Chr$(255)
         locate PaddleRow3,RightColumn
         print Chr$(255)
         locate PaddleRow4,RightColumn
         print Chr$(255)

     'paddle
     if PaddleRow4< 21 then if key$="s" then let PaddleRow1=PaddleRow1+1:PaddleRow2=PaddleRow2+1:PaddleRow3=PaddleRow3+1:PaddleRow4=PaddleRow4+1
     if PaddleRow1> 2 then if key$="w" then let PaddleRow1=PaddleRow1-1:PaddleRow2=PaddleRow2-1:PaddleRow3=PaddleRow3-1:PaddleRow4=PaddleRow4-1
    
     locate PaddleRow1,LeftColumn
     print Chr$(186)
     locate PaddleRow2,LeftColumn
     print Chr$(186)
     locate PaddleRow3,LeftColumn
     print Chr$(186)
     locate PaddleRow4,LeftColumn
     print Chr$(186)
     locate PaddleRow1,RightColumn
     print Chr$(186)
     locate PaddleRow2,RightColumn
     print Chr$(186)
     locate PaddleRow3,RightColumn
     print Chr$(186)
     locate PaddleRow4,RightColumn
     print Chr$(186)
   end if

loop
Reply
#2
Every time it loops, check the x and y posisition of the ball compared to each paddle and have it reverse directions/bounce at 90 deg. angles off the paddle if it comes close enough.... example:

lets say ballx and bally are coords of ball, and lets say that paddlex and paddley are paddle coords.

Lets say the paddle is 10 units tall (y axis)

If you're drawing it from the top down then the top edge of the paddle will be paddley, and the bottom edge will be paddley + 10

so:

Code:
IF ballx = paddlex THEN  'check for ball impacting side of paddle
           IF bally >= paddley AND bally<= paddley + 10 THEN 'ball in realm of top and bottom of paddle
                    BallXHeading= -BallXHeading '90 degree bouncing
                    BallYHeading= -BallYHeading  '90 degree bouncing
            END IF
END IF

This assumes that your paddle is only 1 character wide (x axis). If it's bigger than that, figure out the coords of the edge that you want the ball to impact and check accordingly (Similar to bally if statement).

Good Luck.
That Poons a nub!"
"WTF does "poon a nub" mean??"
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)