Microsoft Small Basic

Program Listing: GBS016
GraphicsWindow.Width=640
GraphicsWindow.Height=400
GraphicsWindow.BackgroundColor="Gray"
GraphicsWindow.Top=Desktop.Height/2-200
GraphicsWindow.Left=Desktop.Width/2-350
GraphicsWindow.BrushColor="white"
GraphicsWindow.FillEllipse(0,150,50,100)
GraphicsWindow.FillEllipse(590,150,50,100)
GraphicsWindow.DrawEllipse(0,150,50,100)
GraphicsWindow.DrawEllipse(590,150,50,100)
GraphicsWindow.BrushColor="lightgray"
GraphicsWindow.FillRectangle(20,25,600,350)
GraphicsWindow.PenColor="gray"
For i=1 To 59
For k=1 To 34
GraphicsWindow.DrawEllipse(20+(i*10),25+(k*10),1,1)
EndFor
EndFor
GraphicsWindow.PenColor="black"
GraphicsWindow.DrawLine(320,25,320,375)
GraphicsWindow.DrawEllipse(270,150,100,100)
GraphicsWindow.DrawRectangle(20,25,600,350)
GraphicsWindow.PenColor="red"
GraphicsWindow.DrawLine(20,152,20,248)
GraphicsWindow.DrawLine(620,152,620,248)
GraphicsWindow.PenColor="black"
For i=1 To 2
If i=1 Then
b=50
GraphicsWindow.BrushColor="red"
Else
GraphicsWindow.BrushColor="Blue"
b=GraphicsWindow.Width-86
EndIf
player[i]=Shapes.AddEllipse(36,36)
Shapes.Move(player[i],b,187)
EndFor
GraphicsWindow.BrushColor="skyblue"
ball=Shapes.AddEllipse(20,20)
Shapes.Move(ball,310,190)
velocity=0
GraphicsWindow.KeyDown=keydown
GraphicsWindow.KeyUp=keyup
x1=GraphicsWindow.Width-86
y1=187
x2=50
y2=187
dt=0.07

Sub keyup
last=GraphicsWindow.LastKey
If last="Right" Then
right1="False"
EndIf
If last="Left" Then
left1="False"
EndIf
If last="Up" Then
up1="False"
EndIf
If last="Down" Then
down1="False"
EndIf
If last="D" Then
right2="False"
EndIf
If last="A" Then
left2="False"
EndIf
If last="W" Then
up2="False"
EndIf
If last="S" Then
down2="False"
EndIf
EndSub


Sub keydown
last=GraphicsWindow.LastKey
If last="Right" Then
right1="True"
EndIf
If last="Left" Then
left1="True"
EndIf
If last="Up" Then
up1="True"
EndIf
If last="Down" Then
down1="True"
EndIf
If last="D" Then
right2="True"
EndIf
If last="A" Then
left2="True"
EndIf
If last="W" Then
up2="True"
EndIf
If last="S" Then
down2="True"
EndIf
EndSub


While "True"
If right1 Then
velocity=5
x1=x1+dc
EndIf
If left1 Then
velocity=5
x1=x1-dc
EndIf
If up1 Then
velocity=5
y1=y1-dc
EndIf
If down1 Then
velocity=5
y1=y1+dc
EndIf
If right2 Then
velocity=5
x2=x2+dc
EndIf
If left2 Then
velocity=5
x2=x2-dc
EndIf
If up2 Then
velocity=5
y2=y2-dc
EndIf
If down2 Then
velocity=5
y2=y2+dc
EndIf
dc=velocity * dt / 2
For i=0 To velocity
Shapes.Move(player[1],x2,y2)
Shapes.Move(player[2],x1,y1)
velocity=velocity-1
EndFor
Program.Delay(dt)
EndWhile