Des petits effets :)

Programmation avancée de jeux en PureBasic
garzul
Messages : 683
Inscription : mer. 26/mai/2004 0:33

Des petits effets :)

Message par garzul »

:) Voici des ptits effets ;) (ne regardez surtout pas les truc pour le debug ca faît des gros chiffres !!! ^^)

Un petit cercle haut en couleur :) :

Code : Tout sélectionner

; ---------------------------------------
; - Auteur            : Garzul          -
; - Date              : 4 Juin 2005     -
; - Type de programme : Effets          -
; - Version de PB     : PureBasic v3.92 -
; ---------------------------------------

InitSprite() : InitKeyboard()

OpenScreen(1024,768,32,"Algorythme")


; - Définition de diverse variables servant au programmes !
x              = 512
y              = 364
Angle          = 0
Rayon          = 350

; - Définition des Couleurs.
Red            = 0
Green          = 0
Blue           = 0

; - Définition de PI.
#pi            = 3.1415


Repeat

ExamineKeyboard()
ClearScreen(0,0,0)



StartDrawing(ScreenOutput())

For i = 0 To Rayon
 For Vit = 0 To 200

  Green + 1 / Cos(i)
  Blue  + 1

  Plot(x + i * Cos(Vit),y + i * Sin(Vit),RGB(Red,Green,Blue))

 Next Vit
Next i

DrawingMode(1) 
FrontColor($00,$FF,$FF) 
DrawText("Arguments de Debuggages : ")
FrontColor($8C,$FF,$73)
Locate(0,20)  
DrawText("Angle : " + Str(Angle))
FrontColor($00,$FF,$FF)
Locate(0,60)
DrawText("Debug Couleur : ")
FrontColor($FF,$01,$00)
Locate(0,80)
DrawText("Vert : " + Str(Green))
Locate(0,100)
DrawText("Bleu : " + Str(Blue))

StopDrawing()


Angle + 1 


FlipBuffers()

