Microsoft Small Basic

Program Listing: TWN285-0
'Challenge of the Month - April 2014 dodge obstcles by NaochanON TWN285

Init()
GraphicsWindow.KeyDown=onkeydown

While NN<1 ' Gmae ends when Hit NN=1
arrowX=arrowX+dx
If arrowX<0 Then
arrowX=10
dx=2
ElseIf arrowX>GraphicsWindow.Width-40 then
arrowX=GraphicsWindow.Width-45
dx=-2
EndIf
Shapes.move(Rect,arrowX,420) ' Rect move
RectX=Shapes.GetLeft(Rect)
RectY=Shapes.GetTop(Rect)
For i =0 To Array.GetItemCount(CLR)
Shapes.Move(CHR[i], shapes.GetLeft(CHR[i]), shapes.Gettop(CHR[i])+fall[i]) ' move Unicode Characters
Half=Size[i]/2
CHRX=Shapes.GetLeft(CHR[i])
CHRY=Shapes.Gettop(CHR[i])
If Math.Abs(Rectx+20-(CHRX+Half))<20 And Math.abs(RectY+10-(CHRY+Half))<10 Then
NN=NN+1
Sound.PlayClick()
elseIf shapes.Gettop(CHR[i])>500 Then
MM=MM+1
Shapes.Move(CHR[i], Math.GetRandomNumber(640),-100-Math.GetRandomNumber(200) )
EndIf
EndFor
Shapes.SetText(msg," Dodged count "+(MM))
Program.Delay(10)
endWhile

Sub onkeydown
dx=(text.GetCharacterCode(GraphicsWindow.LastKey)-79) ' Right=82 Left=76
EndSub

Sub Init
GraphicsWindow.Show()
GraphicsWindow.BackgroundColor="Lightcyan"
CLR="0=Red;1=Green;2=Yellow;3=Navy;4=Black;5=Brown;6=Orange"
For i = 0 To Array.GetItemCount(CLR)
GraphicsWindow.BrushColor=CLR[i]
Size[i]=Math.GetRandomNumber(20)*2+30
GraphicsWindow.FontSize=Size[i]
CHR[i] =Shapes.Addtext(Text.GetCharacter(2*16*16*16+6*16*16+9*16+i)) ' 2653- 265C 2690 -2699 UNICODE character
Shapes.Move(CHR[i],Math.GetRandomNumber(640),-100-Math.GetRandomNumber(200) )
fall[i]=(10+Math.GetRandomNumber(10))/5 ' falling speed
EndFor
GraphicsWindow.PenColor=CLR[1]
GraphicsWindow.brushColor=CLR[1]
Rect = Shapes.AddRectangle(40,20)
arrowX=200
GraphicsWindow.FontSize=25
msg=Shapes.AddText(" ")
endsub