J'essaie de réaliser un petit jeu de type match3 (exemple de jeu connus utilisant ce principe : candyCrush).
J'ai réussi à faire le système de comparaison (match) pour voir si au moins 3 formes sont alignées en X ou en Y. Mais je ne sais pas trop comment faire ensuite pour faire redescendre les formes dans les cases devenues vides.
Auriez-vous une idée de la façon dont je pourrais m'y prendre pour faire ça ?
En gros, pour le moment, je mets les formes qui ont été "matchées" ( c'est-à-dire trouvées par 3 ou + en x ou en Y) en y = -96 Et ensuite, j'aimerai les faire redescendre et faire aussi descendre les formes dans le tableau en dessous desquelles il y a désormais une case vide, comme dans les jeux de match3 ^^.
Si vous avez une idée, même simplement une piste, merci beaucoup

voici le début de mon code :
Code : Tout sélectionner
#Window_main = 0
If InitSprite() =0 Or InitKeyboard() =0
End
EndIf
Global GlobX,GlobY,CaseVide,MaxShape,NbCase
GlobX = 100
GlobY = 50
MaxShape = 4
NbCase = 24
Structure tCase
x.i
y.i
Vide.a
Colone.a
Line.a
OnY.a
EndStructure
Global Dim Caz.tCase(NbCase) ; les cases vides
Structure tCazFond
x.i
y.i
sp.i
EndStructure
Global Dim CazBG.tCazFond(NbCase)
Structure tShape
Sort.i ; For sorting the Array
Typ.a
Sprite.i
x.i
y.i
CibleY.i
CibleOk.a
Selected.a
Line.a
; juste pour voir le n° du tableau
TextId.a
EndStructure
Global Dim Shape.tShape(NbCase)
Procedure SetSpriteImage(n,img)
a = 1
b= 94
If StartDrawing(SpriteOutput(n))
Select img
Case 1
Box(a,a,b,b,RGB(255,0,0))
Case 2
Box(a,a,b,b,RGB(0,255,0))
Case 3
Box(a,a,b,b,RGB(255,255,0))
Case 4
Box(a,a,b,b,RGB(0,255,255))
Case 5
Box(a,a,b,b,RGB(0,0,255))
Case 10
Box(a,a,b,b,RGB(150,150,150))
EndSelect
StopDrawing()
EndIf
EndProcedure
Procedure AddShape(nb,i)
; le type de forme
t = Random(MaxShape+1,1)
Shape(i)\Sprite = CreateSprite(#PB_Any,96,96)
n = Shape(i)\Sprite
SetSpriteImage(n,t)
x = 96 * Mod(i,nb)
y1 = i/nb
y = 96 * y1
Shape(i)\x = x
Shape(i)\y = y
Shape(i)\typ = t
Shape(i)\Line = Shape(i)\y/96
CazBG(i)\sp = CreateSprite(#PB_Any,96,96)
SetSpriteImage(CazBG(i)\sp,10)
CazBG(i)\x = x
CazBG(i)\y = y
EndProcedure
Procedure ResetShape(i)
Caz(i)\x = Shape(i)\x
Caz(i)\y = Shape(i)\y
Caz(i)\Colone = Shape(i)\x/96
Caz(i)\Line = Shape(i)\y/96
If Caz(i)\OnY = 0
Shape(i)\y = -96
Else
Shape(i)\y = -96 * (1+Caz(i)\Line)
EndIf
Shape(i)\y = -96
Shape(i)\CibleY = Shape(i)\y+96
Shape(i)\CibleOk = 1
Shape(i)\Typ = Random(MaxShape+1,1)
Shape(i)\Line = Shape(i)\y/96
SetSpriteImage(Shape(i)\Sprite,Shape(i)\Typ)
EndProcedure
; Match
Procedure CheckMatch()
; JE vérifie si on a 3 shape alignés en X
For i=0 To ArraySize(shape())
If i <= ArraySize(shape())-2
If Shape(i)\y>=0
If Shape(i)\x <=96*2
ok3 = 0
ok4 = 0
t = Shape(i)\Typ
If (Shape(i+1)\typ = t And Shape(i+2)\typ =t)
If (Shape(i+1)\y >= 0 And Shape(i+2)\y >=0)
Caz(i)\Vide = 1
Caz(i+1)\Vide = 1
Caz(i+2)\Vide = 1
bonus = 9
If Shape(i)\x <=96
If shape(i+3)\typ = t
ok3 = 1
bonus=bonus+4
Caz(i+3)\Vide = 1
If Shape(i)\x =0
If shape(i+4)\typ = t
Caz(i+4)\Vide = 1
bonus=bonus+5
ok4 =1
EndIf
EndIf
EndIf
EndIf
u=76
CaseVide = 1
EndIf
EndIf
EndIf
EndIf
EndIf
Next
; puis on vérifie si on a 3 shapes au moins qui se suivent sur trois lignes .
For i=0 To ArraySize(shape())
If i < ArraySize(shape())-9
If Shape(i)\y >=0
If Shape(i)\y <=96*2
ok3 = 0
ok4 = 0
t = Shape(i)\Typ
a = 5
If (Shape(i+a)\typ = t And Shape(i+2*a)\typ =t)
If (Shape(i+a)\y >= 0 And Shape(i+2*a)\y >=0)
Caz(i)\Vide = 1
Caz(i)\OnY = 1
Caz(i+a)\Vide = 1
Caz(i+2*a)\Vide = 1
Caz(i+a)\OnY = 1
Caz(i+a*2)\OnY = 1
bonus = 9
If Shape(i)\y <=96 And i+3*a<=ArraySize(shape())
If shape(i+3*a)\typ = t
ok3 = 1
bonus=bonus+4
Caz(i+3*a)\vide = 1
Caz(i+3*a)\OnY = 1
If Shape(i)\y <=0 And i+4*a<=ArraySize(shape())
If shape(i+4*a)\typ = t
bonus=bonus+5
ok4 =1
Caz(i+4*a)\vide = 1
Caz(i+4*a)\OnY = 1
EndIf
EndIf
EndIf
EndIf
u=76
CaseVide = 1
EndIf
EndIf
EndIf
EndIf
EndIf
Next
EndProcedure
; fenêtre, screen, etc...
flag = #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget
WinW =800
WinH =600
If OpenWindow(#Window_main,0,0,WinW,WinH, "Sprite", Flag) = 0
End
EndIf
If OpenWindowedScreen(WindowID(0), 0,0,WinW,WinH) = 0
End
EndIf
; je crée les shapes & les cases du fond
For i=0 To 24
AddShape(5,i)
Next
Repeat
Repeat
EventID = WindowEvent()
Select EventID
Case #PB_Event_LeftClick
; on verifie si on clique sur 2 formes
x = WindowMouseX(0) - globX
y = WindowMouseY(0) - globY
If selected = 0
id = -1
For i=0 To 24
With shape(i)
If x>\x And x<=\x+96 And y>\y And y<\y+96
id = i
Selected = 1
Break
EndIf
EndWith
Next
Else
id2 =-1
For i=0 To 24
With shape(i)
If x>\x And x<=\x+96 And y>\y And y<\y+96
id2 = i
Break
EndIf
EndWith
Next
If id2 > -1
tt = Shape(id)\Typ
Shape(id)\Typ = Shape(id2)\Typ
Shape(id2)\Typ = tt
SetSpriteImage(Shape(id)\sprite,Shape(id)\Typ)
SetSpriteImage(Shape(id2)\sprite,Shape(id2)\Typ)
EndIf
Selected = 0
EndIf
Case #PB_Event_CloseWindow
End
EndSelect
Until event = 0
; on vérfie si on a pas 3 cases en X ou en Y qui se suivent à l'identique
CheckMatch()
; on a des cases qui se suivent
If caseVide = 1
For j=0 To ArraySize(Caz())
If caz(j)\Vide = 1
ResetShape(j)
caz(j)\Vide = 2
EndIf
Next
EndIf
; puis, on affiche les cases
ClearScreen(RGB(100,100,100))
; le fond
For i=0 To ArraySize(CazBG())
With CazBG(i)
DisplaySprite(\sp,\x+GlobX,\y+GlobY)
EndWith
Next
; les formes
For i=0 To ArraySize(shape())
With shape(i)
DisplaySprite(\Sprite,\x+GlobX,\y+GlobY)
EndWith
Next
If StartDrawing(ScreenOutput())
DrawText(0,0,Str(id)+"/"+Str(id2))
StopDrawing()
EndIf
FlipBuffers()
Until Quit = 1