Hi all,
Here's an example to simulate a mosaic explosion.
An image is displayed, and, a "crack" comes and boooooom the image explodes.
You can download the zip file to have to entire project. I've done it with the learning edition.
Here's the code (see the attached zip file to have the entire project) :
[pbcode]
; PROJECT : mosaic
; AUTHOR : Crystal Noir
; CREATED : 24/02/2010
; EDITED : 24/02/2010
; ---------------------------------------------------------------------
SETFPS 60
//Load Image
LoadImage "pingouin.jpg",1
//Type
Type Morceau
x#
y#
sourcex#
sourcey#
Explox#
Exploy#
EndType
Dim Ping As Morceau List
Mosaic()
AfficheMos()
Sync
Wait 2500
AfficheCrack()
Text 350,500,"Be Carefull..."
Sync
Wait 2000
//Main Loop
Repeat
Cls RGB(0,0,0)
Text 300,500,"BOOOOOOOOOOOOOOOOOOOOOOOOOOM !"
AfficheExplo()
Sync
Until EscKey() = 1
//PBSUB
PSub Mosaic()
For posx = 0 To 400 Step 8
For posy = 0 To 300 Step 8
Ping = New Morceau
Ping.x# = posx + 200
Ping.y# = posy + 150
Ping.sourcex# = sourcex
Ping.sourcey# = sourcey
Ping.Explox# = Rnd#(30) - 15
Ping.Exploy# = Rnd#(30) - 15
sourcey = sourcey + 8
Next
sourcex = sourcex + 8
sourcey = 0
Next
EndPSub
PSub AfficheExplo()
For Each Ping()
mapos = GetListPos(Ping())
Ping.x# = Ping.x# + Ping.Explox#
Ping.y# = Ping.y# + Ping.Exploy#
CopyRect 1,Ping.sourcex#,Ping.sourcey#,Ping.sourcex#+8,Ping.sourcey#+8,0,Ping.x#,Ping.y#
If Ping.x# > 800 Or Ping.x# < 0 Or Ping.y# > 600 Or Ping.y# < 0
FreeCell Ping(),mapos
EndIf
Next
EndPSub
PSub AfficheMos()
For Each Ping()
CopyRect 1,Ping.sourcex#,Ping.sourcey#,Ping.sourcex#+8,Ping.sourcey#+8,0,Ping.x#,Ping.y#
Next
EndPsub
PSub AfficheCrack()
For Each Ping()
a = Rnd(4) - 2
b = Rnd(4) - 2
Ping.x# = Ping.x# + a
Ping.y# = Ping.y# + b
CopyRect 1,Ping.sourcex#,Ping.sourcey#,Ping.sourcex#+8,Ping.sourcey#+8,0,Ping.x#,Ping.y#
Next
EndPSub
[/pbcode]
The Mosaic Psub initialize the different parts of the image. AfficheCrack PSub display the image with a "crrraaaack effect" before the explosion. Finally, the AfficheExplo PSub makes the image explode in many parts.