Until KeyboardPushed(#PB_Key_Escape)
End
La j'avoue que j'ai faît n'importe quoi :) :

Code : Tout sélectionner

; --------------------------------------------------
; - Auteur            : Garzul                     -
; - Date              : 4 Juin 2005                -
; - Type de programme : Algorythme de brouillage   -
; - Version de PB     : PureBasic v3.92            -
; --------------------------------------------------

InitSprite() : InitKeyboard()

OpenScreen(1024,768,32,"Algorythme")


; - Définition de diverse variables servant au programmes !

x              = 0
y              = 0
Rayon          = 0
Red            = 0
Green          = 0
Blue           = 0

Repeat

ExamineKeyboard()
ClearScreen(0,0,0)


StartDrawing(ScreenOutput())

For x = 0 To 1024
 For y = 0 To 768 Step 3
  
  Green +  Sin(x)
  
  ;Red+y/4
  Plot(x,y,RGB(Red,Green,Blue))
 
 Next y
Next x
Rayon + 1
   
DrawingMode(1)
FrontColor($FF,$01,$00)
DrawText("Debug Couleur : ")
Locate(0,30)
DrawText("Vert : " + Str(Green))

StopDrawing()


FlipBuffers()

Until KeyboardPushed(#PB_Key_Escape)
End
Un ptit feu d'artifice xD :D :

Code : Tout sélectionner

InitSprite() : InitKeyboard() : InitMouse()

OpenScreen(1024,768,32,"Formules")

x1          = 700
y1          = 340
xx          = Random(1024)
yy          = 760
Rayon       = 10
PI          = 3.1415
AffichExplo = 0
Angle2      = 0
delay       = 40 + Random(750)


MouseLocate(x1, y1)  

Repeat

ExamineKeyboard()
ExamineMouse() 

ClearScreen(0,0,0)

x = MouseX()    
y = MouseY()  

  If MouseButton(1)
 
    Rayon       = 10
    AffichExplo = 0
    xx          = Random(1024)
    yy          = 760
    delay       = 40 + Random(750)
    
  EndIf

For Angle = 0 To 380

  Red   = 255
  Green = 50
  Blue  = 150
 
   StartDrawing(ScreenOutput())
   
    If AffichExplo = 1
    
     Box(xx + Rayon * Cos(Angle),yy + Rayon * Sin(Angle) * Sin(Sqr(Angle)),2,1,RGB(Red,Green,Blue))
     
    EndIf
    
   StopDrawing()

Next Angle


StartDrawing(ScreenOutput())

  DrawText("Clicker sur le bouton 1 de la souris pour recommencer !")
  Locate(0,20)
  DrawText("PosY : " + Str(PositionY))
  Locate(0,40)
  DrawText("RandomY : " + Str(delay))
  Locate(0,60)
  DrawText("Ca pete dans : " + Str(DelayElapsed))
  
  DelayElapsed = yy - delay
  PositionY    = yy
  
  If DelayElapsed < 0
  
     DelayElapsed = 0
     
  EndIf
  
  If AffichExplo = 0

     Box(xx + Cos(Angle2),yy,3,10,RGB($00,$00,$FF))

  EndIf
  
  If yy = delay
  
     AffichExplo = 1
     
  EndIf
  
  If AffichExplo = 1
  
    Rayon     + 3
    PositionY = 0
    
  EndIf

StopDrawing()

 ;xx - 1
 yy - 1
 Angle2 + 1

FlipBuffers()

Until KeyboardPushed(#PB_Key_Escape)
End

Un truc incompréhensible mais jolie :) :

Code : Tout sélectionner

InitSprite() : InitKeyboard()

OpenScreen(1024,768,32,"Formules")

x     = 350
y     = 340
Rayon = 10

Repeat

ExamineKeyboard()
ClearScreen(0,0,0)

   StartDrawing(ScreenOutput())
   
For Angle = 0 To 380

 Red   = Random(244)
 Green = Random(244)
 Blue  = Random(254)

     Box(x + Rayon * Cos(Angle) + Angle,y + Rayon * Sin(Angle),1,1,RGB(Red,Green,Blue))
     LineXY(x + Rayon * Cos(Angle) + Angle,y + Rayon * Sin(Angle),x - Rayon * Cos(Angle) + Angle,y - Rayon * Sin(Angle),RGB(20,Green,Blue))

Next Angle

   StopDrawing()

 Rayon + 1


FlipBuffers()

Until KeyboardPushed(#PB_Key_Escape)
End
Voili voilou amusez vous bien :D !
Oliv
Messages : 2117
Inscription : mer. 21/janv./2004 18:39

Message par Oliv »

Sympa surtout le dernier mais par contre ton feu d'atifice est "spécial", il y a un petit tait bleu qui bouge c'est tout
garzul
Messages : 683
Inscription : mer. 26/mai/2004 0:33

Message par garzul »

Bah t'attend que le temps écoulé arrive à 0 et normalement ca péte :)
Lapin
Messages : 11
Inscription : mar. 19/juil./2005 2:30

Message par Lapin »

le 'truc incompréhensible mais jolie' c'est vraiment simpa :D

et tout ça en 20 lignes de code #yes
LittleBigMan
Messages : 9
Inscription : mer. 10/août/2005 2:05

Message par LittleBigMan »

Salut tout le monde. (pour Gazul un feux d'artice 3D)

j'ai découvert PUREBASIC fin Mai et aprés une semaine d'éssai j'ai acheté la licence. Je trouve ce langage super !

En regardant sur le forum et sur les site qui parle de PUREBASIC j'ai fait 2 ou 3 petit chose.

voila une des petit chose que j'ai faite :

Code : Tout sélectionner

;/----------------------------------------------------------------------------
;/
;/ Touche HAUT et BAS pour rotation de l'axe X
;/        GAUCHE et DROITE pour rotation de l'axe Y
;/        INSER et SUPPR pour rotation axe Z
;/        PAGE SUIVANTE et PAGE PRECEDENTE pour le Zoom
;/        HOME pour réinitialiser
;/        P pour pause => peut toujours faire des rotation pendant la pose
;/
;/-----------------------------------------------------------------------------

;{- initialisation programe
If InitSprite()=0 Or InitKeyboard() = 0 Or InitSound() = 0 Or OpenScreen(1024 , 768 , 32 , "Feux d'artifice") = 0 
  MessageRequester("Feux d'artifice" , "Erreur DirectX", #MB_ICONINFORMATION | #MB_OK)
  End
EndIf

; InitSprite():InitKeyboard():InitSound()
; OpenWindow(1,10,10,1000,750,#PB_Window_SystemMenu,"Test") 
; OpenWindowedScreen( WindowID(),10,10,1024,768,1,10,10) 
;}

Structure donnees
  x.f
  y.f
  z.f
  rayon.f
  altitude.f
  red.f
  green.f
  blue.f
  petit.f
  vitesse.f
  compteur.l
EndStructure

nbpetard.l = 10

;{- variables
#Pi=3.1415926 
Dim petards.donnees(nbpetard)
Global petards.donnees
Global  scrx.l, scrx2.l, scrxc.l, scry.l, scry2.l, scryc.l
Global wx.l, wy.l, wz.l, Constant.f, zoom.f
Global n.l,cx.f, cy.f, cz.f

scrx=1024:scrx2=scrx/2: scrxc=scrx-3
scry=768:scry2=scry/2:scryc=scry-3
vitesse.f = 1
zoom = 1
pause.b=1
gravite.f=0
wx = 0 : wy = 0 : wz = 0
;}
;{- table des cos
Dim _sin.f(360) 
Dim _cos.f(360) 
Dim _xcos.f(720)
Dim _ysin.f(720)
Dim _zsin.f(720)
For i = 0 To 360
  _sin(i) = Sin(i*#Pi/180) 
  _cos(i) = Cos(i*#Pi/180)
Next
For i=0 To 719
  _xcos(i) = Cos(i) 
  _ysin(i) = Sin(i) * Sin(Sqr(i))
  _zsin(i) = Sin(i) * Cos(Sqr(i))
Next i 
;}

Procedure _plot(x.f,y.f,z.f,rgb.l)
  
  x-scrx2 : y-scry2 : z-scry2
  
  x1.f = x * _cos(wz) - y * _sin(wz) ; Rotation sur l'axe Z
  y1.f = x * _sin(wz) + y * _cos(wz)
  y2.f = y1 * _cos(wx) - z * _sin(wx) ; Rotation sur l'axe X
  z1.f = y1 * _sin(wx) + z * _cos(wx)
  ; z2.f = z1 * _cos(wy) - x1 * _sin(wy) ; Rotation sur l'axe Y
  x2.f = z1 * _sin(wy) + x1 * _cos(wy)
  xx.f = scrx2+x2*zoom
  yy.f = scry2+y2*zoom
  
  If xx > 2 And xx < scrxc And yy > 2 And yy < scryc
    Plot(xx,yy,rgb)
    If petards(n)\petit > 50 And zoom >0.4
      Plot(xx+1, yy, rgb-$323232)
      Plot(xx-1, yy, rgb-$323232)
      Plot(xx, yy+1, rgb-$323232)
      Plot(xx, yy-1, rgb-$323232)
    EndIf
    If petards(n)\petit > 100 And zoom >0.7
      Plot(xx+1, yy-1, rgb-$646464)
      Plot(xx-1, yy-1, rgb-$646464)
      Plot(xx+1, yy+1, rgb-$646464)
      Plot(xx-1, yy+1, rgb-$646464)
    EndIf
    If zoom>4 And petards(n)\petit > 100
      Plot(xx-1, yy+2, rgb-$646464)
      Plot(xx, yy+2, rgb-$646464)
      Plot(xx+1, yy+2, rgb-$646464)
      Plot(xx-1, yy-2, rgb-$646464)
      Plot(xx, yy-2, rgb-$646464)
      Plot(xx+1, yy-2, rgb-$646464)
      Plot(xx+2, yy+1, rgb-$646464)
      Plot(xx+2, yy, rgb-$646464)
      Plot(xx+2, yy-1, rgb-$646464)
      Plot(xx-2, yy+1, rgb-$646464)
      Plot(xx-2, yy, rgb-$646464)
      Plot(xx-2, yy-1, rgb-$646464)
    EndIf
    If zoom>6 And petards(n)\petit > 100
      Plot(xx-2, yy+2, rgb-$646464)
      Plot(xx+2, yy+2, rgb-$646464)
      Plot(xx+2, yy-2, rgb-$646464)
      Plot(xx-2, yy-2, rgb-$646464)
      Plot(xx-3, yy, rgb-$646464)
      Plot(xx, yy+3, rgb-$646464)
      Plot(xx+3, yy, rgb-$646464)
      Plot(xx, yy-3, rgb-$646464)
    EndIf
  EndIf
  
EndProcedure
Procedure _LineXY(x.f,y.f,z.f,xx.f,yy.f,zz.f,rgb.l)
  
  x-scrx2:y-scry2:z-scry2
  xx-scrx2:yy-scry2:zz-scry2
  
  x1.f = x * _cos(wz) - y * _sin(wz) ; Rotation sur l'axe Z
  y1.f = x * _sin(wz) + y * _cos(wz)
  y2.f = y1 * _cos(wx) - z * _sin(wx) ; Rotation sur l'axe X
  z1.f = y1 * _sin(wx) + z * _cos(wx)
  ; z2.f = z1 * _cos(wy) - x1 * _sin(wy) ; Rotation sur l'axe Y
  x2.f = z1 * _sin(wy) + x1 * _cos(wy)
  xl1.f = scrx2+x2*zoom
  yl1.f = scry2+y2*zoom
  
  x1.f = xx * _cos(wz) - yy * _sin(wz) ; Rotation sur l'axe Z
  y1.f = xx * _sin(wz) + yy * _cos(wz)
  y2.f = y1 * _cos(wx) - zz * _sin(wx) ; Rotation sur l'axe X
  z1.f = y1 * _sin(wx) + zz * _cos(wx)
; z2.f = z1 * _cos(wy) - x1 * _sin(wy) ; Rotation sur l'axe Y
  x2.f = z1 * _sin(wy) + x1 * _cos(wy)
  xl2.f = scrx2+x2*zoom
  yl2.f = scry2+y2*zoom
  
  Line(xl1,yl1,xl2-xl1,yl2-yl1,rgb)
  
EndProcedure  
Procedure _DrawText(x.f,y.f,z.f,texte.s,r.l,g.l,b.l)
  
  x-scrx2:y-scry2:z-scry2
  
  x1.f = x * _cos(wz) - y * _sin(wz) ; Rotation sur l'axe Z
  y1.f = x * _sin(wz) + y * _cos(wz)
  y2.f = y1 * _cos(wx) - z * _sin(wx) ; Rotation sur l'axe X
  z1.f = y1 * _sin(wx) + z * _cos(wx)
  ; z2.f = z1 * _cos(wy) - x1 * _sin(wy) ; Rotation sur l'axe Y
  x2.f = z1 * _sin(wy) + x1 * _cos(wy)
  xl1.f = scrx2+x2*zoom
  yl1.f = scry2+y2*zoom
  
  If zoom > 0.045
    LoadFont (0, "verdana", 12*zoom)
    DrawingFont(UseFont(0))
    Locate(xl1, yl1):DrawText(texte)
  EndIf
  
EndProcedure

;{- boucle principale
Repeat 
  
  ClearScreen(0,0,0)
  If StartDrawing(ScreenOutput())
    FrontColor(255,0,0)
    DrawingMode(1|4)
    
    ;{- repere 3d
    ; axe de rotation
    c=3 : ry=0 : Pas = scry/6
    Repeat
      If c<>0
        _LineXY(scrx2-16,ry,scry2,scrx2+16,ry,scry2,RGB(0,0,255)) ; y
        _DrawText(scrx2-32,ry-9,scry2,Str(c),255,0,0)
        _LineXY(scrx2,scry2-16,ry,scrx2,scry2+16,ry,RGB(0,0,255)) ; z
        _DrawText(scrx2,scry2+32,ry-9,Str(c),255,0,0)
      EndIf
      c-1
      ry+Pas
    Until ry>scry
    
    c=-4 : rx=0 : Pas =scrx/8 
    Repeat
      If c<>0
        _LineXY(rx,scry2-16,scry2,rx,scry2+16,scry2,RGB(0,0,255)) ; x
        _DrawText(rx-9,scry2+32,scry2,Str(c),255,0,0)
      EndIf
      c+1
      rx+Pas
    Until rx>scrx
    
    rgb=RGB(0,0,255)
    _LineXY(0,scry2,scry2,scrx,scry2,scry2,rgb) ; x
    _LineXY(scrx2,0,scry2,scrx2,scry,scry2,rgb) ; y
    _LineXY(scrx2,scry2,0,scrx2,scry2,scry,rgb) ; z
    ; cadre avant
    rgb=RGB(0,255,0)
    _LineXY(0,0,0,0,scry,0,rgb) ; |
    _LineXY(scrx,0,0,scrx,scry,0,rgb) ; |
    _LineXY(0,0,0,scrx,0,0,rgb) ; -
    _LineXY(0,scry,0,scrx,scry,0,rgb) ; -
    ; cadre arriere
    _LineXY(0,0,scry,0,scry,scry,rgb) ; |
    _LineXY(scrx,0,scry,scrx,scry,scry,rgb) ; |
    _LineXY(0,0,scry,scrx,0,scry,rgb) ; -
    _LineXY(0,scry,scry,scrx,scry,scry,rgb) ; -
    ; cadre gauche
    _LineXY(0,0,0,0,0,scry,rgb) ; -
    _LineXY(0,scry,0,0,scry,scry,rgb) ; -
    ; cadre droit
    _LineXY(scrx,0,0,scrx,0,scry,rgb) ; -
    _LineXY(scrx,scry,0,scrx,scry,scry,rgb) ; -
    ;}
    
    For n = 0 To nbpetard - 1
      
      ;{- initiliastion de la structure 
      If petards(n)\ red < 50 Or petards(n)\green  < 50 Or petards(n)\blue < 50 
        StopSound(n)
        petards(n)\x = scrx/4 + Random(scrx2) 
        petards(n)\y = scryc
        petards(n)\z = scry2 -scry/8+ Random(scry/4)
        petards(n)\rayon = 20
        petards(n)\altitude = scry/8 + Random(scry/4) 
        petards(n)\red = 200 + Random(55) 
        petards(n)\green = 200 + Random(55) 
        petards(n)\blue = 200 + Random(55) 
        petards(n)\vitesse = 4
        If petards(n)\red < petards(n)\green
          petards(n)\petit = petards(n)\red
        Else 
          petards(n)\petit = petards(n)\green
        EndIf
        If petards(n)\petit > petards(n)\blue
          petards(n)\petit = petards(n)\blue
        EndIf
        petards(n)\compteur = 0
      EndIf
      ;}
      ;{- explosion petard
      If petards(n)\altitude=65535
        rgb=RGB(petards(n)\red,petards(n)\green,petards(n)\blue)
        pr=720-petards(n)\rayon
        nbpoint= pr*zoom
        If nbpoint> 720: nbpoint= 720: EndIf
        For Angle = 0 To nbpoint
          x.f = petards(n)\x+petards(n)\rayon * _xcos(Angle)
          y.f = petards(n)\y+petards(n)\rayon * _ysin(Angle) 
          z.f = petards(n)\z+petards(n)\rayon * _zsin(Angle)
          If x > 1 And x < scrx And y>1 And y<scry And z>1 And z<scry
            _plot(x,y,z,rgb)
          EndIf
        Next Angle
        If pause
          petards(n)\red - 0.5
          petards(n)\green - 0.5
          petards(n)\blue - 0.5
          petards(n)\petit -0.5
          petards(n)\rayon + petards(n)\vitesse/2
          petards(n)\compteur + 1
          ang=(petards(n)\compteur/3+250)
          gravite=_cos(ang)*zoom
          petards(n)\vitesse - gravite/45
          petards(n)\y+gravite*2
        EndIf
      EndIf
      ;}
      ;{- decolage fusee
      If petards(n)\y > petards(n)\altitude
        vibration=_xcos(Random(10))
        x1 = petards(n)\x
        y1 = petards(n)\y
        z1 = petards(n)\z
        ; Plot(x1,y1,$FFFF)
        _plot(x1,y1,z1,$FFFF)
        If pause
          a=petards(n)\y/8
          gravite=_cos(a)*16
          petards(n)\x +vibration
          petards(n)\y - petards(n)\vitesse*4+gravite
          petards(n)\z +vibration
        EndIf
      Else
        petards(n)\altitude=65535
      EndIf 
      ;}
      
    Next
    
    StopDrawing() 
  EndIf
  FlipBuffers() 
  ; FlipBuffers(0) 
  ExamineKeyboard() 
  
  ;{- gestion des touches
  If KeyboardPushed(#PB_Key_PageUp) 
    zoom * 1.02 
    If zoom>10:zoom=10:EndIf
  EndIf 
  If KeyboardPushed(#PB_Key_PageDown) 
    zoom * 0.98
    If zoom<0.001:zoom=0.001:EndIf
  EndIf 
  If KeyboardPushed(#PB_Key_Up) 
    wx - vitesse
    If wx < 1 - vitesse : wx = 359 - vitesse : EndIf
  EndIf
  If KeyboardPushed(#PB_Key_Down) 
    wx + vitesse
    If wx > 359 + vitesse : wx = vitesse : EndIf 
  EndIf 
  If KeyboardPushed(#PB_Key_Right) 
    wy - vitesse
    If wy < 1 - vitesse : wy = 359 - vitesse : EndIf
  EndIf 
  If KeyboardPushed(#PB_Key_Left) 
    wy + vitesse
    If wy > 359 + vitesse : wy = vitesse : EndIf 
  EndIf 
  If KeyboardPushed(#PB_Key_Delete) 
    wz - vitesse
    If wz < 1 - vitesse : wz = 359 - vitesse : EndIf
  EndIf 
  If KeyboardPushed(#PB_Key_Insert) 
    wz + vitesse
    If wz > 359 + vitesse : wz = vitesse : EndIf
  EndIf 
  If KeyboardReleased(#PB_Key_Home) 
    wx = 0 : wy = 0 :  wz = 0 : zoom = 1
  EndIf 
  If KeyboardReleased(#PB_Key_Add) 
    vitesse + 1
    If vitesse = 6 : vitesse = 5 : EndIf
  EndIf 
  If KeyboardReleased(#PB_Key_Subtract) 
    vitesse - 1
    If vitesse = 0 : vitesse = 1 :EndIf
  EndIf 
  If KeyboardReleased(#PB_Key_P)
    If pause
      pause=0
    Else
      pause=1
    EndIf
  EndIf 
  ;}
    
  ;Event.l = WindowEvent() ; pour WindowedScreen 
Until KeyboardPushed(#PB_Key_Escape) ;Or Event = #PB_Event_CloseWindow ; pour WindowedScreen
End 
;}
Bon je sais le code est pas trop propre mais bon le resultat est là
Dr. Dri
Messages : 2527
Inscription : ven. 23/janv./2004 18:10

Message par Dr. Dri »

J'ai une erreur "loadfont ne peut pas être utilisée apres un startdrawing"

Dri :-?
LittleBigMan
Messages : 9
Inscription : mer. 10/août/2005 2:05

Message par LittleBigMan »

Je viend de regarder et chez moi pas d'erreur.

Mais je ne comprend pas si aprés un stardrawing on ne peut pas charger une fonte !!!
LittleBigMan
Messages : 9
Inscription : mer. 10/août/2005 2:05

Message par LittleBigMan »

par contre il faut rajouter une ligne en 274

Code : Tout sélectionner

          If ang>360:ang=360:EndIf

Dr. Dri
Messages : 2527
Inscription : ven. 23/janv./2004 18:10

Message par Dr. Dri »

j'utilise pb 3.94 b4...

Dri
LittleBigMan
Messages : 9
Inscription : mer. 10/août/2005 2:05

Message par LittleBigMan »

c'est peut-être ca moi j'utilise 3.93
LittleBigMan
Messages : 9
Inscription : mer. 10/août/2005 2:05

Message par LittleBigMan »

je l'ai mis dans la rubrique 3D je pense que c'est plus approprié
Répondre