Author Topic: Brick Smasher  (Read 7327 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Brick Smasher
« Reply #15 on: July 08, 2019, 11:17:11 am »
Actually I take that back, I think I know a way to control the ball. I'll try it anyway soon.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Brick Smasher
« Reply #16 on: July 08, 2019, 12:47:10 pm »
OK here it is... There's some control, maybe 3/4 of it is control or so, but there's also a lot of random. I'm no genius so I can't say exactly how this goes lol, but it plays fine for me. :)
I used the oldwheel again to see which direction the paddle is moving when you hit the ball. Tell me what you think, thanks. I think the reason why it's not 100% control is because the computer loops faster than you move the wheel, but that's OK, it kinda adds some challenge to the game.

Code: QB64: [Select]
  1. 'Brick Smasher was created by Ken G. with some help from people at the QB64.org forum, thanks!
  2. 'This game is freeware.
  3. start:
  4. SCREEN _NEWIMAGE(640, 480, 32)
  5. paddles = 10
  6. x = 300: y = 450
  7. points = 0
  8. level = 0
  9. snd = 950
  10. FOR yyy = 10 TO 440 STEP 10
  11.     _LIMIT 300
  12.     sz = INT(RND * 50) + 10
  13.     xxx = INT(RND * 570) + 10
  14.     c = INT(RND * 225) + 30
  15.     c2 = INT(RND * 225) + 30
  16.     c3 = INT(RND * 225) + 30
  17.     CIRCLE (xxx, yyy), sz, _RGB32(c, c2, c3)
  18.     PAINT (xxx, yyy), _RGB32(c, c2, c3), _RGB32(c, c2, c3)
  19.     _DELAY .1
  20.     snd = snd - 10
  21.     SOUND snd, .25
  22.     CIRCLE (xxx, yyy), sz, _RGB32(0, 0, 0)
  23.     PAINT (xxx, yyy), _RGB32(0, 0, 0)
  24. NEXT yyy
  25. SOUND 100, .5
  26. LOCATE 7, 28: PRINT "B R I C K   S M A S H E R"
  27. LOCATE 10, 28: PRINT "       By Ken G."
  28. PRINT "                 You start with 10 Paddles."
  29. PRINT "                 Use the mouse wheel to move."
  30. PRINT "                 Press Esc anytime to quit."
  31. INPUT "                 Press Enter Key to start!", st$
  32. 'This starts a new level.
  33. levels:
  34. DIM brick(500), xx(500), yy(500)
  35. SCREEN _NEWIMAGE(640, 480, 32)
  36. IF b = 0 THEN GOTO skip2:
  37. FOR tt = 1 TO b
  38.     brick(tt) = 0
  39.     xx(tt) = 0
  40.     yy(tt) = 0
  41. NEXT tt
  42. b = 0
  43. bb = 0
  44. t = 0
  45. skip2:
  46. col = INT(RND * 225) + 30
  47. col2 = INT(RND * 225) + 30
  48. col3 = INT(RND * 225) + 30
  49. level = level + 1
  50. level$ = STR$(level)
  51. score$ = STR$(points)
  52. paddles$ = STR$(paddles)
  53. titl$ = "Brick Smasher"
  54. titl2$ = "Score:" + score$
  55. titl3$ = "Paddles:" + paddles$
  56. titl4$ = "Level:" + level$
  57. setup:
  58. 'This loads all the bricks into memory.
  59. FOR yy = 50 TO 250 STEP 50
  60.     col = col + 500
  61.     FOR xx = 100 TO 500 STEP 100
  62.         b = b + 1
  63.         xx(b) = xx
  64.         yy(b) = yy
  65.         LINE (xx, yy)-(xx + 50, yy + 5), _RGB32(col, col2, col3), BF
  66.     NEXT xx
  67. NEXT yy
  68. go:
  69. up = 1
  70. down = 0
  71. right = 0
  72. left = 0
  73. upx = INT(RND * 10) - 5
  74. IF paddles < 10 OR level > 1 THEN
  75.     CIRCLE (oldbx, oldby), 5, _RGB32(0, 0, 0)
  76.     PAINT (oldbx, oldby), _RGB32(0, 0, 0)
  77.     LINE (oldx, oldy)-(oldx + 80, oldy + 10), _RGB32(0, 0, 0), BF
  78. bx = x + 20
  79. by = y - 6
  80. oldbx = bx
  81. oldby = by
  82. oldx = x
  83. oldy = y
  84. LINE (x, y)-(x + 80, y + 10), _RGB32(255, 0, 0), BF
  85. mouseWheel = 0
  86. go2:
  87. oldwheel = mouseWheel
  88.     mouseX = _MOUSEX
  89.     mouseY = _MOUSEY
  90.     mouseLeftButton = _MOUSEBUTTON(1)
  91.     mouseRightButton = _MOUSEBUTTON(2)
  92.     mouseMiddleButton = _MOUSEBUTTON(3)
  93.     mouseWheel = mouseWheel + _MOUSEWHEEL
  94. LOCATE 1, 1: PRINT titl$
  95. LOCATE 1, 16: PRINT titl2$
  96. LOCATE 1, 36: PRINT titl3$ + "   "
  97. LOCATE 1, 50: PRINT titl4$
  98.  
  99. a$ = INKEY$
  100. IF a$ = CHR$(27) THEN END
  101.  
  102. 'Right
  103. IF mouseWheel > oldwheel THEN
  104.     moveright = 1
  105.     moveleft = 0
  106.     nomove = 0
  107.     oldx = x
  108.     x = x + 20
  109.     IF x > 560 THEN x = 560
  110.     IF oldx <> x THEN
  111.         LINE (oldx, oldy)-(oldx + 80, oldy + 10), _RGB32(0, 0, 0), BF
  112.         LINE (x, y)-(x + 80, y + 10), _RGB32(255, 0, 0), BF
  113.     END IF
  114.  
  115. 'Left
  116. IF mouseWheel < oldwheel THEN
  117.     moveleft = 1
  118.     moveright = 0
  119.     nomove = 0
  120.     oldx = x
  121.     x = x - 20
  122.     IF x < 0 THEN x = 0
  123.     IF oldx <> x THEN
  124.         LINE (oldx, oldy)-(oldx + 80, oldy + 10), _RGB32(0, 0, 0), BF
  125.         LINE (x, y)-(x + 80, y + 10), _RGB32(255, 0, 0), BF
  126.     END IF
  127.  
  128. IF mouseWheel = oldwheel THEN
  129.     nomove = 1
  130.  
  131. IF up = 1 THEN
  132.     oldbx = bx
  133.     oldby = by
  134.     CIRCLE (oldbx, oldby), 5, _RGB32(0, 0, 0)
  135.     PAINT (oldbx, oldby), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  136.     bx = bx + upx
  137.     by = by - 2
  138.     CIRCLE (bx, by), 5, _RGB32(127, 255, 127)
  139.     PAINT (bx, by), _RGB32(255, 0, 0), _RGB32(127, 255, 127)
  140.  
  141. IF down = 1 THEN
  142.     oldbx = bx
  143.     oldby = by
  144.     CIRCLE (oldbx, oldby), 5, _RGB32(0, 0, 0)
  145.     PAINT (oldbx, oldby), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  146.     bx = bx + downx
  147.     by = by + 2
  148.     CIRCLE (bx, by), 5, _RGB32(127, 255, 127)
  149.     PAINT (bx, by), _RGB32(255, 0, 0), _RGB32(127, 255, 127)
  150.  
  151. IF right = 1 THEN
  152.     oldbx = bx
  153.     oldby = by
  154.     CIRCLE (oldbx, oldby), 5, _RGB32(0, 0, 0)
  155.     PAINT (oldbx, oldby), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  156.     bx = bx + 2
  157.     IF down = 1 THEN by = by + 2
  158.     IF up = 1 THEN by = by - 2
  159.     CIRCLE (bx, by), 5, _RGB32(127, 255, 127)
  160.     PAINT (bx, by), _RGB32(255, 0, 0), _RGB32(127, 255, 127)
  161.  
  162. IF left = 1 THEN
  163.     oldbx = bx
  164.     oldby = by
  165.     CIRCLE (oldbx, oldby), 5, _RGB32(0, 0, 0)
  166.     PAINT (oldbx, oldby), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  167.     bx = bx - 2
  168.     CIRCLE (bx, by), 5, _RGB32(127, 255, 127)
  169.     PAINT (bx, by), _RGB32(255, 0, 0), _RGB32(127, 255, 127)
  170.  
  171. 'Check the paddle.
  172. IF bx > x - 1 AND bx < x + 81 AND by > y - 1 AND by < y + 11 THEN
  173.     SOUND 200, .5
  174.     up = 1
  175.     down = 0
  176.     IF moveright = 1 THEN
  177.         right = 1
  178.         left = 0
  179.         nomove = 0
  180.         moveleft = 0
  181.         nomove = 0
  182.         downx = (oldwheel + mouseWheel) / 2
  183.         olddownx = downx
  184.     END IF
  185.     IF moveleft = 1 THEN
  186.         left = 1
  187.         right = 0
  188.         nomove = 0
  189.         moveright = 0
  190.         nomove = 0
  191.         downx = (oldwheel - mouseWheel) / 2
  192.         olddownx = downx
  193.     END IF
  194.     IF nomove = 1 THEN
  195.         downx = -(olddownx)
  196.         moveright = 0
  197.         moveleft = 0
  198.     END IF
  199.     oldbx = bx
  200.     oldby = by
  201.     bx = bx - upx
  202.     by = by - 7
  203.     CIRCLE (oldbx, oldby), 5, _RGB32(0, 0, 0)
  204.     PAINT (oldbx, oldby), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  205.     LINE (x, y)-(x + 80, y + 10), _RGB32(255, 0, 0), BF
  206.  
  207. 'Check Bricks
  208. FOR yy = 50 TO 250 STEP 50
  209.     FOR xx = 100 TO 500 STEP 100
  210.         bb = bb + 1
  211.         IF brick(bb) = 1 THEN GOTO nextbrick:
  212.         IF bx > xx(bb) - 1 AND bx < xx(bb) + 51 AND by > yy(bb) - 1 AND by < yy(bb) + 6 THEN
  213.             points = points + 10
  214.             CIRCLE (oldbx, oldby), 5, _RGB32(0, 0, 0)
  215.             PAINT (oldbx, oldby), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  216.             SOUND 600, .5
  217.             LINE (xx(bb), yy(bb))-(xx(bb) + 50, yy(bb) + 5), _RGB32(0, 0, 0), BF
  218.             brick(bb) = 1
  219.             IF up = 1 THEN
  220.                 up = 0:
  221.                 down = 1
  222.                 GOTO skip:
  223.             END IF
  224.             IF down = 1 THEN
  225.                 down = 0
  226.                 up = 1
  227.             END IF
  228.             skip:
  229.             CIRCLE (bx, by), 5, _RGB32(127, 255, 127)
  230.             PAINT (bx, by), _RGB32(255, 0, 0), _RGB32(127, 255, 127)
  231.             level$ = STR$(level)
  232.             score$ = STR$(points)
  233.             titl$ = "Brick Smasher"
  234.             titl2$ = "Score:" + score$
  235.             titl3$ = "Paddles:" + paddles$
  236.             titl4$ = "Level:" + level$
  237.             t = t + 1
  238.             IF t = 25 GOTO levels:
  239.         END IF
  240.         nextbrick:
  241.     NEXT xx
  242. NEXT yy
  243. bb = 0
  244.  
  245. IF bx < 6 THEN
  246.     right = 1
  247.     left = 0
  248.     rightx = RND * 2 + 1
  249.     oldbx = bx
  250.     oldby = by
  251.     CIRCLE (oldbx, oldby), 5, _RGB32(0, 0, 0)
  252.     PAINT (oldbx, oldby), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  253.     bx = bx + rightx
  254.     IF down = 1 THEN
  255.         olddownx = downx
  256.         RANDOMIZE TIMER
  257.         downx = RND * 2 + 1
  258.         bx = bx + downx
  259.     END IF
  260.     IF up = 1 THEN
  261.         by = by - 2
  262.         RANDOMIZE TIMER
  263.         upx = RND * 2 + 1
  264.         bx = bx + upx
  265.     END IF
  266.     CIRCLE (bx, by), 5, _RGB32(127, 255, 127)
  267.     PAINT (bx, by), _RGB32(255, 0, 0), _RGB32(127, 255, 127)
  268.  
  269. IF bx > 634 THEN
  270.     left = 1
  271.     right = 0
  272.     leftx = RND * 3 - 3
  273.     oldbx = bx
  274.     oldby = by
  275.     CIRCLE (oldbx, oldby), 5, _RGB32(0, 0, 0)
  276.     PAINT (oldbx, oldby), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  277.     bx = bx - leftx
  278.     IF down = 1 THEN
  279.         olddownx = downx
  280.         RANDOMIZE TIMER
  281.         downx = RND * 3 - 3
  282.         bx = bx + downx
  283.     END IF
  284.     IF up = 1 THEN
  285.         by = by - 2
  286.         RANDOMIZE TIMER
  287.         upx = RND * 3 - 3
  288.         bx = bx + upx
  289.     END IF
  290.     CIRCLE (bx, by), 5, _RGB32(127, 255, 127)
  291.     PAINT (bx, by), _RGB32(255, 0, 0), _RGB32(127, 255, 127)
  292.  
  293.  
  294. IF by > 480 THEN
  295.     up = 1
  296.     down = 0
  297.     oldbx = bx
  298.     oldby = by
  299.     CIRCLE (oldbx, oldby), 5, _RGB32(0, 0, 0)
  300.     PAINT (oldbx, oldby), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  301.     paddles = paddles - 1
  302.     paddles$ = STR$(paddles)
  303.     level$ = STR$(level)
  304.     score$ = STR$(points)
  305.     titl$ = "Brick Smasher"
  306.     titl2$ = "Score:" + score$
  307.     titl3$ = "Paddles:" + paddles$
  308.     titl4$ = "Level:" + level$
  309.     CIRCLE (bx, by), 5, _RGB32(127, 255, 127)
  310.     PAINT (bx, by), _RGB32(255, 0, 0), _RGB32(127, 255, 127)
  311.     IF paddles = 0 THEN
  312.         LOCATE 9, 30
  313.         PRINT " G A M E       O V E R"
  314.         LOCATE 14, 30
  315.         INPUT "Play Again? (Yes/No)", ag$
  316.         IF ag$ = "y" OR ag$ = "Y" OR ag$ = "Yes" OR ag$ = "YES" OR ag$ = "yes" OR ag$ = "yES" OR ag$ = "yeS" THEN GOTO start:
  317.         END
  318.     END IF
  319.     GOTO go:
  320.  
  321. IF by < 22 THEN
  322.     down = 1
  323.     up = 0
  324.     olddownx = downx
  325.     downx = RND * 5 - 2.5
  326.     oldbx = bx
  327.     oldby = by
  328.     CIRCLE (oldbx, oldby), 5, _RGB32(0, 0, 0)
  329.     PAINT (oldbx, oldby), _RGB32(0, 0, 0), _RGB32(0, 0, 0)
  330.     bx = bx + downx
  331.     by = by + downx
  332.     CIRCLE (bx, by), 5, _RGB32(127, 255, 127)
  333.     PAINT (bx, by), _RGB32(255, 0, 0), _RGB32(127, 255, 127)
  334.  
  335.  
  336. GOTO go2:
  337.  
  338.  
  339.  


