Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. GraphicsWindow.BackgroundColor = "Black"
  2. GraphicsWindow.Width = 565
  3. GraphicsWindow.Height = 500
  4. GraphicsWindow.Title = "Breakout"
  5. GraphicsWindow.PenColor = "White"
  6. GraphicsWindow.BrushColor = "White"
  7.  
  8. 'Bricks
  9. For row = 1 To 3
  10. For col = 1 To 5
  11. xCoord = 50 + (col - 1) * 100
  12. yCoord = 25 * row
  13. GraphicsWindow.FillRectangle(xCoord, yCoord, 65, 12)
  14. arrayName = "Row" + row
  15. Array.SetValue(arrayName, col, 1)
  16. EndFor
  17. EndFor
  18.  
  19.  
  20.  
  21.  
  22. 'Main Block
  23. mainBlockXCoord = 240
  24. mainBlock = Shapes.AddRectangle(100, 15)
  25. Shapes.Move(mainBlock, mainBlockXCoord, 480)
  26. Mouse.ShowCursor()
  27. GraphicsWindow.MouseMove = OnMouseMove
  28.  
  29. PrintScore()
  30.  
  31.  
  32. GraphicsWindow.KeyDown = OnKeyDown
  33. GraphicsWindow.KeyUp = OnKeyDown
  34.  
  35. 'Ball
  36. ball = Shapes.AddEllipse(10, 10)
  37. x = 275.5
  38. y = GraphicsWindow.Height - 50
  39. Shapes.Move(ball, 275.5, 425)
  40.  
  41. deltaX = 1
  42. deltaY = -2
  43.  
  44. While "True"
  45. x = x + deltaX
  46. y = y + deltaY
  47.  
  48. ' If the wall is hit, change the direction
  49. If x >= GraphicsWindow.Width - 10 Or x <= 0 Then
  50. deltaX = -deltaX
  51. EndIf
  52.  
  53. If y <= 0 Then
  54. deltaY = -deltaY
  55. EndIf
  56.  
  57. deltaX = deltaX - 0.01 * (x - Shapes.GetLeft(ball))/30 'Put some diversion
  58. Shapes.Move(ball, x, y)
  59. Program.Delay(5)
  60.  
  61. ' If the main block is hit
  62. If y > GraphicsWindow.Height - 27 And x >= Shapes.GetLeft(mainBlock) And x <= Shapes.GetLeft(mainBlock) + 100 Then
  63. deltaY = -deltaY
  64. ElseIf Shapes.GetTop(ball) > GraphicsWindow.Height - 12 Then
  65. Program.Delay(500)
  66. GraphicsWindow.ShowMessage("Game Over!, Your score is: ", "Breakout")
  67. Program.End()
  68. EndIf
  69.  
  70. 'Check if Brick is hitted
  71. For row = 1 To 3
  72. For col = 1 To 5
  73. xCoord = 50 + (col - 1) * 100
  74. yCoord = 25 * row
  75. arrayName = "Row" + row
  76. If (y > yCoord - 10 And y < yCoord + 12) And (x >= xCoord And x <= xCoord + 100) Then
  77. If Array.GetValue(arrayName, col) = 1 Then
  78. Array.SetValue(arrayName, col, 0)
  79. Sound.PlayChime()
  80.  
  81. GraphicsWindow.PenColor = "Black"
  82. GraphicsWindow.BrushColor = "Black"
  83. GraphicsWindow.FillRectangle(xCoord, yCoord, 65, 12)
  84. GraphicsWindow.DrawRectangle(xCoord, yCoord, 65, 12)
  85. deltaY = -deltaY
  86. PrintScore()
  87. EndIf
  88. EndIf
  89.  
  90. EndFor
  91. EndFor
  92.  
  93. EndWhile
  94.  
  95.  
  96. 'GraphicsWindow.FillRectangle(50, 25, 65, 12)
  97. 'GraphicsWindow.FillRectangle(150, 25, 65, 12)
  98.  
  99. Sub PrintScore
  100. GraphicsWindow.BrushColor = "White"
  101. GraphicsWindow.DrawText(5, 5, "Score: " + 10)
  102. EndSub
  103.  
  104. Sub OnMouseMove
  105. If GraphicsWindow.MouseX >= 50 And GraphicsWindow.Mousex <= 515 Then
  106. Shapes.Move(mainBlock, GraphicsWindow.MouseX - 50, 480)
  107. EndIf
  108. Program.Delay(5)
  109. EndSub
  110.  
  111. Sub OnKeyDown
  112. keyPress = GraphicsWindow.LastKey
  113. shapeXCoord = Shapes.GetLeft(mainBlock)
  114. If keyPress = "Left" Then
  115. shapeXCoord = shapeXCoord - 10
  116. ElseIf keyPress = "Right" Then
  117. shapeXCoord = shapeXCoord + 10
  118. EndIf
  119. Shapes.Move(mainBlock, shapeXCoord, 480)
  120. Program.Delay(2)
  121.  
  122. If keyPress = "Escape" Then
  123. Program.End()
  124. EndIf
  125. EndSub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement