Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GraphicsWindow.BackgroundColor = "Black"
- GraphicsWindow.Width = 565
- GraphicsWindow.Height = 500
- GraphicsWindow.Title = "Breakout"
- GraphicsWindow.PenColor = "White"
- GraphicsWindow.BrushColor = "White"
- 'Bricks
- For row = 1 To 3
- For col = 1 To 5
- xCoord = 50 + (col - 1) * 100
- yCoord = 25 * row
- GraphicsWindow.FillRectangle(xCoord, yCoord, 65, 12)
- arrayName = "Row" + row
- Array.SetValue(arrayName, col, 1)
- EndFor
- EndFor
- 'Main Block
- mainBlockXCoord = 240
- mainBlock = Shapes.AddRectangle(100, 15)
- Shapes.Move(mainBlock, mainBlockXCoord, 480)
- Mouse.ShowCursor()
- GraphicsWindow.MouseMove = OnMouseMove
- PrintScore()
- GraphicsWindow.KeyDown = OnKeyDown
- GraphicsWindow.KeyUp = OnKeyDown
- 'Ball
- ball = Shapes.AddEllipse(10, 10)
- x = 275.5
- y = GraphicsWindow.Height - 50
- Shapes.Move(ball, 275.5, 425)
- deltaX = 1
- deltaY = -2
- While "True"
- x = x + deltaX
- y = y + deltaY
- ' If the wall is hit, change the direction
- If x >= GraphicsWindow.Width - 10 Or x <= 0 Then
- deltaX = -deltaX
- EndIf
- If y <= 0 Then
- deltaY = -deltaY
- EndIf
- deltaX = deltaX - 0.01 * (x - Shapes.GetLeft(ball))/30 'Put some diversion
- Shapes.Move(ball, x, y)
- Program.Delay(5)
- ' If the main block is hit
- If y > GraphicsWindow.Height - 27 And x >= Shapes.GetLeft(mainBlock) And x <= Shapes.GetLeft(mainBlock) + 100 Then
- deltaY = -deltaY
- ElseIf Shapes.GetTop(ball) > GraphicsWindow.Height - 12 Then
- Program.Delay(500)
- GraphicsWindow.ShowMessage("Game Over!, Your score is: ", "Breakout")
- Program.End()
- EndIf
- 'Check if Brick is hitted
- For row = 1 To 3
- For col = 1 To 5
- xCoord = 50 + (col - 1) * 100
- yCoord = 25 * row
- arrayName = "Row" + row
- If (y > yCoord - 10 And y < yCoord + 12) And (x >= xCoord And x <= xCoord + 100) Then
- If Array.GetValue(arrayName, col) = 1 Then
- Array.SetValue(arrayName, col, 0)
- Sound.PlayChime()
- GraphicsWindow.PenColor = "Black"
- GraphicsWindow.BrushColor = "Black"
- GraphicsWindow.FillRectangle(xCoord, yCoord, 65, 12)
- GraphicsWindow.DrawRectangle(xCoord, yCoord, 65, 12)
- deltaY = -deltaY
- PrintScore()
- EndIf
- EndIf
- EndFor
- EndFor
- EndWhile
- 'GraphicsWindow.FillRectangle(50, 25, 65, 12)
- 'GraphicsWindow.FillRectangle(150, 25, 65, 12)
- Sub PrintScore
- GraphicsWindow.BrushColor = "White"
- GraphicsWindow.DrawText(5, 5, "Score: " + 10)
- EndSub
- Sub OnMouseMove
- If GraphicsWindow.MouseX >= 50 And GraphicsWindow.Mousex <= 515 Then
- Shapes.Move(mainBlock, GraphicsWindow.MouseX - 50, 480)
- EndIf
- Program.Delay(5)
- EndSub
- Sub OnKeyDown
- keyPress = GraphicsWindow.LastKey
- shapeXCoord = Shapes.GetLeft(mainBlock)
- If keyPress = "Left" Then
- shapeXCoord = shapeXCoord - 10
- ElseIf keyPress = "Right" Then
- shapeXCoord = shapeXCoord + 10
- EndIf
- Shapes.Move(mainBlock, shapeXCoord, 480)
- Program.Delay(2)
- If keyPress = "Escape" Then
- Program.End()
- EndIf
- EndSub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement