GraphicsWindow.Title = "Rocker"
gw = 450
gh = 400
tx = 225
ty = 320
score = 0
angle = 0
ballDirection = -1
ballSpeed = 0.3
acceleration = 1.001
power = 1.2
gameStarted = "False"
ballX = 210
ballY = 280
GraphicsWindow.KeyDown = OnKeyDown
CreateUI()
gameOver = "False"
While gameStarted = "False"
Program.Delay(300)
EndWhile
gameStartTime = Clock.ElapsedMilliseconds
Shapes.Remove(directions)
While gameOver = "False"
Shapes.Rotate(paddle, angle)
power = 1 + Math.Abs(angle) / 200
Shapes.Rotate(paddle, angle)
CalculateBallMetrics()
Shapes.Move(ball, ballX, ballY)
WriteTime()
Program.Delay(20)
If ballX < 105 Or ballX > 315 Then
gameOver = "True"
EndIf
EndWhile
GraphicsWindow.ShowMessage("You survived for " + timeDisplayText + ".", "Game Over")
Sub CreateUI
GraphicsWindow.CanResize = "False"
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.Top = (Desktop.Height - gh) / 2
GraphicsWindow.Left = (Desktop.Width - gw) / 2
GraphicsWindow.DrawRectangle(10, 10, 430, 380)
GraphicsWindow.BrushColor = "Violet"
tri = Shapes.AddTriangle(tx, ty, tx - 50, ty + 50, tx + 50, ty + 50)
GraphicsWindow.BrushColor = "Purple"
paddle = Shapes.AddRectangle(210, 10)
Shapes.Move(paddle, 120, 310)
GraphicsWindow.BrushColor = "Red"
ball = Shapes.AddEllipse(30, 30)
Shapes.Move(ball, ballX, ballY)
GraphicsWindow.FontSize = 16
GraphicsWindow.FontName = "Verdana"
directions = Shapes.AddText("Press ENTER to start the game!")
Shapes.Move(directions, 80, 150)
GraphicsWindow.BrushColor = "Blue"
timeText = Shapes.AddText("Time: 00:00")
Shapes.Move(timeText, 310, 16)
EndSub
Sub OnKeyDown
If gameStarted = "True" Then
If GraphicsWindow.LastKey = "Left" Then
angle = Math.Max(-40, angle - 1)
ElseIf GraphicsWindow.LastKey = "Right" Then
angle = Math.Min(40, angle + 1)
EndIf
Else
If GraphicsWindow.LastKey = "Return" Then
gameStarted = "True"
EndIf
EndIf
EndSub
Sub CalculateBallMetrics
If ballDirection * Math.Abs(angle) = angle Then
ballSpeed = Math.Min(2, ballSpeed * power)
Else
ballSpeed = Math.Max(0.1, ballSpeed / power)
If ballSpeed < 0.2 Then
ballDirection = -1 * ballDirection
ballSpeed = 0.2
EndIf
EndIf
ballX = ballX + ballDirection * ballSpeed
deltaX = ballX - 210
deltaY = deltaX * Math.Sin(Math.GetRadians(angle))
ballY = 280 + deltaY
EndSub
Sub WriteTime
elapsedTime = Clock.ElapsedMilliseconds - gameStartTime
totalSeconds = Math.Round(elapsedTime / 1000)
seconds = Math.Remainder(totalSeconds, 60)
minutes = Math.Round(totalSeconds / 60)
If (seconds < 10) Then
seconds = Text.Append("0", seconds)
EndIf
If (minutes < 10) Then
minutes = Text.Append("0", minutes)
EndIf
timeDisplayText = minutes + ":" + seconds
Shapes.SetText(timeText, "Time: " + timeDisplayText)
EndSub