gambas-source-code/app/examples/Games/StarField/.src/MMain.module
Benoît Minisini c6a9cd69c2 [EXAMPLES]
* NEW: Add examples again. I hope correctly this time.


git-svn-id: svn://localhost/gambas/trunk@6726 867c0c6c-44f3-4631-809d-bfa615b0a4ec
2014-12-12 19:58:52 +00:00

81 lines
1.7 KiB
Text

' Gambas module file
Public screen As New Window As "screen"
' structure pour stocker les coordonnées d'une étoile
' ainsi que sa vitesse
Public Struct Star
x As Integer
y As Integer
speed As Integer
End Struct
' notre champ étoilé
Private Starfield As New Star[]
' le logo
Private img As Image
Private rotation As Integer = 0
Public Sub Main()
Dim i As Integer
Dim stars As Star
Randomize
' Ouverture de notre fenêtre, on limite
' a 60 images par secondes maximum
With screen
.Framerate = 60
.Resizable = False
.Show()
End With
img = Image.Load("logo.png")
' Remplissons notre champ étoilé
For i = 0 To 100
Stars = New Star
Stars.x = Int(Rnd(Screen.Width))
Stars.y = Int(Rnd(screen.Height))
Stars.speed = Int(Rnd(1, 4))
Starfield.Push(stars)
Next
End
Public Sub screen_draw()
Dim Stars As Star
screen.Clear()
For Each Stars In Starfield
' Plus une étoile est rapide (proche), plus elle est lumineuse
Draw.ForeColor = &h444444& * Stars.speed
' Plus elle est proche plus sa trace est longue
Draw.Line(Stars.x, Stars.y, Stars.x + (Stars.speed * 2), stars.y)
Stars.x += Stars.speed
' Notre étoile est hors de l'écran
If Stars.x > screen.Width Then
Stars.x = 0
Stars.y = Int(Rnd(screen.Height))
Stars.speed = Int(Rnd(1, 4))
Endif
Next
' Attention la couleur affecte aussi les images !
Draw.ForeColor = &hFFFFFF&
Draw.Text(Screen.Framerate, 10, Screen.Height - 40)
' on applique la rotation et on affiche le logo
Draw.Rotate(rotation)
Draw.Image(img, Screen.Width - 128, Screen.Height - 128)
' rotation de 0 a 360 :-)
rotation = (rotation + 1) Mod 360
End