Small Basic: Exemple - JetLag (fr-FR)
Voici un jeu vidéo où vous devez éviter des obstacles. Démarrer le jeu en appuyant sur la barre espace, se déplacer à gauche et à droite avec les touches fléchées.
Vous pouvez importer le programme avec l'ID WNF231
Code
Initialize()
While (GameState<>"End")
DoGameLoop()
EndWhile
Program.End()
Sub Initialize
'Initialisation des Variables
Score = 0
Direction = 0
GameState = "GameOver"
GameDelay = 100
'Initialisation de GraphicsWindow
GraphicsWindow.Show()
UpdateScore()
GraphicsWindow.Width = 640
GraphicsWindow.Height = 480
GraphicsWindow.BackgroundColor = "#000000"
GraphicsWindow.KeyDown = OnKeyDown
'Initialisation des Blocs
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = "#FFFFFF"
For Index=0 To 29
Temp = Shapes.AddRectangle(16,16)
Shapes.Move(Temp,0,Index*16)
Array.SetValue("Blocks",Index,Temp)
Array.SetValue("BlockPositions",Index,0)
EndFor
'Initialisation des Murs
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = "#0000FF"
Temp = Shapes.AddRectangle(16,480)
shapes.Move(Temp,624,0)
shapes.AddRectangle(16,480)
'Initialisation de Queue
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = "#FFFF00"
For Index = 0 To 4
Temp = Shapes.AddRectangle(16,16)
Shapes.Move(Temp,320,Index*16)
Array.SetValue("Tail",Index,Temp)
Array.SetValue("TailPositions",Index,20)
EndFor
'Initialsation de la Tête
GraphicsWindow.PenWidth = 0
GraphicsWindow.BrushColor = "#FF0000"
Temp = Shapes.AddRectangle(16,16)
Shapes.Move(Temp,320,5*16)
Array.SetValue("Tail",5,Temp)
Array.SetValue("TailPositions",5,20)
EndSub
Sub UpdateScore
GraphicsWindow.Title = "SBJetLag - Score: " + Score
EndSub
Sub OnKeyDown
Temp = GraphicsWindow.LastKey
If (GameState = "GameOver") Then
If (GraphicsWindow.LastKey = "Space") Then
StartGame()
Else
If (GraphicsWindow.LastKey = "Escape") Then
GameState = "End"
Else
If (GraphicsWindow.LastKey = "D1") Then
GameDelay = 100
GraphicsWindow.ShowMessage("Pause du Jeu définie à 100ms","Vitesse Modifiée!")
Else
If (GraphicsWindow.LastKey = "D2") Then
GameDelay = 200
GraphicsWindow.ShowMessage("Pause du Jeu définie à 200ms","Vitesse Modifiée!")
Else
If (GraphicsWindow.LastKey = "D3") Then
GameDelay = 300
GraphicsWindow.ShowMessage("Pause du Jeu définie à 300ms","Vitesse Modifiée!")
Else
If (GraphicsWindow.LastKey = "D4") Then
GameDelay = 400
GraphicsWindow.ShowMessage("Pause du Jeu définie à 400ms","Vitesse Modifiée!")
Else
If (GraphicsWindow.LastKey = "D5") Then
GameDelay = 500
GraphicsWindow.ShowMessage("Pause du Jeu définie à 500ms","Vitesse Modifiée!")
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
Else
If (GraphicsWindow.LastKey = "Left") Then
Direction = -1
Else
If (GraphicsWindow.LastKey = "Right") Then
Direction = 1
EndIf
EndIf
EndIf
EndSub
Sub StartGame
Score = 0
Direction = 1
UpdateScore()
For Index=0 To 29
Temp = Array.GetValue("Blocks",Index)
Shapes.Move(Temp,0,Index*16)
Array.SetValue("BlockPositions",Index,0)
EndFor
For Index=0 To 5
Temp = Array.GetValue("Tail",Index)
Shapes.Move(Temp,20*16,Index*16)
Array.SetValue("TailPositions",Index,20)
EndFor
GameState = "Play"
EndSub
Sub DoGameLoop
If (GameState = "Play") Then
Score = Score + 1
UpdateScore()
For Index=0 To 28
Temp = Array.GetValue("BlockPositions",Index+1)
Array.SetValue("BlockPositions",Index,Temp)
EndFor
Array.SetValue("BlockPositions",29,Math.GetRandomNumber(38))
For Index=0 To 29
Temp = Array.GetValue("Blocks",Index)
Shapes.Move(Temp,Array.GetValue("BlockPositions",Index)*16,Index*16)
EndFor
For Index=0 To 4
Temp = Array.GetValue("TailPositions",Index+1)
Array.SetValue("TailPositions",Index,Temp)
EndFor
Array.SetValue("TailPositions",5,Array.GetValue("TailPositions",5)+Direction)
For Index=0 To 5
Temp = Array.GetValue("Tail",Index)
Shapes.Move(Temp,Array.GetValue("TailPositions",Index)*16,Index*16)
EndFor
Temp = Array.GetValue("TailPositions",5)
If (Temp=0 Or Temp = 39 Or Temp = Array.GetValue("BlockPositions",5)) Then
GameState = "GameOver"
EndIf
Program.Delay(GameDelay)
EndIf
EndSub
Voir Aussi
Autres Langues
- Article original : Small Basic Sample: JetLag (en-US)