Voilà un peu un code léger en ressources (j'ai mis les commandes de flèche du jeu de tonton) qui donne une idée des déplacements du fond d'écran. Maintenant, je n'ai hélas pas envie ni le temps suffisant pour faire ou refaire un jeu actuellement.
(Et, toujours la même : ne pas oublier Directx9 dans l'option sous-sytème du menu des options de compilation)
Bon courage à vous.
Code : Tout sélectionner
;PB 4.30 le 10/01/09 (Comtois)
;20/03/09 Test défilement 2D (Ollivier)
Global Full.I = 1 ; 1 = FullScreen, c'est comme la boîte
; auto : ça marche tout seul...
InitEngine3D()
InitSprite()
InitKeyboard()
#R2D = 180.0 / #PI
;Pour enregistrer au format PNG
UsePNGImageEncoder()
ExamineDesktops()
EcrL = DesktopWidth(0)
EcrH = DesktopHeight(0)
EcrP = DesktopDepth(0)
If Full
OpenScreen(EcrL, EcrH, EcrP, "Tutoriel 3D")
Else
OpenWindow(0, 0, 0, EcrL, EcrH, "DX9ParalX", $80000000)
OpenWindowedScreen(WindowID(0), 0, 0, EcrL, EcrH, 0, 0, 0)
EndIf
;Pour charger une texture, mesh, entity , etc, indiquer le chemin où se trouvent ces médias
Add3DArchive("/", #PB_3DArchive_FileSystem)
Global ScrollX.F
Global ScrollY.F
Global AngleTeta.F
Global Coef.F
Global Angle.f, Vitesse.f
;-Mesh
#Mesh = 0
CreateMesh(#Mesh, 100)
Options = #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_Color | #PB_Mesh_UVCoordinate
SetMeshData(#Mesh, Options , ?Sommets, 24)
SetMeshData(#Mesh, #PB_Mesh_Face, ?Triangles, 12)
;-Textures
#Texture = 0
CreateImage(#Texture, 64, 64)
;Remplissage de la texture en blanc
StartDrawing(ImageOutput(#Texture))
Box(0, 0, ImageWidth(#Texture), ImageHeight(#Texture), $FFFFFF)
DrawingMode(#PB_2DDrawing_Outlined) ; Pour tracer le contour
Box(0, 0, ImageWidth(#Texture), ImageHeight(#Texture), 0)
StopDrawing()
;Enregistre l'image dans le même répertoire que le code source
Fichier$="TextureDVP1.PNG"
SaveImage(#Texture, Fichier$, #PB_ImagePlugin_PNG)
;Maintenant on peut charger notre texture
LoadTexture(#Texture, Fichier$)
#TextureSol = 1
CreateImage(#TextureSol, 512, 512)
;Remplissage de la texture en blanc
StartDrawing(ImageOutput(#TextureSol))
Box(0, 0, ImageWidth(#TextureSol), ImageHeight(#TextureSol), $0)
For I = 0 To 500
R = Random(127) + 128
X = Random(511)
Y = Random(511)
Plot(X, Y, RGB(R, R, R) )
For D = 1 To 5
C = RGB(R / 1 << D, R / 1 << D, R / 1 << D)
Line((X - D << 1) & 511, (Y) & 511, -2, 1, C)
Line((X + D << 1) & 511, (Y) & 511, 2, 1, C)
Line((X) & 511, (Y - D << 1) & 511, 1, -2, C)
Line((X) & 511, (Y + D << 1) & 511, 1, 2, C)
For DX = -1 To 1 Step 2
For DY = -1 To 1 Step 2
Plot((X + DX * D) & 511, (Y + DY * D) & 511, C)
Next DY
Next DX
Next D
Next I
StopDrawing()
;Enregistre l'image dans le même répertoire que le code source
Fichier$="TextureDVP2.PNG"
SaveImage(#TextureSol, Fichier$, #PB_ImagePlugin_PNG)
;Maintenant on peut charger notre texture
LoadTexture(#TextureSol, Fichier$)
;-Matière
#Matiere = 0
CreateMaterial(#Matiere, TextureID(#Texture))
#MatiereSol = 1
CreateMaterial(#MatiereSol, TextureID(#TextureSol))
For I = 1 To 3
AddMaterialLayer(#MatiereSol, TextureID(#TextureSol), #PB_Material_Replace)
Next I
;-Entity
#Entity = 0
CreateEntity(#Entity, MeshID(#Mesh), MaterialID(#Matiere))
ScaleEntity(#Entity, 10, 10, 10) ; Agrandi l'entity
EntityLocate(#Entity, 500, 5, 500)
#EntitySol = 1
CreateEntity(#EntitySol, MeshID(#Mesh), MaterialID(#MatiereSol))
ScaleEntity(#EntitySol, 1000, 2, 1000) ; Agrandi l'entity
EntityLocate(#EntitySol, 500, -50, 500)
;-Camera
#Camera = 0
CreateCamera(#Camera, 0, 0, 100, 100)
;-Light
;AmbientColor(RGB(55,55,55)) ; Réduit la lumière ambiante pour mieux voir les lumières
;#LightRouge = 0 : CreateLight(#LightRouge,RGB(255, 0, 0), 0, 500, 0)
;#LightBleue = 1 : CreateLight(#LightBleue,RGB(0, 0, 255), 0, 500, 1000)
;#LightVerte = 2 : CreateLight(#LightVerte,RGB(0, 255, 0), 1000, 500, 1000)
;- Sprite pour afficher l'aide
Procedure SpriteText(Text.S)
CreateSprite(64000, 256, 24)
StartDrawing(SpriteOutput(64000) )
DrawText(0, 0, Text, #White, #Black)
StopDrawing()
EndProcedure
;- Démarrage
CameraLocate(#Camera, 500, 500, 500)
RotateCamera(#Camera, 270, 270, 0)
Angle = #PI / 2.0
RotateEntity(#Entity, 0.0, 90.0, 0.0, PB_Absolute)
Repeat
Delay(1) ; On prévient Windows qu'on est cool
If Full
Delay(1)
Delay(1)
Delay(1)
Delay(1)
Delay(1)
Delay(1)
Delay(1)
Else
WindowEvent()
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up)
Vitesse + 0.0001
EndIf
Vitesse * 0.99
If KeyboardPushed(#PB_Key_Left)
Angle + 0.1
RotateEntity(#Entity, 0.0, Angle * #R2D, 0.0, PB_Absolute)
ElseIf KeyboardPushed(#PB_Key_Right)
Angle - 0.1
RotateEntity(#Entity, 0.0, Angle * #R2D, 0.0, PB_Absolute)
EndIf
EndIf
ScrollX + Cos(Angle) * Vitesse
ScrollY + Sin(Angle) * Vitesse
For I = 0 To 3
Coef = 1.0 / (1 + I)
ScrollMaterial(#MatiereSol, ScrollX / Coef, ScrollY / Coef, #PB_Material_Fixed, I)
Next I
RenderWorld()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End
;{ Définition du cube
DataSection
Sommets:
;Dessus 0 à 3
Data.f -0.2,0.5,-0.5
Data.f 0,1,0
Data.L 0
Data.f 0,0
Data.f 0.2,0.5,-0.5
Data.f 0,1,0
Data.L 0
Data.f 0,1
Data.f 0.2,0.5,0.5
Data.f 0,1,0
Data.L 0
Data.f 1,1
Data.f -0.2,0.5,0.5
Data.f 0,1,0
Data.L 0
Data.f 1,0
;Dessous 4 à 7
Data.f -0.5,-0.5,0.5
Data.f 0,-1,0
Data.l 0
Data.f 0,0
Data.f 0.5,-0.5,0.5
Data.f 0,-1,0
Data.L 0
Data.f 0,1
Data.f 0.5,-0.5,-0.5
Data.f 0,-1,0
Data.L 0
Data.f 1,1
Data.f -0.5,-0.5,-0.5
Data.f 0,-1,0
Data.L 0
Data.f 1,0
;Devant 8 à 11
Data.f -0.5,0.5,0.5
Data.f 0,0,1
Data.l 0
Data.f 0,0
Data.f 0.5,0.5,0.5
Data.f 0,0,1
Data.l 0
Data.f 0,1
Data.f 0.5,-0.5,0.5
Data.f 0,0,1
Data.l 0
Data.f 1,1
Data.f -0.5,-0.5,0.5
Data.f 0,0,1
Data.l 0
Data.f 1,0
;Derrière 12 à 15
Data.f 0.5,0.5,-0.5
Data.f 0,0,-1
Data.l 0
Data.f 0,0
Data.f -0.5,0.5,-0.5
Data.f 0,0,-1
Data.l 0
Data.f 0,1
Data.f -0.5,-0.5,-0.5
Data.f 0,0,-1
Data.l 0
Data.f 1,1
Data.f 0.5,-0.5,-0.5
Data.f 0,0,-1
Data.l 0
Data.f 1,0
;Cote gauche 16 à 19
Data.f -0.5,0.5,-0.5
Data.f -1,0,0
Data.l 0
Data.f 0,0
Data.f -0.5,0.5,0.5
Data.f -1,0,0
Data.l 0
Data.f 0,1
Data.f -0.5,-0.5,0.5
Data.f -1,0,0
Data.l 0
Data.f 1,1
Data.f -0.5,-0.5,-0.5
Data.f -1,0,0
Data.l 0
Data.f 1,0
;Cote droit 20 à 23
Data.f 0.5,0.5,0.5
Data.f 1,0,0
Data.l 0
Data.f 0,0
Data.f 0.5,0.5,-0.5
Data.f 1,0,0
Data.l 0
Data.f 0,1
Data.f 0.5,-0.5,-0.5
Data.f 1,0,0
Data.l 0
Data.f 1,1
Data.f 0.5,-0.5,0.5
Data.f 1,0,0
Data.l 0
Data.f 1,0
Triangles:
;Face en Haut
Data.w 2,1,0
Data.w 0,3,2
;Face en Bas
Data.w 6,5,4
Data.w 4,7,6
;Face Avant
Data.w 10,9,8
Data.w 8,11,10
;Face Arrière
Data.w 14,13,12
Data.w 12,15,14
;Face Gauche
Data.w 18,17,16
Data.w 16,19,18
;Face Droite
Data.w 22,21,20
Data.w 20,23,22
EndDataSection
;}