I hope this example helps you.
//by Qugurun
SetClearColor(50, 50, 60)
global width : width=GetVirtualWidth()
global height : height=GetVirtualHeight()
//---------------------------------------------------------
type box_class
id as integer
R as integer
G as integer
B as integer
state as integer
endtype
global box_game as box_class[]
box_game = CreateBox(3, 6, 5, width/2, height/2)
//---------------------------------------------------------
type touch_class
item as integer
color as integer
endtype
touch_color as touch_class [1]
touch_count=0
//=========================================================
do
if GetPointerPressed()=1
for i = 0 to box_game.length
if GetSpriteHitTest(box_game[i].id, GetPointerX(), GetPointerY()) = 1 and box_game[i].state=0 and touch_count<2
box_game[i].state=1
SetSpriteColor(box_game[i].id, box_game[i].r, box_game[i].g, box_game[i].b, 255)
touch_color[touch_count].item=i
touch_color[touch_count].color=MakeColor(box_game[i].r, box_game[i].g, box_game[i].b)
inc touch_count
exit
endif
next i
endif
if GetPointerReleased()=1 and touch_count=2
if touch_color[0].color <> touch_color[1].color
b1=touch_color[0].item
b2=touch_color[1].item
box_game[b1].state=0
box_game[b2].state=0
SetSpriteColor(box_game[b1].id, 255, 255, 255, 255)
SetSpriteColor(box_game[b2].id, 255, 255, 255, 255)
touch_count=0
else
touch_count=0
endif
endif
Sync()
loop
//=========================================================
function ColorShake(array ref as box_class[])
for i = array.length to 0 step -1
j=Random(0, i)
tmp_r=array[j].r
tmp_g=array[j].g
tmp_b=array[j].b
array[j].r = array[i].r
array[j].g = array[i].g
array[j].b = array[i].b
array[i].r = tmp_r
array[i].g = tmp_g
array[i].b = tmp_b
next i
endfunction
function CreateBox (row, col, distance, x#, y#)
image_w=80
image_h=80
x1=x#-((image_w+distance)*(row-1))/2
y1=y#-((image_h+distance)*(col-1))/2
local array as box_class[]
color_step = 0
temp_color = 0
for i=0 to col-1
for k=0 to row-1
array.length=array.length+1
//---------------------------------------------------------
array[array.length].id=CreateSprite(0)
SetSpriteSize(array[array.length].id, 80, 80)
//---------------------------------------------------------
if color_step = 0
temp_color=MakeColor(random(0, 255),random(0, 255), random(0, 255))
endif
array[array.length].r=GetColorRed(temp_color)
array[array.length].g=GetColorGreen(temp_color)
array[array.length].b=GetColorBlue(temp_color)
inc color_step
if color_step = 2 then color_step = 0
//---------------------------------------------------------
SetSpritePositionByOffset(array[array.length].id, x1+GetSpriteWidth(array[array.length].id)*k+k*distance, y1+GetSpriteHeight(array[array.length].id)*i+i*distance )
next k
next i
ColorShake(array)
endfunction array