Microsoft Small Basic

Program Listing: kbl066
' Challenge of the month September 2012 Wave by NaochanON


gui()
shipimage()
while "true"
MM=MM+1
wave()
Program.Delay(20)
endwhile

Sub wave
PY=math.Abs(Math.Cos(math.GetRadians(MM/10))) ' decide wave height
For NN=-10 To 280
Shapes.move(rect[NN],Shapes.GetLeft(rect[NN]),math.sin(Math.GetRadians(NN+MM))*200*PY+300)
If NN=90 Then ' ship position
shpy= Shapes.GetTop(rect[NN])-SH/2
shpx= Shapes.GetLeft(ship)
GraphicsWindow.Title=" Wave height = "+(300-(shpy+SH))
shpy2= Shapes.GetTop(rect[NN+SW/DP])-SH/2
angle= Math.GetDegrees(Math.ArcTan((shpy2-shpy)/SW)) ' get angle of ship
shipmoving()
EndIf
endfor
EndSub

Sub gui
GraphicsWindow.Hide()
GraphicsWindow.BackgroundColor="lightcyan"
GraphicsWindow.Width=1200
GraphicsWindow.Height=500
GraphicsWindow.BrushColor="Blue"
GraphicsWindow.PenColor="Blue"
DP=5 ' wave pitch
For I=-10 To 280
rect[I] = Shapes.AddRectangle(DP,1000)
Shapes.move(rect[I],I*DP,math.sin(Math.GetRadians(i*DP/5))*200+300) ' initial wave
If i=90 Then
shpX= Shapes.GetLeft(rect[I]) ' ship position
shpy= Shapes.Gettop(rect[I]) -SH/2
EndIf
EndFor
EndSub

Sub shipimage
' ------------------- ship image ----------------------------------
sW=100 ' ship length
sH=20 ' ship height
tW=6 ' head or trail triangle width
tH=sH-6 ' head or trail triangle height
GraphicsWindow.BrushColor="darkgreen"
GraphicsWindow.PenColor="darkgreen"
tri1=Shapes.AddTriangle(-tw,0,0,0,0,tH) ' trail
tri2=Shapes.AddTriangle(sw,0,sw+tW,0,sw,tH) ' head
ship= Shapes.AddRectangle(sW,sH) ' body
GraphicsWindow.BrushColor="lightcyan"
GraphicsWindow.PenColor="Red"
For i=1 To 6
window[i]= Shapes.AddEllipse(8,8) ' window
EndFor
angle=0
shipmoving()
GraphicsWindow.Show()
EndSub

Sub shipmoving
Shapes.Move(tri1,shpX,shpY)
Shapes.Move(tri2,ShpX,shpY)
Shapes.Move(ship,ShpX,ShpY)
Shapes.Rotate(ship,angle)
Shapes.Rotate(tri1,angle)
Shapes.Rotate(tri2,angle)
For i=1 To 6
dx=Math.Cos(Math.GetRadians(angle))
dy=Math.sin(Math.GetRadians(angle))
Shapes.Move(window[i],ShpX+(i*14*dx), ShpY+5+(i*14*dy))
EndFor
EndSub