L'Effet 2D de vaguelette du pauvre

Programmation avancée de jeux en PureBasic
Avatar de l’utilisateur
Fig
Messages : 1176
Inscription : jeu. 14/oct./2004 19:48

L'Effet 2D de vaguelette du pauvre

Message par Fig »

Code : Tout sélectionner

DisableDebugger
#X=600:#Y=400
#Dampening=0.995 ;change this value to make the wave last longer (closer to 1)
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0 Or OpenWindow(0, 0, 0, #X, #Y, "2D waves", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)=0 Or OpenWindowedScreen(WindowID(0),0,0,#X,#Y,0,0,0,#PB_Screen_NoSynchronization )=0
    MessageRequester("Error", "Can't open the sprite system", 0)
    End
EndIf
Dim Buffer.f(#X*2,#Y)
Structure Pixel
    Pixel.l
EndStructure
prev_buffer.i=0
cur_buffer.i=#X
Repeat
    FlipBuffers()
    Repeat:Until WindowEvent()=0
    
    ;copy the current buffer to the screen memory
    StartDrawing(ScreenOutput())
    Buffer      = DrawingBuffer()
    Pitch       = DrawingBufferPitch()
    For j=0 To #Y-1
        *Line.Pixel = Buffer+Pitch*j
        For ii=0 To #X-1
            i=ii+cur_buffer
            
            ;propagate the wave
            If ii>0 And ii<#X-1 And j>1 And j<#Y-1
                k=ii+prev_buffer
                Buffer(i,j)=(Buffer(k-1,j)+Buffer(k+1,j)+Buffer(k,j-1)+Buffer(k,j+1))/2-Buffer(i,j)
                Buffer(i,j)*#Dampening                
            EndIf
            
            ;copy to the screen
            color.i=Int(Buffer(i,j)*10)
            *Line\Pixel=color
            *line+4
            
        Next ii
    Next j
    ;display mouse cursor
    DrawText(0,0,"[Escape] pour quitter")
    DrawText(0,20,"[Clique gauche] taper la surface")
    Box(MouseX(),MouseY(),10,10,RGB(255,255,255))
    StopDrawing()
    
    ExamineKeyboard()
    ExamineMouse()
    
    If MouseButton(#PB_MouseButton_Left) And MouseX()>0 And MouseX()<#X-1 And MouseY()>0 And MouseY()<#Y-1
        Buffer(MouseX(),MouseY())=20
    EndIf
    
    cur_buffer!#X
    prev_buffer!#X
      
Until KeyboardPushed(#PB_Key_Escape)
Dernière modification par Fig le dim. 13/mai/2018 8:40, modifié 3 fois.
Il y a deux méthodes pour écrire des programmes sans erreurs. Mais il n’y a que la troisième qui marche.
Version de PB : 6.00LTS - 64 bits
Avatar de l’utilisateur
SPH
Messages : 4722
Inscription : mer. 09/nov./2005 9:53

Re: L'Effet 2D de vaguelette du pauvre

Message par SPH »

Interessant 8)
http://HexaScrabble.com/
!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Intel Core i7 4770 64 bits - GTX 650 Ti
Version de PB : 6.00 - 64 bits
Avatar de l’utilisateur
GallyHC
Messages : 1703
Inscription : lun. 17/déc./2007 12:44

Re: L'Effet 2D de vaguelette du pauvre

Message par GallyHC »

Bonjour,

Sympa j'aime bien, merci.

GallyHC
Configuration : Tower: Windows 10 (Processeur: i7 "x64") (Mémoire: 16Go) (GeForce GTX 760 - 2Go) - PureBasic 5.72 (x86 et x64)
Avatar de l’utilisateur
Kwai chang caine
Messages : 6962
Inscription : sam. 23/sept./2006 18:32
Localisation : Isere

Re: L'Effet 2D de vaguelette du pauvre

Message par Kwai chang caine »

Cool !!! merci 8)
ImageLe bonheur est une route...
Pas une destination

PureBasic Forum Officiel - Site PureBasic
Shadow
Messages : 1373
Inscription : mer. 04/nov./2015 17:39

Re: L'Effet 2D de vaguelette du pauvre

Message par Shadow »

Jolie, comprends rien mais jolie :D
Processeur: Intel Core I7-4790 - 4 Cœurs - 8 Thread: 3.60 Ghz.
Ram: 32 GB.
Disque: C: SDD 250 GB, D: 3 TB.
Vidéo: NVIDIA GeForce GTX 960: 2 GB DDR5.
Écran: Asus VX248 24 Pouces: 1920 x 1080.
Système: Windows 7 64 Bits.

PureBasic: 5.60 x64 Bits.
Répondre