QB / QB64 Discussion Forum      Other Subforums, Links and Downloads
Respond to this messageReturn to Index
Original Message
  • SLR Game _ BRick Smash v.01
    • (Login unseenmachine)
      R
      Posted Jun 11, 2010 5:54 AM

      Based on breakout, this is a final tweaked version of .01. Let me know what you think, UNSEEN.


      code....

      'SLR Games - Brick Smash v.01 - By Unseen Machine

      DIM SHARED scrn AS LONG, cx AS INTEGER, cy AS INTEGER, pflag AS INTEGER, bcnt AS INTEGER
      DIM SHARED fnt AS LONG, px AS INTEGER, py AS INTEGER, oldpx AS INTEGER, oldpy AS INTEGER
      DIM SHARED KeyDown(127) AS LONG, bx AS INTEGER, by AS INTEGER, bdirect AS INTEGER
      DIM SHARED colcnt AS INTEGER, rowcnt AS INTEGER, brick(1 TO 7, 1 TO 5) AS INTEGER
      DIM SHARED lives AS INTEGER

      RANDOMIZE TIMER

      _TITLE " Brick Smash v.01"

      scrn = _NEWIMAGE(1200, 900, 12)

      SCREEN scrn, , 1, 1

      CALL drawgrid

      CALL Drawbricks

      px = 540: py = 610: pflag = 1

      rndm = INT(RND * 5) + 1

      bx = 560: by = 390

      FOR c = 1 TO rndm

      by = by - 20

      NEXT

      bdinitial = INT(RND * 2)

      IF bdinitial = 1 THEN bdirect = 4 ELSE bdirect = 2

      lives = 3

      GOSUB drawpaddle
      _DELAY 1

      now! = TIMER
      bnow! = TIMER

      DO

      LOCATE 2, 30: PRINT "Lives : ", lives
      IF bcnt = 35 THEN GOSUB win
      newnow! = TIMER
      bnow2! = TIMER

      colcnt = (bx - 100) / 20
      rowcnt = (by - 50) / 20

      IF pflag = 2 THEN GOSUB clrpaddle
      IF pflag = 1 THEN GOSUB drawpaddle

      IF newnow! - now! >= .1 THEN

      CALL control
      CALL collision
      now! = TIMER

      END IF

      IF bnow2! - bnow! >= .15 THEN

      CALL Ball
      bnow! = TIMER

      END IF

      LOOP

      drawpaddle:
      oldpx = px
      FOR i = 1 TO 4

      PAINT (px, py), 15, 7
      px = px + 20

      NEXT
      px = oldpx
      pflag = 0
      RETURN


      clrpaddle:
      FOR i = 1 TO 4

      PAINT (oldpx, py), 0, 7
      oldpx = oldpx + 20

      NEXT
      pflag = 1
      RETURN

      win:
      CLS
      LOCATE 5, 30: PRINT "Well Done = You have completed the game."
      _DELAY 5
      SYSTEM


      SUB collision

      colstart = 2
      rowstart = 2

      FOR b = 1 TO 5

      IF rowcnt = rowstart THEN

      FOR a = 1 TO 7

      IF colcnt >= colstart AND colcnt <= colstart + 4 THEN

      IF brick(a, b) = 0 THEN

      bcnt = bcnt + 1
      brick(a, b) = 1
      CALL Drawbricks
      IF bdirect = 1 THEN bdirect = 4
      IF bdirect = 3 THEN bdirect = 2

      END IF

      END IF

      colstart = colstart + 7

      NEXT a
      END IF

      rowstart = rowstart + 3

      NEXT

      END SUB


      SUB Ball

      PAINT (bx, by), 0, 7

      IF by >= 610 AND lives = 0 THEN

      RUN

      ELSEIF by >= 610 THEN

      lives = lives - 1
      bx = 560: by = 390

      _DELAY 1

      FOR c = 1 TO rndm

      by = by - 20

      NEXT

      bdinitial = INT(RND * 2)

      IF bdinitial = 1 THEN bdirect = 4 ELSE bdirect = 2
      px = 540: py = 610: pflag = 2

      END IF

      IF POINT(bx + 20, by + 20) = 15 AND bdirect = 2 THEN bdirect = 3
      IF POINT(bx, by + 20) = 15 AND bdirect = 2 THEN bdirect = 3
      IF POINT(bx - 20, by + 20) = 15 AND bdirect = 4 THEN bdirect = 1
      IF POINT(bx, by + 20) = 15 AND bdirect = 2 THEN bdirect = 3

      IF bdirect = 3 AND bx = 1080 THEN bdirect = 1
      IF bdirect = 1 AND by = 50 THEN bdirect = 4
      IF bdirect = 4 AND bx = 100 THEN bdirect = 2
      IF bdirect = 1 AND bx = 100 THEN bdirect = 3
      IF bdirect = 3 AND by = 50 THEN bdirect = 2
      IF bdirect = 2 AND bx = 1080 THEN bdirect = 4

      IF bdirect = 1 THEN 'up left

      IF by > 50 THEN by = by - 20
      IF bx > 100 THEN bx = bx - 20

      ELSEIF bdirect = 2 THEN 'down right

      IF by < 620 THEN by = by + 20
      IF bx < 1080 THEN bx = bx + 20

      ELSEIF bdirect = 3 THEN 'up right

      IF by > 50 THEN by = by - 20
      IF bx < 1080 THEN bx = bx + 20

      ELSEIF bdirect = 4 THEN ' down left

      IF by < 620 THEN by = by + 20
      IF bx > 100 THEN bx = bx - 20

      END IF

      PAINT (bx, by), 1, 7

      END SUB

      SUB drawgrid

      cx = 100: cy = 50

      FOR i = 1 TO 1500

      CIRCLE (cx, cy), 10, 7
      cx = cx + 20

      IF i MOD 50 = 0 THEN cx = 100: cy = cy + 20

      NEXT i

      END SUB


      SUB Drawbricks

      cx = 140: cy = 90

      FOR k = 1 TO 5

      FOR j = 1 TO 7

      FOR i = 1 TO 4

      IF POINT(cx, cy) = 0 AND brick(j, k) = 0 THEN

      PAINT (cx, cy), 6, 7

      ELSEIF brick(j, k) = 1 THEN

      PAINT (cx, cy), 0, 7

      END IF
      cx = cx + 20

      NEXT i

      cx = cx + 60

      NEXT j

      cx = 140
      cy = cy + 60

      NEXT

      END SUB


      SUB control

      'Galleoans INP(&H60) routine for keyboard input - logs multiple keys
      'update keydown states

      i& = INP(&H60)
      DO
      IF (i& AND 128) THEN KeyDown(i& XOR 128) = 0
      IF (i& AND 128) = 0 THEN KeyDown(i&) = -1
      i2& = i&
      i& = INP(&H60)
      LOOP UNTIL i& = i2&
      DO: LOOP UNTIL INKEY$ = "" 'flush INKEY$ buffer

      IF KeyDown(75) THEN

      oldpx = px
      IF px > 100 THEN
      px = px - 20
      pflag = 2
      END IF

      ELSEIF KeyDown(77) THEN

      oldpx = px
      IF px < 1020 THEN
      px = px + 20
      pflag = 2
      END IF

      END IF

      END SUB
    Login Status
  • You are not logged in
    • Login
      Password
       

      Optional
      Provides additional benefits such as notifications, signatures, and user authentication.


      Create Account
    Your Name
    Your Email
    (Optional)
    Message Title
    Message Text
    Options Also send responses to my email address