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,chamcoll.w,champsol.w,champlafond.w
Global champsaut.w,champsautH.w,champsautV.w,champsautM.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 (8,8,120))
LineXY (0, 0, 32, 0, RGB (88,8,88))
LineXY (32, 0, 0, 32, RGB (88,8,88))
LineXY (0, 32, 0, 0, RGB (88,8,88))
LineXY (64, 63, 48, 63, RGB (88,8,88))
LineXY (48, 63, 63, 48, RGB (88,8,88))
LineXY (63, 48, 63, 63, RGB (88,8,88))
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 (objet intéractif car il fait office à la fois de mur, sol et plafond).
CreateSprite ( #blocs ,64,64, #PB_Sprite_Texture )
StartDrawing ( SpriteOutput ( #blocs ))
BackColor ( RGB (0,0,0))
Box (0,0, 4, 64, RGB (0,104,0))
Box (4,0, 4, 64, RGB (16,152,16))
Box (8,0, 12, 64, RGB (0,208,0))
Box (20,0, 4, 64, RGB (152,248,168))
Box (24,0, 4, 64, RGB (248,248,248))
Box (28,0, 4, 64, RGB (152,248,168))
Box (32,0, 8, 64, RGB (80,232,80))
Box (36,0, 4, 64, RGB (0,208,0))
Box (40,0, 4, 64, RGB (16,152,16))
Box (44,0, 12, 64, RGB (0,208,0))
Box (56,0, 4, 64, RGB (16,152,16))
Box (60,0, 4, 64, RGB (0,104,0))
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)
tpb=255
; ******************************************************************************************************
Repeat ; Boucle principale
; ******************************************************************************************************
ExamineMouse():ExamineKeyboard ()
If KeyboardPushed ( #PB_Key_Add ) And tpb<255:tpb+1:EndIf
If KeyboardPushed ( #PB_Key_Subtract ) And tpb>5:tpb-1:EndIf
Start3D ()
For a=0 To 15 ; 1024/64=16
For b=0 To 11 ; 768/64=12
DisplaySprite3D(#fondA3D, a*64, b*64, 255) ; 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>bs()\y+15 And champY<bs()\y+49)
chamcoll=1
EndIf
EndIf
If champX+64>bs()\x-1 And champX+64<bs()\x+16
If (champY+16>bs()\y+15 And champY+16<bs()\y+49) Or (champY+48>bs()\y+15 And champY+48<bs()\y+49)
chamcoll=1
EndIf
EndIf
If champX>bs()\x+48 And champX<bs()\x+65
If (champY>bs()\y+15 And champY<bs()\y+49)
chamcoll=2
EndIf
EndIf
If champX>bs()\x+48 And champX<bs()\x+65
If (champY+16>bs()\y+15 And champY+16<bs()\y+49) Or (champY+48>bs()\y+15 And champY+48<bs()\y+49)
chamcoll=2
EndIf
EndIf
; champsol -> =1 collision avec la partie haute du bloc solide:
If (champX+8>bs()\x+7 And champX+8<bs()\x+57) Or (champX+56>bs()\x+7 And champX+56<bs()\x+57)
If (champY+64>bs()\y-1 And champY+64<bs()\y+16)
champsol=1:champY=(bs()\y-64)+1
EndIf
EndIf
; champlafond -> =1 collision avec le plafond
If (champX+8>bs()\x+7 And champX+8<bs()\x+57) Or (champX+56>bs()\x+7 And champX+56<bs()\x+57)
If champY>bs()\y+48 And champY<bs()\y+65
champlafond=1
EndIf
EndIf
DisplaySprite3D ( bs()\id , bs()\x, bs()\y, tpb)
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)
champlafond$= Str (champlafond)
tpb$= Str (tpb)
zutB$= Str (zutB)
zutC$= Str (zutC)
DrawText (50,1+20, "chamcoll: " +chamcoll$)
DrawText (50,1+40, "champsol: " +champsol$)
DrawText (50,1+60, "champlafond: " +champlafond$)
DrawText (50,1+100, "testX: " +testX$)
DrawText (50,1+120, "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")
DrawText (350,50, "appuyez sur la touche - ou + du pavé numérique ")
DrawText (365,70, "niveau transparence des blocs solides: " +tpb$)
StopDrawing ()
Gosub fps ; nombre d'image par seconde.
If KeyboardPushed ( #PB_Key_R ):champX=0:champY=0:depart=0:tpb=255:EndIf ; reset
; °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
; remise à 0 des variables avertissant d'une collision:
chamcoll=0:champsol=0:champlafond=0
; °°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°
;FlipBuffers (60)
FlipBuffers (): ClearScreen ( RGB (0,0,0))
; ******************************************************************************************************
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
; faisons un 1er plafond:
For a=0 To 3
LastElement(bs())
AddElement(bs())
bs()\id=#blocs3D
bs()\x=a*64:bs()\y=512
Next
; faisons un 2eme plafond:
For a=0 To 2
LastElement(bs())
AddElement(bs())
bs()\id=#blocs3D
bs()\x=(a*64)+192:bs()\y=320
Next
; faisons un 3eme plafond:
For a=0 To 1
LastElement(bs())
AddElement(bs())
bs()\id=#blocs3D
bs()\x=(a*64)+640:bs()\y=192
Next
; 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+6
If champX>1024-64:champX-6:EndIf
EndIf
If KeyboardPushed ( #PB_Key_Left ) And chamcoll<>2
champX-6
If champX<0:champX+6:EndIf
EndIf
If KeyboardPushed ( #PB_Key_Up ) And champsol=1 And champsaut=0:champsaut=1:EndIf
If champsaut=1
If champsautH<15 ;H comme hauteur du saut
champsautV=12:champsautH+1
EndIf
If champsautH+champsautM>14 And champsautH+champsautM<25 ; M comme modulable
champsautV=10:champsautM+1
EndIf
If champsautH+champsautM>24 And champsautH+champsautM<35
champsautV=8:champsautM+1
EndIf
champY=champY-champsautV; V comme vitesse de la montée lors du saut.
; si (joueur lache touche haut ET saut minimum effectué) OU hauteur saut maximal atteind, alors...
If (KeyboardPushed ( #PB_Key_Up )=0 And champsautH>14) Or champsautH+champsautM=35 Or champlafond=1
champsautH=0:champsautM=0:champsaut=0
EndIf
EndIf
If champsol=0 And champsaut=0 ; si champignon ne touche plus le sol ET pas de saut, alors...
champY+8
EndIf
DisplaySprite3D ( #champi3D , champX, champY, 255)
EndProcedure