Computer Science Canada

[Q-Basic] Pong Game

Author:  Weapon X [ Mon May 08, 2006 4:40 pm ]
Post subject:  [Q-Basic] Pong Game

hey all, i have just started learning Qbaisc and since i already know vb i can easily program in qbasic. so now i made a pong game in qbasic but the ball and the 2 paddles keep flikering, if anyone can help me stop the fliker that would be awesome. thanx

code:

DIM x AS INTEGER
DIM xmod AS INTEGER
DIM y AS INTEGER
DIM ymod AS INTEGER
DIM delay AS DOUBLE
DIM c AS DOUBLE
DIM linex AS INTEGER
DIM liney AS INTEGER
DIM linex2 AS INTEGER
DIM liney2 AS INTEGER
DIM dc AS INTEGER
x = 320
y = 240
xmod = 1
ymod = 1
delay = 1
c = 0
linex = 10
liney = 240
linex2 = 630
liney2 = 240
DO
        x = x + xmod
        y = y + ymod
        liney2 = y
        press$ = INKEY$
        IF press$ = "a" THEN
                liney = liney - 8
        ELSEIF press$ = "z" THEN
                liney = liney + 8
        END IF
        IF x > 623 THEN
                xmod = -xmod
        ELSEIF x < 17 THEN
                xmod = -xmod
        ELSEIF y < 17 THEN
                ymod = -ymod
        ELSEIF y > 463 THEN
                ymod = -ymod
        ELSEIF liney + 40 = 480 THEN
                liney = liney - 8
        ELSEIF liney - 40 = 0 THEN
                liney = liney + 8
        END IF
        REM IF (y = liney + 40 OR y = liney - 40) AND (x = linex + 5 OR x = linex - 5) THEN
            REM xmod = -xmod
            REM ymod = -ymod
        REM END IF
        SCREEN 12
        CIRCLE (x, y), 17, 120
        LINE (linex - 5, liney - 40)-(linex + 5, liney + 40), 120, BF
        LINE (linex2 - 5, liney2 - 40)-(linex2 + 5, liney2 + 40), 120, BF
        CIRCLE (x, y), 17, 0
        LINE (linex - 5, liney - 40)-(linex + 5, liney + 40), 0, BF
        LINE (linex2 - 5, liney2 - 40)-(linex2 + 5, liney2 + 40), 0, BF
        press$ = ""
LOOP


Author:  Weapon X [ Sun May 14, 2006 12:16 am ]
Post subject:  aww :(

...anyone? Sad

Author:  [Gandalf] [ Sun May 14, 2006 12:38 am ]
Post subject: 

Sure, seeing as how I first got into programming using QBASIC and some other BASIC variants...

It's been a while since I've done much in BASIC, but one improvement I can suggest is to make your code more dynamic. If you ever decided to improve it it would become difficult to keep track of all the co-ordinate values, which you seem to have hardcoded a lot of, ie:
code:
ELSEIF y > 463 THEN


The game itself is functional, though you could have the score be outputted.

Instead of learning BASIC now, you could choose a more modern and interesting language like Ruby to learn, though ultimately it's up to you. I'm sure you would get a larger response from the compsci.ca community as well.


: