
-----------------------------------
Comp_Expert777
Thu Dec 25, 2003 10:10 am

Help on Pong Program
-----------------------------------
I need help on my pong game. I cant figure out how to make the ball bounce off the paddles on my pong program. Can someone help me? 


Here is the code: 

drawfillbox (0,0,maxx,maxy,black)

var font1, font2, font3 : int
font1:= Font.New ("serif:220:bold")
font2 := Font.New ("sans serif:15:bold")
font3 := Font.New ("sans serif:15:bold")
Font.Draw ("Pong", 5,150,font1,white)

Font.Draw ("Start Game", 265,100,font2,white)
Font.Draw ("Quit Game", 265,50,font3,white)
drawfillbox (50,20,150,30,brightblue)
drawfillbox (405,375,500,385,brightred)

var ch : string (1)
var x, y, btnnum, btnupdown : int 
loop
if buttonmoved ("down") then
buttonwait ("down", x,y,btnnum,btnupdown)
locate (1,1)
for i : 1..100
%Variables
var y1 : int 
var x1 : int 
var c : int 
if x  > 256 and x < 400 then
if y > 100 and y < 300 then
View.Set ("offscreenonly")
View.Update
cls
%Second Page
View.Set ("offscreenonly")
var chars : array char of boolean
var x2,y2,x3,y3 : int := 0
var row : int := 630
var column : int :=2
loop

var rowchange, columnchange := 1
loop
drawfillbox (0,0,maxx,maxy,black)
if row = 630 or row= 0 then
rowchange := -rowchange
end if 
if column= 394 or column = 0 then
columnchange := -columnchange
end if 
locatexy (row,column)
drawfilloval (row,column,10,10,brightgreen)
row :=row + rowchange
column:= column+columnchange

Input.KeyDown (chars)
locate (1,1)
drawfillbox (x2+5,y2,x2+15,y2+70,brightblue)
if chars (KEY_UP_ARROW) then
y2 := y2+2
end if 
if chars (KEY_DOWN_ARROW) then
y2 := y2-2
end if 
if y2328 then
y2:=328
end if

Input.KeyDown (chars)
locate (1,1)
drawfillbox (x3+635,y3,x3+625,y3+70,brightblue)
if chars ('w') then
y3 := y3+2
end if 
if chars ('s') then
y3 := y3-2
end if 
if y3328 then
y3:=328
end if
drawline(maxx div 2,0,maxx div 2,maxy,brightgreen)
View.Update
cls
drawfillbox (0,0,maxx,maxy,black)
end loop 
end loop
end if 
end if 
end for 
end if 
end loop

-----------------------------------
DanShadow
Thu Dec 25, 2003 11:15 am


-----------------------------------
An easier way, (but a little worse) is this way. Take a look: 

Draw.FillBox (0, 0, maxx, maxy, 255)
var ballx, bally, px, py, xstep, ystep, score : int := 0
var key : string (1) := ""
ballx := 230
bally := 200
xstep := 1
ystep := 1
px := 10
py := 200
loop
    if hasch then
        getch (key)
    end if
    Draw.FillOval (ballx, bally, 10, 10, 255)
    Draw.FillBox (px - 8, py - 20, px, py + 20, 1)
    delay (5)
    ballx := ballx + xstep
    bally := bally + ystep
    Draw.FillOval (ballx, bally, 10, 10, 12)
    Draw.FillBox (px - 20, py - 50, px, py + 50, 255)
    if ballx + 10 >= maxx then
        xstep := -1
    elsif ballx - 10 = maxy then
        ystep := -1
    elsif bally - 10  256 and x < 400 then
if y > 100 and y < 300 then
View.Set ("offscreenonly")
View.Update
cls
%Second Page
View.Set ("offscreenonly")
var chars : array char of boolean
var x2,y2,x3,y3 : int := 0
var a : int 
a := 200 
var p2,p1:int 
p2:=0 
p1:=0 
loop

View.Set ("offscreenonly")
var ballx,bally : int :=200 
var xstep,ystep : int := 1 
loop 
ballx:=ballx+xstep 
bally:=bally+ystep 
drawfilloval(ballx, bally, 10, 10, 0) 
delay(5) 
drawfilloval(ballx, bally, 10, 10, 12) 
if ballx+15>=maxx then 
xstep:=-1 
elsif ballx-15=maxy then 
ystep:=-1 
elsif bally-15 256 and x < 400 then
if y > 100 and y < 300 then
View.Set ("offscreenonly")
View.Update
cls
%Second Page
View.Set ("offscreenonly")
var chars : array char of boolean
var x2,y2,x3,y3 : int := 0
var a : int 
a := 200 
var p2,p1:int 
p2:=0 
p1:=0 
loop

View.Set ("offscreenonly")
var ballx,bally : int := 200 
var xstep,ystep : int := 1 
loop 
ballx:=ballx+xstep 
bally:=bally+ystep 
drawfilloval(ballx, bally, 10, 10, brightred) 
if ballx+15>=maxx then 
xstep:=-1 
elsif ballx-15=maxy then 
ystep:=-1 
elsif bally-15=maxx then 
p1:=p1+1 
elsif ballx-15