Nunez
If pong is what is interesting to you then we should work on that one.
What was your Dark Basic version? Pro or Classic?
Anyways,
I should hope you know these commands
value = Upkey()
value = Downkey()
value = Leftkey()
value = Rightkey()
Those commands decide whether any of those keys are being pressed.
You might use them in a code such as
If Upkey()=1 Then Print "hello"
The 2D graphic commands you should become familiar with are:
Box X1,Y1,X2,Y2
Circle X,Y,Radius
Your paddles will be boxes and your ball will be a circle. For example the paddle may be
From now on I am going to add comments into the code. Hopefully you know what they are and how to use them. Comment with the ` key and REM. Some times I may get carried away and use //. If I use // just think of it a comment that you cannot use in Dark Basic.
Anyways so we know how to make our paddles and ball, along with how to detect if an arrow key was pressed.
Now lets sum it up a bit into a little piece of code:
paddleX=20
paddleY=20
ballX=100
ballY=100
Do
Cls
Box paddleX,paddleY-20,paddleX+5,paddleY+20
Circle ballX,ballY,20
If Upkey()=1 Then paddleY=paddleY-1
If Downkey()=1 Then paddleY=paddleY+1
Loop
That little piece of code will make a paddle and ball. It will then get moved when you push up or down. The reason I did paddleY-20 and paddleY+20 is so that when I move the paddle up and down the core of the paddle will be the center. That becomes more helpful when we come down to collision.
Now it may or may not get difficult for you. It is time for collision between our ball and paddle.
If ballX<=paddleX+5 and ballY>=paddleY-20 and ballY<=paddleY+20 then bounce the ball
We want to make sure that the ball touches the paddle on both the x-axis and y-axis. Then we just tell the ball to do something else. Here is maybe a final code:
paddleX=20
paddleY=20
ballX=100
ballY=100
bspdX=1
bspdY=1
Do
Cls
Box paddleX,paddleY-20,paddleX+5,paddleY+20
Circle ballX,ballY,20
ballX=ballX+bspdX
ballY=ballY+bspdY
If Upkey()=1 Then paddleY=paddleY-1
If Downkey()=1 Then paddleY=paddleY+1
If ballX<=paddleX+5 and ballY>=paddleY-20 and ballY<=paddleY+20
bspdX=-1
bspdY=-2
Endif
Loop
What that code does is when the ball hits the paddle, it bounces the other direction at an up diagnal direction. The ball speed x no longer matches the ball speed y so it is slanted.
I hope you get the idea a little.
Post back with your thoughts so far and we will continue.
The Lone Programmer
"Is The Juice Worth The Squeeze"
-The Girl Next Door