Alors essayez ce petit truc

http://partage.lsi-dev.com/Mouton.zip
Et ne mettez pas la souris sur le mouton, sinon, il se cache, c'est voulu
Voici le code, mais il faut les ressources du zip
Code : Tout sélectionner
; Auteur : Le Soldat Inconnu
; Version de PB : 4
;
; Explication du programme :
; Un petit mouton
#Ressource = "Ressources\"
Enumeration
; Menu
#Quitter
; Image
; #Mouton
; #Mouton_Corp
; #Mouton_TeteProfil
; #Mouton_OeilProfil
; #Mouton_TeteFace
; #Mouton_DentsFace
; #Mouton_LangueFace
; #Mouton_PatteAv1
; #Mouton_PatteAv2
; #Mouton_PatteAr1
; #Mouton_PatteAr2
EndEnumeration
Structure Structure_Image
x.l
y.l
id.l
id_Inversion.l
EndStructure
Structure Structure_Mouton
Mvt.l
Animation.l
x.l
y.l
Sens.l
Corp.Structure_Image
Tete_Animation.l
TeteProfil.Structure_Image
OeilProfil.Structure_Image
TeteFace.Structure_Image
DentsFace.Structure_Image
LangueFace.Structure_Image
PatteAv1.Structure_Image
PatteAv2.Structure_Image
PatteAr1.Structure_Image
PatteAr2.Structure_Image
EndStructure
Global Mouton.Structure_Mouton
Structure Structure_Animation
Frequence.l
Continuer.l
Duree.l
ClignerOeil.l
Special.l
EndStructure
Global NewList Animation.Structure_Animation(), Animation_Total
#Fenetre_H = 48
#Fenetre_L = 64
UsePNGImageDecoder()
Procedure Timer(hwnd.l, uMsg.l, idEvent.l, dwTime.l)
Select uMsg
Case #WM_TIMER
PostMessage_(hwnd, #WM_USER, idEvent, dwTime)
EndSelect
EndProcedure
Procedure SetWinTransparency(WinHandle.l, Transparency_Level.l)
If OpenLibrary(0, "user32.dll")
CallFunction(0, "SetLayeredWindowAttributes", WinHandle, 0, Transparency_Level, 2)
CloseLibrary(0)
EndIf
EndProcedure
Procedure Image(Fichier.s)
id = LoadImage(#PB_Any, #Ressource + Fichier)
If id = 0
MessageRequester("Erreur", "Impossible de charger l'image : " + Chr(10) + #Ressource + Fichier)
End
EndIf
ProcedureReturn id
EndProcedure
Procedure Deplace(*Position.Structure_Image, x, y)
*Position\x = x
*Position\y = y
EndProcedure
Procedure Retourne(*Image.Structure_Image)
id = *Image\id
*Image\id = *Image\id_Inversion
*Image\id_Inversion = id
EndProcedure
Procedure Mouton_Retourne()
Mouton\Sens * -1
Retourne(Mouton\Corp)
Retourne(Mouton\TeteProfil)
Retourne(Mouton\OeilProfil)
Retourne(Mouton\TeteFace)
Retourne(Mouton\LangueFace)
Retourne(Mouton\DentsFace)
Retourne(Mouton\PatteAv1)
Retourne(Mouton\PatteAv2)
Retourne(Mouton\PatteAr1)
Retourne(Mouton\PatteAr2)
EndProcedure
;{- Fenêtre
; Création de la fenêtre et de la GadgetList
If OpenWindow(0, -#Fenetre_L, 0, #Fenetre_L, #Fenetre_H, "Mouton", #PB_Window_BorderLess | #PB_Window_Invisible) = 0
End
EndIf
SetWindowLong_(WindowID(0), #GWL_EXSTYLE, GetWindowLong_(WindowID(0), #GWL_EXSTYLE) | #WS_EX_TOOLWINDOW | $00080000) ; choix de la barre d'outil réduite
StickyWindow(0, 1)
SetWinTransparency(WindowID(0), 255)
HideWindow(0, 0)
IconEx_LoadIconFile(#Ressource + "Mouton.ico")
Icone = IconEx_ExtractIcon(16)
IconEx_FreeIcon()
If AddSysTrayIcon(0, WindowID(0), Icone)
If CreatePopupImageMenu(0)
MenuItem(#Quitter, "Quitter", Icone)
Else
End
EndIf
Else
End
EndIf
;}
;{- Images
Mouton\Corp\id = Image("Corp.png")
Mouton\Corp\id_Inversion = ImageSymmetryV(ImageID(Mouton\Corp\id))
Mouton\TeteProfil\id = Image("Tete profil.png")
Mouton\TeteProfil\id_Inversion = ImageSymmetryV(ImageID(Mouton\TeteProfil\id))
Mouton\OeilProfil\id = Image("Oeil profil.png")
Mouton\OeilProfil\id_Inversion = ImageSymmetryV(ImageID(Mouton\OeilProfil\id))
Mouton\TeteFace\id = Image("Tete face.png")
Mouton\TeteFace\id_Inversion = ImageSymmetryV(ImageID(Mouton\TeteFace\id))
Mouton\DentsFace\id = Image("Dents face.png")
Mouton\DentsFace\id_Inversion = ImageSymmetryV(ImageID(Mouton\DentsFace\id))
Mouton\LangueFace\id = Image("Langue face.png")
Mouton\LangueFace\id_Inversion = ImageSymmetryV(ImageID(Mouton\LangueFace\id))
Mouton\PatteAv1\id = Image("Patte avant 1.png")
Mouton\PatteAv1\id_Inversion = ImageSymmetryV(ImageID(Mouton\PatteAv1\id))
Mouton\PatteAv2\id = Image("Patte avant 2.png")
Mouton\PatteAv2\id_Inversion = ImageSymmetryV(ImageID(Mouton\PatteAv2\id))
Mouton\PatteAr1\id = Image("Patte arriere 1.png")
Mouton\PatteAr1\id_Inversion = ImageSymmetryV(ImageID(Mouton\PatteAr1\id))
Mouton\PatteAr2\id = Image("Patte arriere 2.png")
Mouton\PatteAr2\id_Inversion = ImageSymmetryV(ImageID(Mouton\PatteAr2\id))
Mouton\Sens = 1
;}
;{- Animation
SetTimer_(WindowID(0), 1, 50, @Timer())
; Gère la chance d'avoir une animation
; Plus la valeur est grande et plus l'animation a de chance d'apparaitre
AddElement(Animation()) : Animation()\Frequence = 25 : Animation()\Continuer = 15 : Animation()\ClignerOeil = 50 ; Avancer
AddElement(Animation()) : Animation()\Frequence = 5 : Animation()\Continuer = 30 : Animation()\ClignerOeil = 10 ; Arrêt
AddElement(Animation()) : Animation()\Frequence = 5 : Animation()\Continuer = 10 ; Tire la langue
AddElement(Animation()) : Animation()\Frequence = 5 : Animation()\Continuer = 10 ; Sourire
AddElement(Animation()) : Animation()\Frequence = 3 : Animation()\Continuer = 300 ; Coucher
AddElement(Animation()) : Animation()\Frequence = 15 : Animation()\Continuer = 8 : Animation()\ClignerOeil = 50 : Animation()\Special = 20 ; Saut
Animation_Total = 0
ForEach Animation()
Animation_Total + Animation()\Frequence
Next
;}
;{ Ecran
ExamineDesktops()
Ecran_Largeur = DesktopWidth(0)
Ecran_Hauteur = DesktopHeight(0)
SystemParametersInfo_(#SPI_GETWORKAREA, 0, @Ecran_Zone.RECT, 0)
Mouton\x = -#Fenetre_L
Mouton\y = Ecran_Zone\bottom - #Fenetre_H
DC = GetDC_(0)
;}
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Menu
Select EventMenu() ; Menus
Case #Quitter
Event = #PB_Event_CloseWindow
EndSelect
Case #PB_Event_Gadget
Select EventGadget() ; Gadgets
EndSelect
Case #PB_Event_SysTray
Select EventType()
Case #PB_EventType_LeftClick, #PB_EventType_RightClick
DisplayPopupMenu(0, WindowID(0))
EndSelect
Case #WM_USER
If DesktopMouseX() >= WindowX(0) And DesktopMouseX() < WindowX(0) + #Fenetre_L And DesktopMouseY() >= WindowY(0) And DesktopMouseY() < WindowY(0) + #Fenetre_H
HideWindow(0, 1)
Else
HideWindow(0, 0)
EndIf
;/ Mouton
;{- Choix de l'animation
If Mouton\Animation = 0
If Mouton\x < 0 Or Mouton\x > Ecran_Largeur - #Fenetre_L
Mouton\Mvt = 0 ; Si on est en dehors de l'écran, on marche
Else
Sauvegarde_Mvt = Mouton\Mvt
Repeat
x = Random(Animation_Total - 1) + 1
xx = 0
ForEach Animation()
xx + Animation()\Frequence
If xx > x
Mouton\Mvt = ListIndex(Animation())
Break
EndIf
Next
Until Mouton\Mvt <> Sauvegarde_Mvt
EndIf
Animation()\Duree = 0
; On initialise la position du mouton
ClignerOeil = 0 ; On ouvre l'oeil, finit de cligner, on change d'animation
Mouton\Tete_Animation = 0 ; tete droite
Deplace(Mouton\Corp, 0, 0)
Deplace(Mouton\TeteProfil, 0, 0)
Deplace(Mouton\TeteFace, 0, 0)
Deplace(Mouton\DentsFace, 0, 0)
Deplace(Mouton\LangueFace, 0, 0)
Deplace(Mouton\PatteAv1, 0, 0)
Deplace(Mouton\PatteAv2, 0, 0)
Deplace(Mouton\PatteAr1, 0, 0)
Deplace(Mouton\PatteAr2, 0, 0)
EndIf
;}
; On gère l'animation du mouton
Mouton\Animation + 1
SelectElement(Animation(), Mouton\Mvt)
;{- Cligner de l'oeil
; Pour faire cligner de l'oeil le mouton
If ClignerOeil > 0
ClignerOeil - 1
Select ClignerOeil
Case 2
Mouton\Tete_Animation = 1
Case 0
Mouton\Tete_Animation = 0
EndSelect
ElseIf Animation()\ClignerOeil > 1
ClignerOeil = Random(Animation()\ClignerOeil) + 10
EndIf
;}
Select Mouton\Mvt
Case 0
;{- On avance
Vitesse = 2
HauteurPied = 2
Mouton\x + Vitesse * Mouton\Sens
If Mouton\Animation = 5 ; Pour revenir au départ de l'animation
Mouton\Animation = 1
EndIf
Select Mouton\Animation
Case 1
Deplace(Mouton\TeteProfil, 0, 0)
Deplace(Mouton\PatteAv1, -Vitesse, 0)
Deplace(Mouton\PatteAv2, Vitesse, 0)
Deplace(Mouton\PatteAr1, Vitesse, 0)
Deplace(Mouton\PatteAr2, -Vitesse, 0)
Case 2
Deplace(Mouton\TeteProfil, 0, 1)
Deplace(Mouton\PatteAv1, 0, -HauteurPied)
Deplace(Mouton\PatteAv2, 0, 0)
Deplace(Mouton\PatteAr1, 0, 0)
Deplace(Mouton\PatteAr2, 0, -HauteurPied)
Case 3
Deplace(Mouton\PatteAv1, Vitesse, 0)
Deplace(Mouton\PatteAv2, -Vitesse, 0)
Deplace(Mouton\PatteAr1, -Vitesse, 0)
Deplace(Mouton\PatteAr2, Vitesse, 0)
Case 4
Deplace(Mouton\TeteProfil, 0, 0)
Deplace(Mouton\PatteAv1, 0, 0)
Deplace(Mouton\PatteAv2, 0, -HauteurPied)
Deplace(Mouton\PatteAr1, 0, -HauteurPied)
Deplace(Mouton\PatteAr2, 0, 0)
If Random(Animation()\Continuer) = 0
Mouton\Animation = 0
EndIf
EndSelect
;}
Case 1
;{- Le mouton s'arrête
If Animation()\Duree = 0
Animation()\Duree = Random(Animation()\Continuer) + 10
EndIf
If Mouton\Animation = Animation()\Duree
Mouton\Animation = 0
EndIf
;}
Case 2
;{- Tire la langue
If Animation()\Duree = 0
Animation()\Duree = Random(Animation()\Continuer) + 10
EndIf
Select Mouton\Animation
Case 1
Mouton\Tete_Animation = 10
Case 2, Animation()\Duree + 2
Mouton\Tete_Animation = 12
Deplace(Mouton\LangueFace, 0, -3)
Case 3, Animation()\Duree + 1
Deplace(Mouton\LangueFace, 0, -2)
Case 4, Animation()\Duree
Deplace(Mouton\LangueFace, 0, -1)
Case 5
Deplace(Mouton\LangueFace, 0, 0)
Case Animation()\Duree + 3
Mouton\Tete_Animation = 10
Mouton\Animation = 0
EndSelect
;}
Case 3
;{- Sourire
Mouton\Tete_Animation = 11
If Animation()\Duree = 0
Animation()\Duree = Random(Animation()\Continuer) + 10
EndIf
Select Mouton\Animation
Case 1
Deplace(Mouton\DentsFace, 0, -2)
Case 2, Animation()\Duree
Deplace(Mouton\DentsFace, 0, -1)
Case 3
Deplace(Mouton\DentsFace, 0, 0)
Case Animation()\Duree + 1
Mouton\Tete_Animation = 10
Mouton\Animation = 0
EndSelect
;}
Case 4
;{- Coucher
If Animation()\Duree = 0
Coucher = 0
Animation()\Duree = Random(Animation()\Continuer) + 30
EndIf
Select Mouton\Animation
Case 1, Animation()\Duree + 1
Deplace(Mouton\TeteProfil, 0, 1)
Case 2, Animation()\Duree
Deplace(Mouton\TeteProfil, 0, 2)
Case 3 To 15
Coucher + 1
Mouton\Tete_Animation = 1
Deplace(Mouton\TeteProfil, -1, 3)
Deplace(Mouton\Corp, 0, Coucher)
Case Animation()\Duree + 2 To Animation()\Duree + 14
Coucher - 1
Mouton\Tete_Animation = 0
Deplace(Mouton\TeteProfil, 0, 0)
Deplace(Mouton\Corp, 0, Coucher)
Case Animation()\Duree + 15
Deplace(Mouton\Corp, 0, 0)
Mouton\Animation = 0
EndSelect
;}
Case 5
;{- Saut
Vitesse = 3
If Mouton\Animation <= 1
Mouton\Animation = 1
Select Random(Animation()\Special)
Case 0, 1
Animation()\Duree = 15
Case 2
Animation()\Duree = 20
Default
Animation()\Duree = 10
EndSelect
Saut_Y = Mouton\y
EndIf
Select Mouton\Animation
Case 1 ; Prise d'élan
Deplace(Mouton\Corp, 1, 1)
Case 2
Deplace(Mouton\Corp, 2, 2)
Case 3
Deplace(Mouton\Corp, 2, 3)
Case 4
Deplace(Mouton\Corp, 2, 4)
Saut_Depart = Mouton\Animation
Saut_Corp = Mouton\Corp\y
Default ; Début du saut
Vitesse = 4
Mouton\x + (Vitesse - Mouton\Corp\x) * Mouton\Sens
x = (Mouton\Animation - Saut_Depart) * Vitesse
y = -Animation()\Duree / 3 * x * x / (Animation()\Duree * Vitesse) + Animation()\Duree / 3 * x ; Equation du saut
If y <= Saut_Corp And Mouton\Corp\y <> 0 ; On tend les pattes
Deplace(Mouton\Corp, 0, Saut_Corp - y)
Else ; On décolle
Deplace(Mouton\Corp, 0, 0)
; on rentre les pattes
If Mouton\y >= Saut_Y - y - Saut_Corp
If Saut_RentrePatte < 4
Saut_RentrePatte + 1
EndIf
Else
If Saut_RentrePatte > 0
Saut_RentrePatte - 1
EndIf
EndIf
Deplace(Mouton\PatteAv1, -Saut_RentrePatte, -Saut_RentrePatte / 2)
Deplace(Mouton\PatteAv2, -Saut_RentrePatte, -Saut_RentrePatte / 2)
Deplace(Mouton\PatteAr1, -Saut_RentrePatte / 2, 0)
Deplace(Mouton\PatteAr2, -Saut_RentrePatte / 2, 0)
; On monte
Mouton\y = Saut_Y - y - Saut_Corp
EndIf
If Mouton\y >= Saut_Y
Mouton\y = Saut_Y
If Random(Animation()\Continuer) = 0
Mouton\Animation = 0
Else
Mouton\Animation = -1
EndIf
EndIf
EndSelect
;}
EndSelect
;{- On dessine le mouton
If Mouton\x > Ecran_Largeur + #Fenetre_L ; Si on sort de l'écran
If Random(1) = 0
Mouton\x = -#Fenetre_L
Else
Mouton_Retourne()
Mouton\x = Ecran_Largeur
EndIf
EndIf
If Mouton\x < -#Fenetre_L
If Random(1) = 0
Mouton_Retourne()
Mouton\x = -#Fenetre_L
Else
Mouton\x = Ecran_Largeur
EndIf
EndIf
Dessin = StartDrawing(WindowOutput(0))
If Dessin
Box(0, 0, #Fenetre_L, #Fenetre_H, $000000)
BitBlt_(Dessin, 0, 0, #Fenetre_L, #Fenetre_H, DC, Mouton\x, Mouton\y, #SRCPAINT)
DrawAlphaImage(ImageID(Mouton\PatteAv1\id), Mouton\PatteAv1\x * Mouton\Sens, Mouton\PatteAv1\y)
DrawAlphaImage(ImageID(Mouton\PatteAv2\id), Mouton\PatteAv2\x * Mouton\Sens, Mouton\PatteAv2\y)
DrawAlphaImage(ImageID(Mouton\PatteAr1\id), Mouton\PatteAr1\x * Mouton\Sens, Mouton\PatteAr1\y)
DrawAlphaImage(ImageID(Mouton\PatteAr2\id), Mouton\PatteAr2\x * Mouton\Sens, Mouton\PatteAr2\y)
DrawAlphaImage(ImageID(Mouton\Corp\id), Mouton\Corp\x * Mouton\Sens, Mouton\Corp\y)
Select Mouton\Tete_Animation
Case 0, 1
DrawAlphaImage(ImageID(Mouton\TeteProfil\id), (Mouton\Corp\x + Mouton\TeteProfil\x) * Mouton\Sens, (Mouton\Corp\y + Mouton\TeteProfil\y))
If Mouton\Tete_Animation = 0
DrawAlphaImage(ImageID(Mouton\OeilProfil\id), (Mouton\Corp\x + Mouton\TeteProfil\x + Mouton\OeilProfil\x) * Mouton\Sens, (Mouton\Corp\y + Mouton\TeteProfil\y + Mouton\OeilProfil\y))
EndIf
Case 10, 11, 12
If Mouton\Tete_Animation = 11
DrawAlphaImage(ImageID(Mouton\DentsFace\id), (Mouton\Corp\x + Mouton\TeteFace\x + Mouton\DentsFace\x) * Mouton\Sens, (Mouton\Corp\y + Mouton\TeteFace\y + Mouton\DentsFace\y))
EndIf
If Mouton\Tete_Animation = 12
DrawAlphaImage(ImageID(Mouton\LangueFace\id), (Mouton\Corp\x + Mouton\TeteFace\x + Mouton\LangueFace\x) * Mouton\Sens, (Mouton\Corp\y + Mouton\TeteFace\y + Mouton\LangueFace\y))
EndIf
DrawAlphaImage(ImageID(Mouton\TeteFace\id), (Mouton\Corp\x + Mouton\TeteFace\x) * Mouton\Sens, (Mouton\Corp\y + Mouton\TeteFace\y))
EndSelect
;{ FPS
CompilerIf #PB_Compiler_Debugger
Ips_Cpt + 1
If Ips_Cpt >= Ips.f
Ips = Ips_Cpt * 1000 / (ElapsedMilliseconds() - Ips_Temps)
Ips_Cpt = 0
Ips_Temps = ElapsedMilliseconds()
EndIf
DrawText(0, 0, Str(Ips))
CompilerEndIf
;}
StopDrawing()
EndIf
ResizeWindow(0, Mouton\x, Mouton\y, #PB_Ignore, #PB_Ignore)
;}
EndSelect
Until Event = #PB_Event_CloseWindow
ReleaseDC_(0, DC)
End