ça marche très bien sous windows, mais pas sous linux (testé avec 4.10 et 4.20beta) vous avez une idée pourquoi ?
il faut un répertoire appeler "Images" et y placer une image Jpeg
Code : Tout sélectionner
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse()=0 Or InitSound()=0
MessageRequester("Error", "Can't open DirectX 7 or later", 0)
End
EndIf
Global ScreenWidth=800
Global ScreenHeight=480
If OpenWindow(0,0,0,ScreenWidth,ScreenHeight,"Maxime Puzzle",#PB_Window_SystemMenu|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
If OpenWindowedScreen(WindowID(0),0,0,ScreenWidth,ScreenHeight,0,0,0)
UseJPEGImageDecoder()
UseOGGSoundDecoder()
;LoadSound(0,"./Sounds/claps.ogg")
Else
MessageRequester("Error", "Can't open windowed screen!", 0)
End
EndIf
EndIf
Structure Param
DivX.l
DivY.l
PieceWidth.l
PieceHeight.l
EndStructure
Global Param.Param
Global Dim Puzzle.l(1)
Procedure NewImage()
ExamineDirectory(0,"./Images/","*.jpg")
NewList mylist.s()
Repeat
file=NextDirectoryEntry(0)
If file=1
AddElement(mylist.s())
mylist.s()=DirectoryEntryName(0)
EndIf
Until file=0
SelectElement(mylist.s(),Random(CountList(mylist.s())-1))
Names.s=mylist()
LoadImage(0,"Images/"+Names,#PB_Sprite_Memory)
EndProcedure
Procedure Cut(X.l,Y.l)
Param\DivX=X
Param\DivY=Y
StartDrawing(ScreenOutput())
DrawImage(ImageID(0),0,0,ScreenWidth,ScreenHeight)
StopDrawing()
Param\PieceWidth=ScreenWidth/Param\DivX
Param\PieceHeight=ScreenHeight/Param\DivY
sp=0
For y=0 To Param\DivY-1
For x=0 To Param\DivX-1
sp+1
GrabSprite(sp, x*Param\PieceWidth, y*Param\PieceHeight, Param\PieceWidth, Param\PieceHeight)
Next
Next
ReDim Puzzle.l(Param\DivX*Param\DivY)
EndProcedure
Procedure ShuffleTable()
Nb=Param\DivX*Param\DivY
ReDim Puzzle(Nb)
For Index = 1 To Nb
Puzzle(Index) = Index
Next
For Index = 1 To Nb
IndexB = Random(Nb-1)+1
If IndexB <> Index
Swap Puzzle(Index), Puzzle(IndexB)
EndIf
Next
EndProcedure
Procedure Finish()
Nb=Param\DivX*Param\DivY
Ok=0
For z=1 To Nb
If Puzzle(z)=z
Ok+1
EndIf
Next
If Ok=Nb:
ProcedureReturn 1
Else
ProcedureReturn 0
EndIf
EndProcedure
Procedure NextPicture()
NewImage()
Cut(4,4)
ShuffleTable()
EndProcedure
NextPicture()
Mode=0
Repeat
Event.l = WindowEvent()
If Event = #PB_Event_Gadget
Else
; do the sprite & screen stuff here...
FlipBuffers() ; Inverse the buffers (the back become the front (visible)... and we can do the rendering on the back
ExamineKeyboard()
ExamineMouse()
If KeyboardPushed(#PB_Key_N)
NewImage()
Cut(4,4)
ShuffleTable()
EndIf
If KeyboardPushed(#PB_Key_Return)
ShuffleTable()
EndIf
If KeyboardPushed(#PB_Key_Space)
Nb=Param\DivX*Param\DivY
For z=1 To Nb
Puzzle(z)=z
Next
EndIf
; Clear the screen and draw our sprites
ClearScreen(RGB(0,0,0))
sp=0
For y=0 To Param\DivY-1
For x=0 To Param\DivX-1
sp+1
If IsSprite(Puzzle(sp))
DisplaySprite(Puzzle(sp), x*Param\PieceWidth, y*Param\PieceHeight)
EndIf
Next
Next
StartDrawing(ScreenOutput())
If Mode<3
For x=0 To Param\DivX-1
Line(x*Param\PieceWidth,0,0,ScreenHeight,0)
Next
For y=0 To Param\DivY-1
Line(0,y*Param\PieceHeight,ScreenWidth,0,0)
Next
EndIf
Circle(MouseX(),MouseY(),5,RGB(255,0,0))
StopDrawing()
If Take>0
DisplaySprite(Puzzle(Take),MouseX()-DeltaX,MouseY()-DeltaY)
EndIf
If MouseButton(#PB_MouseButton_Left) And Mode=0
Take=((MouseX()/Param\PieceWidth)+MouseY()/Param\PieceHeight*Param\DivX)+1
Mode=1
DeltaX=MouseX()-Int(MouseX()/Param\PieceWidth)*Param\PieceWidth
DeltaY=MouseY()-Int(MouseY()/Param\PieceHeight)*Param\PieceHeight
ElseIf MouseButton(#PB_MouseButton_Left)=0 And Mode=1
Swap Puzzle(Take), Puzzle(((MouseX()/Param\PieceWidth)+MouseY()/Param\PieceHeight*Param\DivX)+1)
Take=0
Mode=0
If Finish()
Time=ElapsedMilliseconds()
;PlaySound(0)
Mode=3
EndIf
ElseIf Mode=3
If ElapsedMilliseconds()-Time>3000
Mode=0
NextPicture()
EndIf
EndIf
Delay(1)
EndIf
Until Event = #PB_Event_CloseWindow Or KeyboardPushed(#PB_Key_Escape)
End