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"
- numberOfRows = 3
- score = 0
- totalBricks = 0
- InitializeComponents()
- 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.001 * (x - Shapes.GetLeft(ball)) / 30 'Put some diversion
- Shapes.Move(ball, x, y)
- Program.Delay(5)
- CheckIfMainBlockIsHitted()
- CheckIfBrickIsHitted()
- If totalBricks = 0 Then
- GraphicsWindow.Clear()
- GraphicsWindow.FontSize = 30
- GraphicsWindow.BrushColor = "Green"
- GraphicsWindow.DrawText(200, 185, "You Won!")
- GraphicsWindow.FontSize = 25
- GraphicsWindow.DrawText(185, 235, "Your score is: " + score)
- EndIf
- EndWhile
- Sub CheckIfMainBlockIsHitted
- ' If the main block is hit
- If y > GraphicsWindow.Height - 29 And x >= Shapes.GetLeft(mainBlock) And x <= Shapes.GetLeft(mainBlock) + 100 Then
- deltaY = -deltaY
- mainBlockMiddleX = Shapes.GetLeft(mainBlock) + 50
- If Shapes.GetLeft(ball) + 5 <= mainBlockMiddleX Then
- If deltaX > 0 Then
- deltaX = -deltaX
- Else
- deltaX = deltaX - 0.1
- EndIf
- ElseIf Shapes.GetLeft(ball) + 5 > mainBlockMiddleX Then
- If deltaX > 0 Then
- deltaX = deltaX + 0.1
- Else
- deltaX = -deltaX
- EndIf
- EndIf
- ElseIf Shapes.GetTop(ball) > GraphicsWindow.Height - 12 Then
- EndGame()
- EndIf
- EndSub
- Sub CheckIfBrickIsHitted
- For row = 1 To numberOfRows
- 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.PlayClick()
- GraphicsWindow.PenColor = "Black"
- GraphicsWindow.BrushColor = "Black"
- GraphicsWindow.FillRectangle(xCoord, yCoord, 65, 12)
- GraphicsWindow.DrawRectangle(xCoord, yCoord, 65, 12)
- deltaY = -deltaY
- totalBricks = totalBricks - 1
- score = score + 1
- PrintScore()
- EndIf
- EndIf
- EndFor
- EndFor
- EndSub
- Sub InitializeComponents
- 'Bricks
- For row = 1 To numberOfRows
- For col = 1 To 5
- xCoord = 50 + (col - 1) * 100
- yCoord = 25 * row
- GraphicsWindow.BrushColor = GraphicsWindow.GetRandomColor()
- GraphicsWindow.FillRectangle(xCoord, yCoord, 65, 12)
- arrayName = "Row" + row
- Array.SetValue(arrayName, col, 1)
- totalBricks = totalBricks + 1
- EndFor
- EndFor
- 'Main Block
- mainBlockXCoord = 240
- mainBlock = Shapes.AddRectangle(100, 15)
- Shapes.Move(mainBlock, mainBlockXCoord, 480)
- Mouse.ShowCursor()
- GraphicsWindow.MouseMove = OnMouseMove
- PrintScore()
- 'Ball
- ball = Shapes.AddEllipse(10, 10)
- x = 275.5
- y = GraphicsWindow.Height - 50
- Shapes.Move(ball, 275.5, 425)
- GraphicsWindow.KeyDown = OnKeyDown
- GraphicsWindow.KeyUp = OnKeyDown
- EndSub
- Sub PrintScore
- GraphicsWindow.BrushColor = "Black"
- GraphicsWindow.FillRectangle(10, 5, 100, 20)
- GraphicsWindow.BrushColor = "White"
- GraphicsWindow.DrawText(5, 5, "Score: " + score)
- 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
- Sub EndGame
- Sound.PlayBellRing()
- GraphicsWindow.Clear()
- GraphicsWindow.FontSize = 30
- GraphicsWindow.BrushColor = "Red"
- GraphicsWindow.DrawText(200, 185, "Game Over!")
- GraphicsWindow.FontSize = 25
- GraphicsWindow.DrawText(195, 235, "Your score is: " + score)
- Program.Delay(3000)
- Program.End()
- EndSub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement