Informática Elemental
Capacitación básica en Computación
Un juego simple e instructivo construido en Small Basic
‘ QJQ087 program listing
GraphicsWindow.BackgroundColor = “SteelBlue”
For i = 1 To 6
CorredorGif = ImageList.LoadImage(“http://ingenieriasimple.com/smallbasic/Corredor0″ + i + “.png”)
CorredorSh[i][1] = Shapes.AddImage(CorredorGif)
Shapes.Zoom(CorredorSh[i][1],0.5,0.5)
Shapes.HideShape(CorredorSh[i][1])
CorredorGif = ImageList.LoadImage(“http://ingenieriasimple.com/smallbasic/Corredor0″ + i + “r.png”)
CorredorSh[i][-1] = Shapes.AddImage(CorredorGif)
Shapes.Zoom(CorredorSh[i][-1],0.5,0.5)
Shapes.HideShape(CorredorSh[i][-1])
EndFor
Shapes.ShowShape(CorredorSh[1][1])
Corredor = 1
CorredorDir = 1
Terron = ImageList.LoadImage(“http://ingenieriasimple.com/smallbasic/TerronG.png”)
Timer.Interval = 160
Timer.Tick = CaeCorredor
GraphicsWindow.KeyDown = CambiaDireccionCorredor
For i = 1 To 4
Tierra[i] = Shapes.AddImage(Terron)
Shapes.HideShape(Tierra[i])
Shapes.Move(Tierra[i],Math.GetRandomNumber(GraphicsWindow.Width),GraphicsWindow.Height*(0.25*i))
Shapes.ShowShape(Tierra[i])
EndFor
Sub CaeCorredor
DeltaXCo = 15
DeltaYCo = 3
DeltaYTrra = 10
CurXCo = Shapes.GetLeft(CorredorSh[Corredor][1])
CurYCo = Shapes.GetTop(CorredorSh[Corredor][1])
For i = 1 To 4
CurXTrra = Shapes.GetLeft(Tierra[i])
CurYTrra = Shapes.GetTop(Tierra[i])
‘GraphicsWindow.DrawEllipse(CurXTrra+7,CurYTrra,52,5)
‘GraphicsWindow.DrawEllipse(CurXCo+25,CurYCo+90,35,5)
If Math.Abs(CurXTrra – CurXCo – 18) < 52 And Math.Abs(CurYTrra – CurYCo – 90) < 15 Then
DeltaYCo = – DeltaYTrra
EndIf
If CurYTrra <= -50 Then
Shapes.Move(Tierra[i],Math.GetRandomNumber(GraphicsWindow.Width),GraphicsWindow.Height)
EndIf
EndFor
Shapes.HideShape(CorredorSh[Corredor][1])
Shapes.HideShape(CorredorSh[Corredor][-1])
Corredor = Math.Remainder(Corredor,6) + 1
Shapes.ShowShape(CorredorSh[Corredor][CorredorDir])
For i = 1 To 6
If i = Corredor Then
Shapes.Animate(CorredorSh[i][1],CurXCo + DeltaXCo*CorredorDir,CurYCo + DeltaYCo,150)
Shapes.Animate(CorredorSh[i][-1],CurXCo + DeltaXCo*CorredorDir,CurYCo + DeltaYCo,150)
Else
Shapes.Move(CorredorSh[i][1],CurXCo + DeltaXCo*CorredorDir,CurYCo + DeltaYCo)
Shapes.Move(CorredorSh[i][-1],CurXCo + DeltaXCo*CorredorDir,CurYCo + DeltaYCo)
EndIf
EndFor
For i = 1 To 4
CurXTrra = Shapes.GetLeft(Tierra[i])
CurYTrra = Shapes.GetTop(Tierra[i])
Shapes.Animate(Tierra[i],CurXTrra,CurYTrra-DeltaYTrra,150)
EndFor
EndSub
Sub CambiaDireccionCorredor
If GraphicsWindow.LastKey = “Left” Then
CorredorDir = -1
ElseIf GraphicsWindow.LastKey = “Right” Then
CorredorDir = 1
EndIf
EndSub
%d bloggers like this:
No comments:
Post a Comment