Publié : ven. 28/sept./2007 23:04
@wolfjeremy
L’eau est gratuite, fallait mettre plus goûtes

L’eau est gratuite, fallait mettre plus goûtes

J’ai limité le nombre de goûtes à 9999.wolfjeremy a écrit :Ont peut mettre plus de goute ? MDR
Elles sont déjà à la vitesse max du CPU (delay(1))Frenchy Pilou a écrit :Il n'y a pas moyen d'accélérer le débit les gouttes?
;-------------
;-By Dobro sur une idée de Mytic ---
;-------------
InitSprite ()
InitMouse ()
InitKeyboard ()
Declare rapide_Point(x,Y)
Declare nouvel_goute(x.l,Y.l)
Declare gravite_collision()
Global taille=4 ; testez un autre chiffre<------------ zoom sur le phenomene
Structure goute
x.l
Y.l
pasy.l
pasx.l
EndStructure
Global NewList goute.goute()
Global largeur,hauteur
Enumeration
#crayon
#goute
#fond
#Window
EndEnumeration
;OpenWindow ( #Window ,1,1,1024,768, "ecran" , #PB_Window_BorderLess )
;OpenWindowedScreen ( WindowID ( #Window ),1,1,1024,768,1,0,0)
OpenScreen (1024,768,16, "Eau" )
;OpenScreen(1024,768,32,"Eau")
largeur = GetSystemMetrics_ ( #SM_CXSCREEN ): ;=largeur de l'ecran
hauteur = GetSystemMetrics_ ( #SM_CYSCREEN ): ;=hauteur de l'ecran
; ********** Fond ****************
CreateSprite ( #fond ,1024,768 )
; ********************************
; ********** crayon ****************
CreateSprite ( #crayon ,taille*2,taille*2)
StartDrawing ( SpriteOutput ( #crayon ))
Box (0,0,taille,taille, RGB (0,255,0))
StopDrawing ()
; ********************************
; ********** goute d'eau ****************
CreateSprite ( #goute ,taille,taille)
StartDrawing ( SpriteOutput ( #goute ))
For i = 0 To 5
DrawingMode ( #PB_2DDrawing_Outlined )
Circle (taille/2,taille/2,i, RGB ( Random (160), Random (160),220 + Random (30)))
Next i
DrawingMode ( #PB_2DDrawing_Default )
StopDrawing ()
; ********************************
Repeat
; Event = WindowEvent () ; mode fenetre
ExamineKeyboard ()
ExamineMouse ()
ClearScreen (0)
If KeyboardPushed ( #PB_Key_Escape )
End
EndIf
DisplaySprite ( #fond ,0,0)
x = MouseX ()
Y = MouseY ()
DisplaySprite ( #crayon ,x,Y)
If MouseButton ( #PB_MouseButton_Left )
StartDrawing ( SpriteOutput ( #fond ))
Circle (x,Y,taille, RGB (255,0,0))
StopDrawing ()
EndIf
If KeyboardPushed ( #PB_Key_Space )
StartDrawing ( SpriteOutput ( #fond ))
Circle (x,Y,taille, RGB (0,0,0))
StopDrawing ()
EndIf
If MouseButton ( #PB_MouseButton_Right )
;Y=0
; x=Random(largeur)
G=G+1
;Debug CountList (goute())
nouvel_goute(x,Y)
If G>1000 ; < ------------- seuil maximum
ClearList (goute())
G=0
EndIf
EndIf
gravite_collision()
Delay (1)
FlipBuffers ()
ForEver
End
Procedure nouvel_goute(x.l,Y.l)
AddElement (goute())
goute()\x=x
goute()\Y=Y
DisplaySprite ( #goute ,x,Y)
EndProcedure
Procedure gravite_collision()
ResetList (goute() )
While NextElement (goute())
StartDrawing ( ScreenOutput ())
If rapide_Point (goute()\x,goute()\Y+taille) = 0
goute()\Y+taille
Else
p = Random (1)
If p = 1
If rapide_Point (goute()\x+taille,goute()\Y)= 0
goute()\x+taille
Else
If rapide_Point (goute()\x-1,goute()\Y)= 0 :goute()\x-taille: EndIf
EndIf
Else
If rapide_Point (goute()\x-1,goute()\Y)=0
goute()\x-taille
Else
If rapide_Point (goute()\x+taille,goute()\Y)= 0 :goute()\x+taille: EndIf
EndIf
EndIf
EndIf
StopDrawing ()
; ******** test sorti en bas on remet en haut ! ************
If goute()\Y>= (hauteur-10)
goute()\Y=0
EndIf
; *******************************
; ******** test sorti a droite et gauche************
If (goute()\x>= (largeur-taille) Or goute()\x<=0)
goute()\pasx=0
goute()\pasy=0
EndIf
; *******************************
DisplayTransparentSprite ( #goute ,goute()\x,goute()\Y)
Wend
EndProcedure
Procedure rapide_Point(x,Y)
Select DrawingBufferPixelFormat ()
Case #PB_PixelFormat_16Bits : PF=2
color= PeekW ( DrawingBuffer () + (x * PF) + DrawingBufferPitch ()* ( Y ) )
Case #PB_PixelFormat_32Bits_RGB : PF=4
color= PeekL ( DrawingBuffer () + (x * PF) + DrawingBufferPitch ()* ( Y ) )
Case #PB_PixelFormat_32Bits_BGR : PF=4
color= PeekL ( DrawingBuffer () + (x * PF) + DrawingBufferPitch ()* ( Y ) )
Rouge= Red (color)
Vert= Green (color)
Bleu= Blue (color)
color= RGB (Bleu,Vert,Rouge)
EndSelect
ProcedureReturn color
EndProcedure
Code : Tout sélectionner
;-------------
;-By Dobro sur une idée de Mytic ---
;-------------
InitSprite ()
InitMouse ()
InitKeyboard ()
Declare rapide_Point(x,Y)
Declare nouvel_goute(x.l,Y.l)
Declare gravite_collision()
Global taille=10 ; testez un autre chiffre<------------ zoom sur le phenomene
Structure goute
x.l
Y.l
pasy.l
pasx.l
EndStructure
Global NewList goute.goute()
Global largeur,hauteur
Enumeration
#crayon
#goute
#fond
#Window
EndEnumeration
OpenWindow ( #Window ,1,1,1024,768, "ecran" , #PB_Window_BorderLess )
OpenWindowedScreen ( WindowID ( #Window ),1,1,1024,768,1,0,0)
;OpenScreen(1024,768,32,"Eau")
largeur = GetSystemMetrics_ ( #SM_CXSCREEN ): ;=largeur de l'ecran
hauteur = GetSystemMetrics_ ( #SM_CYSCREEN ): ;=hauteur de l'ecran
; ********** Fond ****************
CreateSprite ( #fond ,1024,768 )
; ********************************
; ********** crayon ****************
CreateSprite ( #crayon ,taille*2,taille*2)
StartDrawing ( SpriteOutput ( #crayon ))
Box (0,0,taille,taille, RGB (0,255,0))
StopDrawing ()
; ********************************
; ********** goute d'eau ****************
CreateSprite ( #goute ,taille,taille)
StartDrawing ( SpriteOutput ( #goute ))
For i = 0 To 5
DrawingMode(#PB_2DDrawing_Outlined)
Circle(taille/2,taille/2,i,RGB(Random(160),Random(160),220 + Random(30)))
Next i
DrawingMode(#PB_2DDrawing_Default)
StopDrawing ()
; ********************************
Repeat
Event = WindowEvent ()
ExamineKeyboard ()
ExamineMouse ()
ClearScreen (0)
If KeyboardPushed ( #PB_Key_Escape )
End
EndIf
DisplaySprite ( #fond ,0,0)
x = MouseX ()
Y = MouseY ()
DisplaySprite ( #crayon ,x,Y)
If MouseButton ( #PB_MouseButton_Left )
StartDrawing ( SpriteOutput ( #fond ))
Circle (x,Y,taille, RGB (255,0,0))
StopDrawing ()
EndIf
If KeyboardPushed ( #PB_Key_Space )
StartDrawing ( SpriteOutput ( #fond ))
Circle (x,Y,taille, RGB (0,0,0))
StopDrawing ()
EndIf
If MouseButton ( #PB_MouseButton_Right )
;Y=0
; x=Random(largeur)
G=G+1
;Debug CountList (goute())
nouvel_goute(x,Y)
If G>1000 ; < ------------- seuil maximum
ClearList (goute())
G=0
EndIf
EndIf
gravite_collision()
Delay (1)
FlipBuffers ()
ForEver
End
Procedure nouvel_goute(x.l,Y.l)
AddElement (goute())
goute()\x=x
goute()\Y=Y
DisplaySprite ( #goute ,x,Y)
EndProcedure
Procedure gravite_collision()
ResetList (goute() )
While NextElement (goute())
StartDrawing ( ScreenOutput ())
If rapide_Point (goute()\x,goute()\Y+taille) = 0
goute()\Y+taille
Else
p = Random (1)
If p = 1
If rapide_Point (goute()\x+taille,goute()\Y)= 0
goute()\x+taille
Else
If rapide_Point (goute()\x-1,goute()\Y)= 0 :goute()\x-taille: EndIf
EndIf
Else
If rapide_Point (goute()\x-1,goute()\Y)=0
goute()\x-taille
Else
If rapide_Point (goute()\x+taille,goute()\Y)= 0 :goute()\x+taille: EndIf
EndIf
EndIf
EndIf
StopDrawing ()
; ******** test sorti en bas on remet en haut ! ************
If goute()\Y>= (hauteur)
goute()\Y=0
EndIf
; *******************************
; ******** test sorti a droite et gauche************
If (goute()\x>= (largeur-taille) Or goute()\x<=0)
goute()\pasx=0
goute()\pasy=0
EndIf
; *******************************
DisplayTransparentSprite(#goute ,goute()\x,goute()\Y)
Wend
EndProcedure
Procedure rapide_Point(x,Y)
; de cpl Bator
If (x > 0) And (x < largeur) And (Y > 0) And (Y < hauteur)
Select DrawingBufferPixelFormat ()
Case #PB_PixelFormat_8Bits : PF=1:t=0
Case #PB_PixelFormat_15Bits : PF=2:t=0
Case #PB_PixelFormat_16Bits : PF=2:t=0
Case #PB_PixelFormat_24Bits_RGB : PF=3:t=0
Case #PB_PixelFormat_24Bits_BGR : PF=3:t=1
Case #PB_PixelFormat_32Bits_RGB : PF=4:t=0
Case #PB_PixelFormat_32Bits_BGR : PF=4:t=1
EndSelect
color= PeekL ( DrawingBuffer () + (x * PF) + DrawingBufferPitch ()* ( Y ) )
If t=1
Rouge= Red (color)
Vert= Green (color)
Bleu= Blue (color)
color= RGB (Bleu,Vert,Rouge)
EndIf
ProcedureReturn color
Else
color= RGB (0,0,0)
ProcedureReturn color
EndIf
EndProcedure
Code : Tout sélectionner
DisplayTransparentSprite ( #crayon ,x,Y)
Code : Tout sélectionner
DisplaySprite ( #crayon ,x,Y)
non !!Mytic a écrit :Ah, Dsl…![]()
Au fait, la collision ne se fait pas au centre de sprite ?
ben nonMytic a écrit :Il suffit de faire ça Point(x+tailleX/2,y+tailleY/2)
Code : Tout sélectionner
couleur_gauche = point(x-1,(y+taille/2))
couleur_ haut = point(x+(taille/2),y-1)
couleur_droite =point(x+taille,y+(taille/2))
couleur_bas=point(x+(taille/2),y+taille)
Code : Tout sélectionner
couleur_angle_haut_gauche = point(x-1,y-1)
couleur_ angle_haut_droite = point(x+(taille+1),y-1)
couleur_angle_bas_gauche =point(x-1,y+(taille+1))
couleur_angle_bas_droite=point(x+(taille+1),y+(taille+1))