Weekly Qbasic and Qb64 Lesson Topics
March 29, 2024, 10:22:44 am
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Want to see a specific Tutorial? ASK!
 
  Home Help Search Arcade Links Staff List Login Register  

Bouncing ball

Pages: [1]
  Print  
Author Topic: Bouncing ball  (Read 718 times)
GarrisonRicketson
Admin
Administrator
Hero Member
*****
Posts: 583



WWW
« on: September 06, 2011, 10:01:09 pm »

I had copied this code from some where, and saved it, it has a paddle and a moveing ball, but the paddle dose not move,..I don't know who wrote the original code,..I added a few lines,..and tried changeing some things,..but still could not get the paddle moveing.
Code:
REM
DEFINT A-Z

DIM Ball%(540)
DIM Mask%(540)
DIM Background%(540)
DIM PaddleBak%(102) '10x40

SCREEN 12
_FULLSCREEN
PRINT "HELLO WORLD"
PLAY "ageba"
PRINT "Can anyone tell me who owns this code ? "

CX = 20: CY = 10: oldcx = CX: oldcy = CY
px = 420: py = 440: oldpx = px: oldpy = py
GOSUB MakBall
GOSUB MakMask
CLS
GOSUB MakBackground

Horizontal = 4: Vertical = 4

DO
    Past! = TIMER

    GOSUB GetKey
    PUT (oldpx, oldpy), PaddleBak%(0), PSET
    PUT (oldcx, oldcy), Background%(0), PSET

    GET (px, py)-(px + 39, py + 9), PaddleBak%(0)
    GET (CX, CY)-(CX + 19, CY + 19), Background%(0)

    LINE (px, py)-(px + 39, py + 9), 3, BF
    PUT (CX, CY), Mask%(0), AND 'draw ball
    PUT (CX, CY), Ball%(0), XOR 'draw ball

    GOSUB Movement
    GOSUB Boundary
    WHILE Past! = TIMER: WEND
LOOP WHILE INKEY$ <> CHR$(27)
SYSTEM

'-GOSUBS
GetKey:
a% = 0
a$ = INKEY$
a$ = RIGHT$(a$, 1)
IF LEN(a$) > 0 THEN a% = ASC(a$)
RETURN

MakBall:
CIRCLE (9, 9), 9, 12
PAINT (9, 9), 2, 12
GET (0, 0)-(19, 19), Ball%(0)
RETURN

MakMask:
FOR x = 0 TO 19
    FOR y = 0 TO 19
        z = POINT(x, y)
        IF z <> 0 THEN PSET (x, y), 0 ELSE PSET (x, y), 8
    NEXT y
NEXT x
GET (0, 0)-(19, 19), Mask%(0)
RETURN


MakBackground:
FOR x = 0 TO 699 STEP 3
    LINE (x, 10)-(x - 50, 470), 7
NEXT x
GET (CX, CY)-(CX + 19, CY + 19), Background%(0)
GET (px, py)-(px + 39, py + 9), PaddleBak%(0)
RETURN

Movement:
oldcx = CX: oldcy = CY
CX = CX + Horizontal
CY = CY + Vertical

oldpx = px: oldpy = py
IF a% = 75 THEN
    px = px - 4
    IF px < 10 THEN px = 10
END IF
IF a% = 77 THEN
    px = px + 4
    IF px > 590 THEN px = 590
END IF
RETURN

Boundary:
IF CX <= 10 THEN
    CX = 10
    Horizontal = -Horizontal
END IF
IF CX >= 620 THEN
    CX = 620
    Horizontal = -Horizontal
END IF
IF CY <= 10 THEN
    CY = 10
    Vertical = -Vertical
END IF

IF CY >= 420 THEN
    IF CX >= px AND CX <= px + 39 THEN
        CY = 420
        Vertical = -Vertical
    END IF
END IF
IF CY > 460 THEN END
RETURN



   
Report Spam   Logged


Pages: [1]
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum


Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy