GraphicsWindow.brushcolor="Black"
GraphicsWindow.DrawText(100,100,"Control the Red ball using the Arrow keys")
GraphicsWindow.DrawText(100,125,"See how many Blue balls you can collect")
GraphicsWindow.DrawText(100,150,"Without coming into contact with Yellow ones")
GraphicsWindow.brushcolor="red"
GraphicsWindow.FillEllipse(400,100,20,20)
GraphicsWindow.brushcolor="Black"
GraphicsWindow.drawEllipse(400,100,20,20)
GraphicsWindow.brushcolor="Blue"
GraphicsWindow.FillEllipse(400,125,20,20)
GraphicsWindow.brushcolor="Black"
GraphicsWindow.drawEllipse(400,125,20,20)
GraphicsWindow.brushcolor="yellow"
GraphicsWindow.FillEllipse(400,150,20,20)
GraphicsWindow.brushcolor="black"
GraphicsWindow.drawEllipse(400,150,20,20)
'ButtonSub
Sub ButtonClick
B=Controls.LastClickedButton
If (B=StartButton) Then
GraphicsWindow.Clear()
GraphicsWindow.BrushColor="Black"
GraphicsWindow.DrawText(10,50,"Score: ")
Food()
StartGame()
elseif (B=StartButtonReset) Then
GraphicsWindow.Clear()
GraphicsWindow.BrushColor="Black"
GraphicsWindow.DrawText(10,50,"Score: ")
xPos=400
yPos=300
NewGame = 1
food()
StartGame()
EndIf
endsub
'Start game sub
Sub StartGame
GraphicsWindow.BrushColor="red"
ball=shapes.AddEllipse(20,20)
Shapes.Move(ball,xPos,yPos)
' GenerateBallToAvoid()
EndSub
'Keypress sub
Sub Keypressed
If NewGame = 1 then
Timer.Resume()
NewGame = 0
else
Move=10
If GraphicsWindow.lastkey="Left" And xPos > 0 Then
xPos=xPos-move
Shapes.Move(ball,xPos,yPos)
elseif GraphicsWindow.lastkey="Right" And xPos < 780 then
xPos=xPos+move
Shapes.Move(ball,xPos,yPos)
elseif graphicswindow.lastkey="Up" and yPos > 0 then
yPos=yPos-move
Shapes.Move(ball,xPos,yPos)
elseif graphicswindow.lastkey="Down" and yPos < 580 then
yPos=yPos+move
Shapes.Move(ball,xPos,yPos)
elseif GraphicsWindow.lastkey="Escape" then
Program.End()
endif
If (xPos = foodxpos - 15) and (yPos = foodypos - 15) Then
elseif (xPos = foodxpos) and (yPos = foodypos) then
score=score+1
GraphicsWindow.BrushColor="lightblue"
GraphicsWindow.FillRectangle(50,50,100,100)
GraphicsWindow.BrushColor="black"
GraphicsWindow.DrawText(50,50,score)
For counter = 1 to TempCounter
If ((foodxpos > x[counter] - 20) and (foodxpos < x[counter] + 20)) or ((foodypos > y[counter] - 20) and (foodypos < y[counter] + 20)) then
OK = "False"
counter = TempCounter
else
OK = "True"
EndIf
If (OK = "True") and (counter = tempcounter) then
Shapes.move(food,foodxpos,foodypos)
NoOfBallsToAvoid = NoOfBallsToAvoid + 1
GenerateBallToAvoid()
MoveBall()
EndIf
endfor
endwhile
endif
'If (xPos = x + 20) and (yPos = y + 20) Then
' elseif (xPos = x) and (yPos = y) then
For z = 1 to NoOfBallsToAvoid
If ((xPos > x[z] - 20) And (xPos < x[z] + 20)) And ((yPos > y[z] - 20) And (yPos < y[z] + 20)) then
x = Math.GetRandomNumber(80)*10
y = Math.GetRandomNumber(60)*10
GraphicsWindow.Clear()
'GraphicsWindow.BrushColor="Black"
'GraphicsWindow.DrawText(350,250,"Game Over :(")
'GraphicsWindow.DrawText(345,275,"Your score is "+score)
For i = 1 To 7000
xEnd=math.GetRandomNumber(800)
yEnd=math.GetRandomNumber(600)
'GraphicsWindow.brushcolor="yellow"
GraphicsWindow.BrushColor="Yellow"
GraphicsWindow.FillEllipse(xEnd,yEnd,20,20)
GraphicsWindow.brushcolor="black"
GraphicsWindow.drawEllipse(xEnd,yEnd,20,20)
endfor
Timer.Pause()
GraphicsWindow.Clear()
GraphicsWindow.BrushColor="Black"
GraphicsWindow.DrawText(350,250,"Game Over :(")
GraphicsWindow.DrawText(345,275,"Your score is "+score)
StartButtonReset=Controls.AddButton("Try Again",360,300)
' Controls.ButtonClicked=ButtonClickReset
endif
endfor
endif
endsub
'Food sub
Sub Food
GraphicsWindow.BrushColor="blue"
food=shapes.addEllipse(20,20)
Shapes.Animate(food,foodxpos,foodypos,0)
endsub