|
Post by ccefal on May 10, 2006 16:37:23 GMT
how can i make QB run a program that is the same as the Atari game pong ?
|
|
|
Post by Mikrondel on May 11, 2006 8:52:50 GMT
Well, let's go down to objects. We'll start with just one - the ball.
What does the program need to know about it? -Where it is and how to calculate where it will be.
I.e., its X and Y co-ordinates, as well as its X and Y speeds. Let's try this: BallX = 10 BallY = 10 BallXSpeed = 3 BallYSpeed = 2
What does it do several times a second?
It erases the ball from its old position, calculates its new position, and draws it there. Isn't that simple?
We'll use SCREEN 13 because it has big pixels. Then we... PSET (BallX, BallY), 0 'Erase old BallX = BallX + BallXSpeed BallY = BallY + BallYSpeed PSET (BallX, BallY), 15 'Draw in new position
Now, we also add a bit of a delay to stop the ball being ultra-fast, and to make its speed the same on any half-decent computer, and the final program looks like this:
SCREEN 13
BallX = 10 BallY = 10 BallXSpeed = 3 BallYSpeed = 2
DO DelayWait! = TIMER + .1 PSET (BallX, BallY), 0 BallX = BallX + BallXSpeed BallY = BallY + BallYSpeed PSET (BallX, BallY), 15 DO: LOOP WHILE TIMER < DelayWait!
LOOP
You'll notice that the ball flies straight off the screen- obviously if it hits the top or bottom (that'd be its Y coordinate going out of bounds) then it bounces: This means its vertical speed is made negative. (You'll need IF-THENs checking this every time the position changes.)
Also if it goes past the left, a point is earned for one player, and to the right, a point is earned for the other player, and both make the ball restart somewhere centre-ish.
You're quite lucky that I was feeling generous and gave you all this help. Please show us that you're not going to just "take, take, take", and in future show us your own attempts and talk to us a little more. If you don't understand something then say so, and don't ask us to tell you how to do something very complex if you don't understand how all of its parts work first.
Good luck.
|
|
|
Post by earlofqb on May 11, 2006 19:55:19 GMT
Spiffy Pong tutorial. Microsoft posted something similar to this a few years ago, but it was oriented towards VB.NET, and I think they even had one for C++. With a bit of code, this thing would actually be a very spiffy Pong game. Also, if he or she really wanted a Pong program for free, there'd be thousands of websites where this has been discussed. So, really I suppose we should be honoured that he or she chose us. At least I do, for at least it got me to post on here again
|
|
|
Post by esibiebodba on May 10, 2019 8:05:23 GMT
|
|