« Last Edit: July 08, 2019, 12:50:26 pm by SierraKen »

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Brick Smasher
« Reply #17 on: July 08, 2019, 05:44:47 pm »
Cool game... That ball has some wicked moves! Lost most of my paddles because of them....   Nicely done!
Logic is the beginning of wisdom.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Brick Smasher
« Reply #18 on: July 08, 2019, 09:27:03 pm »
Thanks Johno.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Brick Smasher
« Reply #19 on: July 10, 2019, 06:27:39 am »
Hi SierraKen

I must say Cool! I like sound of the past times!
Colors, the same, fine to use scrolling wheel of the mouse for paddle movements.

Feedback:
Movement of ball is too fancy and mad and at random, it is an your coded feature the absence of incremental speed of the ball.
The passing of the ball among the blocks sometimes leaves a shadow that cancel part of the block with no collision (so I think that this is a graphic bug and not a logic bug)

Lovely
Thanks to  share!
Programming isn't difficult, only it's  consuming time and coffee

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Brick Smasher
« Reply #20 on: July 10, 2019, 12:39:42 pm »
Thanks TempodiBasic! Yeah, there's some flaws. I tried to update it with some control of the ball, sometimes, lol... It's just the way I made everything that makes it sometimes have no control. I think I will just keep it as it is. Thanks though. :)

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: Brick Smasher
« Reply #21 on: July 10, 2019, 12:44:28 pm »
Right. You can't please all of the people all of the time; so the thing to remember is... Just make sure I'm OK with it, and you're golden!

Pete
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Brick Smasher
« Reply #22 on: July 10, 2019, 01:06:27 pm »
LOL thanks Pete. :)