Hi there.
I've been working with a friend on a project in Basic 256.
We're trying to create a pong game with two paddles, but somethings wrong the ball never comes back when ballx is over 275. It always says "You missed" but the ball never comes back.
Here's the code:
cls
print "Use the J and K keys to move the paddle"
print "Use the A and D keys to move the paddle"
loop1:
a1 = key
if a1 = 68 then y1 = y1 + 30
if a1 = 65 then y1 = y1 - 30
if y1 < 0 then y1 = 0
if y1 > 200 then y1 = 200
gosub drawpaddle1
gosub moveball
gosub drawball
refresh
pause 0.0000000000000000000000000000000000001
a2 = key
if a2 = 75 then y2 = y2 + 30
if a2 = 74 then y2 = y2 - 30
if y2 < 0 then y2 = 0
if y2 > 200 then y2 = 200
gosub drawpaddle2
gosub moveball
gosub drawball
goto loop1
refresh
moveball:
ballx = ballx + ballxinc
bally = bally + ballyinc
if bally > 270 then ballyinc = -ballyinc
if bally < 5 then ballyinc = -ballyinc
if ballx > 295 then gosub checkball
if ballx < 5 then gosub checkball
return
pause 0.0000000000000000000000000000000000001
drawpaddle1:
color gray
rect 0,0,400,400
color darkblue
rect x1,y1,10,100
color blue
rect x1+1,y1+1,8,98
rect x2+1,y2+1,8,98
refresh
return
checkball:
if bally < y1 - 70 then goto missed
if bally > (y1 + 150) then goto missed
ballyinc = -ballyinc
ballxinc = ((ballx -x1) - 50) / 10
pause 0.0000000000000000000000000000000000001
drawpaddle2:
color gray
rect 0,0,400,400
color darkblue
rect x2,y2,10,100
color blue
rect x2+1,y2+1,8,98
rect x1+1,y1+1,8,98
color yellow
line 150,0,150,300
drawball:
color black
circle ballx, bally, 5
color white
circle ballx, bally, 4
return
missed:
print "You Missed!!"
bally = 10
refresh
return
Can you please help us?
It's very important!
Sincerly,
Alex and Philipp
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am a beginner at programming but I'll try to help. This much I know: It's best to get a small portion of a program working and than add a little at a time while testing each small addition.
I just tried to make a pong game. Here are the steps I took.
1) Draw a rectangle in the middle of one end. (Easily done)
2) Find the key values for Q (up) and A (down). (Easily done)
3) Get the rectangle to move when pressing Q or A. (Easily done)
4) Draw another rectangle on the other end (Easily done)
5) Find key values for P (up) and L (up). (Easily done)
6) Get the second rectangle to move for P and L. (Easily done)
7) Get both rectangles to move at the same time while pressing Q or A and P or L. -Here's where I ran into trouble. If I pressed both Q and P (at the same time) the program would only recognize one as being pressed.
I copied, pasted and ran your program and noticed the same thing -could only get one paddle to move at a time. I wonder if it is a limitation of Basic 256 to only be able to work with one key being pressed at a time. This maybe is the root cause of the problem you are having.
It will take someone more knowledgeable than me to know how to get the program to recognize more than one key being pressed at a time (or if it is even possible).
Hope this helps, good luck, have fun,
Dave
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi there.
I've been working with a friend on a project in Basic 256.
We're trying to create a pong game with two paddles, but somethings wrong the ball never comes back when ballx is over 275. It always says "You missed" but the ball never comes back.
Here's the code:
cls
print "Use the J and K keys to move the paddle"
print "Use the A and D keys to move the paddle"
fastgraphics
x1 = 285
y1 = 105
ballx = 30
bally = 0
ballxinc = 5
ballyinc = 5
xinc = 5
fastgraphics
x2 = 5
y2 = 105
xinc = 5
pause 0.0000000000000000000000000000000000001
loop1:
a1 = key
if a1 = 68 then y1 = y1 + 30
if a1 = 65 then y1 = y1 - 30
if y1 < 0 then y1 = 0
if y1 > 200 then y1 = 200
gosub drawpaddle1
gosub moveball
gosub drawball
refresh
pause 0.0000000000000000000000000000000000001
a2 = key
if a2 = 75 then y2 = y2 + 30
if a2 = 74 then y2 = y2 - 30
if y2 < 0 then y2 = 0
if y2 > 200 then y2 = 200
gosub drawpaddle2
gosub moveball
gosub drawball
goto loop1
refresh
moveball:
ballx = ballx + ballxinc
bally = bally + ballyinc
if bally > 270 then ballyinc = -ballyinc
if bally < 5 then ballyinc = -ballyinc
if ballx > 295 then gosub checkball
if ballx < 5 then gosub checkball
return
pause 0.0000000000000000000000000000000000001
drawpaddle1:
color gray
rect 0,0,400,400
color darkblue
rect x1,y1,10,100
color blue
rect x1+1,y1+1,8,98
rect x2+1,y2+1,8,98
refresh
return
checkball:
if bally < y1 - 70 then goto missed
if bally > (y1 + 150) then goto missed
ballyinc = -ballyinc
ballxinc = ((ballx -x1) - 50) / 10
pause 0.0000000000000000000000000000000000001
drawpaddle2:
color gray
rect 0,0,400,400
color darkblue
rect x2,y2,10,100
color blue
rect x2+1,y2+1,8,98
rect x1+1,y1+1,8,98
color yellow
line 150,0,150,300
drawball:
color black
circle ballx, bally, 5
color white
circle ballx, bally, 4
return
missed:
print "You Missed!!"
bally = 10
refresh
return
Can you please help us?
It's very important!
Sincerly,
Alex and Philipp
I am a beginner at programming but I'll try to help. This much I know: It's best to get a small portion of a program working and than add a little at a time while testing each small addition.
I just tried to make a pong game. Here are the steps I took.
1) Draw a rectangle in the middle of one end. (Easily done)
2) Find the key values for Q (up) and A (down). (Easily done)
3) Get the rectangle to move when pressing Q or A. (Easily done)
4) Draw another rectangle on the other end (Easily done)
5) Find key values for P (up) and L (up). (Easily done)
6) Get the second rectangle to move for P and L. (Easily done)
7) Get both rectangles to move at the same time while pressing Q or A and P or L. -Here's where I ran into trouble. If I pressed both Q and P (at the same time) the program would only recognize one as being pressed.
I copied, pasted and ran your program and noticed the same thing -could only get one paddle to move at a time. I wonder if it is a limitation of Basic 256 to only be able to work with one key being pressed at a time. This maybe is the root cause of the problem you are having.
It will take someone more knowledgeable than me to know how to get the program to recognize more than one key being pressed at a time (or if it is even possible).
Hope this helps, good luck, have fun,
Dave
The checkball subroutine only checks for the paddle on the right (y1). Shouldn't there be a subroutine to check for the left (y2) paddle as well?
Dave