voilà de quoi est capable purebasic, alors que je l'ai exploré uniquement en surface
Code : Tout sélectionner
; ------------------------------------------------------------
; droit dans le mur - 2007 - source purebasic 4. et des poussières
;
; Collision sans fonction.
;
; France - Toulouse - H. Philippe - pseudo: beauregard
; ------------------------------------------------------------
;UsePNGImageDecoder () ; oui, toi t'es obligatoire.
If InitMouse ()=0 Or InitSprite ()=0 Or InitKeyboard ()=0 Or InitSprite3D ()=0
MessageRequester ( "Error" , "Can't open DirectX 7 or later" , 0)
End
EndIf
Enumeration ; ici, on donne un petit nom à nos sprites( non, chuis pas un numéro !):
; tout en sprites3D, même le décor (pourquoi s'embéter ?):
#fondA
#fondA3D
; dirigé par le joueur durand la phase de jeu:
#champi ;
#champi3D
; bloc solide:
#blocs
#blocs3D
; permet au progammeur de repèrer les positions des divers objets qu'il teste à l'écran:
#repere
#repere3D
EndEnumeration
;Global page.w=0,niveau.w=1
;Global placemX=512,placemY=384
; chamcoll-> =1 collision à droite, =2 collision à gauche.
Global champX.w, champY.w,champsol.w,chamcoll.w
Global nbrebs
Structure balle
id.l
x.w
Y.w
sensx.l
sensy.l
sr.w
attract.w
EndStructure
Global NewList bs.balle(); bloc solide, c'est à dire infranchissable des 4 côtés.
Declare Fchampignon()
Declare Fcloneblocs()
; Si votre PC ne peut pas afficher une haute résoution résolution en 32bit, Alors arrêt du programme.
;If OpenScreen (1440, 900, 32, "droit dans le mur" )=0
If OpenScreen (1024, 768, 32, "droit dans le mur" )=0
MessageRequester ( "Error" , "Can't open a 1024*768 - 32 bit screen !" , 0)
End
EndIf
; fond:
CreateSprite ( #fondA ,64,64, #PB_Sprite_Texture )
StartDrawing ( SpriteOutput ( #fondA ))
BackColor ( RGB (0,0,0))
Box (0,0, 64, 64, RGB (108,119,206))
Box (8,8, 56, 56, RGB (26,45,190))
StopDrawing ()
CreateSprite3D ( #fondA3D , #fondA ) ; osons les amis, osons !
; °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
; champignon:
CreateSprite ( #champi ,64,64, #PB_Sprite_Texture ) ; objet dirigé par le joueur.
StartDrawing ( SpriteOutput ( #champi ))
BackColor ( RGB (0,0,0))
Box (0,0, 128, 128, RGB (255,255,255))
StopDrawing ()
CreateSprite3D ( #champi3D , #champi )
; decor blocsolide
CreateSprite ( #blocs ,64,64, #PB_Sprite_Texture ) ; objet intéractif (mur, sol, plafond).
StartDrawing ( SpriteOutput ( #blocs ))
BackColor ( RGB (0,0,0))
Box (0,0, 128, 128, RGB (200,115,115))
StopDrawing ()
CreateSprite3D ( #blocs3D , #blocs )
; repere ( utilisé uniquement par le programmeur):
CreateSprite ( #repere ,4,4, #PB_Sprite_Texture )
StartDrawing ( SpriteOutput ( #repere ))
BackColor ( RGB (0,0,0))
Box (0,0, 4, 4, RGB (255,255,255))
StopDrawing ()
CreateSprite3D ( #repere3D , #repere )
Global zutA,zutB,zutC ; pour repère la variable qui n'aurait la bonne valeur.
;MouseLocate(449,62)
; ******************************************************************************************************
Repeat ; Boucle principale
; ******************************************************************************************************
ExamineMouse():ExamineKeyboard ()
Start3D ()
For a=0 To 15 ; 1024/64=16
For b=0 To 11 ; 768/64=12
DisplaySprite3D(#fondA3D, a*64, b*64) ; 16*12
Next
Next
; **********************************************************************************************
; fabrication bloc solide:
If nbrebs<1:nbrebs+1:Fcloneblocs():EndIf
; Affichage clone bloc solide si existe:
ForEach bs()
; chamcoll -> =1 collision à droite, =2 collision à gauche.
If champX+64>bs()\x-1 And champX+64<bs()\x+16
If (champY+32>bs()\y+15 And champY+32<bs()\y+49)
chamcoll=1
EndIf
EndIf
If champX>bs()\x+48 And champX<bs()\x+65
If (champY+32>bs()\y+15 And champY+32<bs()\y+49)
chamcoll=2
EndIf
EndIf
; champsol -> =1 collision avec la partie haute du bloc solide:
If (champX>bs()\x-1 And champX<bs()\x+65) Or (champX+64>bs()\x-1 And champX+64<bs()\x+65)
If (champY+64>bs()\y-1 And champY+64<bs()\y+16)
champsol=1
EndIf
EndIf
DisplaySprite3D ( bs()\id , bs()\x, bs()\y, 255)
Next
; Contrôlé par le joueur:
If depart=0:depart=1:champX+512:champY+64:EndIf
Fchampignon()
Stop3D ()
; ligne de test afin de connaître la valeur des variables:
StartDrawing ( ScreenOutput ())
DrawingMode (1)
FrontColor ( RGB (255,255,255))
chamcoll$= Str (chamcoll)
champsol$= Str (champsol)
zutB$= Str (zutB)
zutC$= Str (zutC)
DrawText (50,1+20, "chamcoll: " +chamcoll$)
DrawText (50,1+40, "champsol: " +champsol$)
DrawText (50,1+60, "testX: " +testX$)
DrawText (50,1+80, "testY: " +testY$)
DrawText (50,1+260, "zutB: " +zutB$);:zutB=0
DrawText (50,1+280, "zutC: " +zutC$);:zutC=0
DrawText (350,20, "appuyez sur la touche R pour remise à 0 du code")
StopDrawing ()
Gosub fps ; nombre d'image par seconde.
If KeyboardPushed ( #PB_Key_R ):champY=0:EndIf ; reset
; °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
; remise à 0 des variables avertissant d'une collision:
chamcoll=0:champsol=0;
; °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
FlipBuffers (): ClearScreen ( RGB (0,0,0));FlipBuffers (60)
; ******************************************************************************************************
Until KeyboardPushed ( #PB_Key_Escape ): End ; fin de la boucle principale (appuyez sur la touche Esc)
; ******************************************************************************************************
fps:
If Val ( FormatDate ( "%ss" , Date ()))=sek ; regardez pas là, c'est trop compliqué. Arrêtez j'vous dis! Bon ben, je
; vous aurez prévenu...
fps+1
Else
FPS$= Str (fps)
fps=0
EndIf
sek= Val ( FormatDate ( "%ss" , Date ()))
StartDrawing ( ScreenOutput ())
DrawingMode (1)
FrontColor ( RGB (255,255,255))
DrawText (1,1, "FPS: " +FPS$)
StopDrawing ()
Return
; ***********************************************************************************************
; ********************************* ici commence les procedures *********************************
; ***********************************************************************************************
Procedure Fcloneblocs() ; 64*64 fabrication clone bloc solide:
; placement clone bloc solide:
; faisons le sol:
For a=0 To 15
LastElement(bs())
AddElement(bs())
bs()\id=#blocs3D
bs()\x=a*64:bs()\y=704
Next
; faisons 2 autres blocs ( mur):
LastElement(bs()):AddElement(bs())
bs()\id=#blocs3D:bs()\x=0:bs()\y=640
LastElement(bs()):AddElement(bs())
bs()\id=#blocs3D:bs()\x=1024-64:bs()\y=640
; et faisont mumuse avec d'autres constructions...
LastElement(bs()):AddElement(bs())
bs()\id=#blocs3D:bs()\x=448:bs()\y=640
LastElement(bs()):AddElement(bs())
bs()\id=#blocs3D:bs()\x=512:bs()\y=640
LastElement(bs()):AddElement(bs())
bs()\id=#blocs3D:bs()\x=448:bs()\y=576
EndProcedure
Procedure Fchampignon() ; 64*64
; chamcoll-> =1 collision à droite, =2 collision à gauche.
If KeyboardPushed ( #PB_Key_Right ) And chamcoll<>1
champX+8;+8
EndIf
If KeyboardPushed ( #PB_Key_Left ) And chamcoll<>2
champX-8;-8
EndIf
If champsol=0
champY+4
EndIf
DisplaySprite3D ( #champi3D , champX, champY, 255)
EndProcedure