# also

by (Login MCalkins)
Moderator

First of all, I just want to make sure than you know that you can open Qbasic programs in Notepad, that way you can copy and paste to and from the forum, without having to type everything.

Moving:

SCREEN 12

so that it is after the part that asks the user for the difficulty level fixes that little white area in the ball sprite.

Also, I would recommend using something more like the following:

IF x = xmax - 19 AND y >= curtpos AND y <= curtpos + (speed * 30) THEN
dx = -1
ELSEIF x > xmax THEN
ponescore = ponescore + 1
GOTO begin
END IF

IF x = xmin + 10 AND y >= curpos AND y <= curpos + 100 THEN 'If ball g
dx = 1
ELSEIF x < xmin THEN
ptwoscore = ptwoscore + 1
GOTO begin
END IF

There are several changes here. First, it now uses the correct length for player two's paddle.

Second, I changed the number to 10 for player one's paddle, because 20-10=10. The ball's width is 9, so I changed the number to 19 for player two's paddle, because (630-620)+9=19. This should prevent the ball from going through the paddle as much before bouncing. (As it is, these numbers might be still 1 off, as these tests are done before the ball's position is incremented. That might be something to check.)

Third, I changed the < and > operations to =. The reason is that, since the ball can go past the paddle some distance before the player is declared to have lost, that the player could still catch the ball by moving the paddle, even after the ball has passed the paddle. I believe this change removes that concern.

Also, using this:

IF curtpos + (speed * 15) < 240 THEN curtpos = curtpos + (1 / 2) * speed
IF curtpos + (speed * 15) > 240 THEN curtpos = curtpos - (1 / 2) * speed

You can see that by changing 50 to (speed * 15), that player two's paddle goes to the center better.

Likewise, the same thing here:

IF y > curtpos + (speed * 15) THEN
curtpos = curtpos + (1 / 2) * speed
ELSEIF y < curtpos + (speed * 15) THEN
curtpos = curtpos - (1 / 2) * speed
END IF

Which targets player two's paddle better.

You are doing the bounds checking for both paddles after adjusting each paddle. This is redundant.

IF curtpos + (speed * 30) > 479 THEN curtpos = 479 - (speed * 30)

You can see that I've changed 450 to 479, to allow player two's paddle to go down as far as player one's paddle.

There might be more changes that could be made, or things that could be double checked, but I am feeling rather lazy at the moment. (yeah, I know, i've been full of excuses lately...) I didn't test my changes very well, but it should be an improvement. You might use a variable to track player two's paddle size so that you don't have to calculate it each time. (Better yet might be arrays that both players could share, to allow for the same code to handle both paddles. This might not be as fast in terms of execution speed, because of the over head involved in loops and arrays, but it would be more simple and elegant from a programming perspective. I might demonstrate this later.)

Regards,
Michael

 This message has been edited by MCalkins on Sep 5, 2011 7:20 PM

Posted on Sep 5, 2011, 7:18 PM

 Response Title Author and Date Re: also anonymous on Sep 6 Re: also anonymous on Sep 6 Re: Re: also Michael Calkins on Sep 8 Re: Re: also pmarathe on Sep 8