Here's a very quick example of match3 that I've just knocked together.
The number represents the start of a matching column or row.
// Project: match3
// Author: Scraggle
// Created: 2020-06-28
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "match3" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
#constant BOARD_SIZE 8
#constant CELL_SIZE 75
#constant QTY_STYLES 5
type tCell
style as integer
spr as integer
txt as integer
qtyMatches as integer
checkedH as integer
checkedV as integer
endtype
global board as tCell[BOARD_SIZE, BOARD_SIZE]
global color as integer[QTY_STYLES]
color[0] = 0xff0000
color[1] = 0x00ff00
color[2] = 0x0000ff
color[3] = 0xff00ff
color[4] = 0x00ffff
color[5] = 0xffff00
InitialiseBoard()
GetMatches()
ShowMatches()
repeat
Print("Press <Space> to randomise board")
if GetRawKeyPressed(32)
RandomiseBoard()
GetMatches()
ShowMatches()
endif
Sync()
until GetRawKeyPressed(27)
function GetMatches()
ClearMatches()
for y = 0 to BOARD_SIZE
for x = 0 to BOARD_SIZE
//Check horizontally for matches
if board[x,y].checkedH = 0
match = CheckHoriz(x,y)
if match > board[x,y].qtyMatches
board[x,y].qtyMatches = match
endif
endif
//Check Vertically for matches
if board[x,y].checkedV = 0
match = CheckVert(x,y)
if match > board[x,y].qtyMatches
board[x,y].qtyMatches = match
endif
endif
next x
next y
endfunction
function CheckHoriz(x,y)
match = 1
while x < BOARD_SIZE
if board[x,y].style = board[x+1,y].style
board[x,y].checkedH = 1
inc match
inc x
else
exitfunction match
endif
endwhile
endfunction match
function CheckVert(x,y)
match = 1
while y < BOARD_SIZE
if board[x,y].style = board[x,y+1].style
board[x,y].checkedV = 1
inc match
inc y
else
exitfunction match
endif
endwhile
endfunction match
function ClearMatches()
for y = 0 to BOARD_SIZE
for x = 0 to BOARD_SIZE
board[x,y].qtyMatches = 1
board[x,y].checkedH = 0
board[x,y].checkedV = 0
next x
next y
endfunction
function ShowMatches()
for y = 0 to BOARD_SIZE
for x = 0 to BOARD_SIZE
SetTextString(board[x,y].txt, str(board[x,y].qtyMatches))
if board[x,y].qtyMatches >= 3
SetTextVisible(board[x,y].txt, 1)
else
SetTextVisible(board[x,y].txt, 0)
endif
next x
next y
endfunction
function InitialiseBoard()
for y = 0 to BOARD_SIZE
for x = 0 to BOARD_SIZE
board[x,y].spr = CreateSprite(0)
SetSpriteSize(board[x,y].spr, CELL_SIZE, CELL_SIZE)
SetSpritePosition(board[x,y].spr, 50 + x*CELL_SIZE, 50 + y*CELL_SIZE)
board[x,y].txt = CreateText("0")
SetTextPosition(board[x,y].txt, 50+(CELL_SIZE/2) + x*CELL_SIZE, 50 + y*CELL_SIZE)
SetTextColor(board[x,y].txt, 0, 0, 0, 255)
SetTextSize(board[x,y].txt, CELL_SIZE)
SetTextAlignment(board[x,y].txt, 1)
next x
next y
RandomiseBoard()
endfunction
function RandomiseBoard()
for y = 0 to BOARD_SIZE
for x = 0 to BOARD_SIZE
board[x,y].style = Random(0, QTY_STYLES)
SetSpriteColor(board[x,y].spr, GetColorRed(color[board[x,y].style]), GetColorGreen(color[board[x,y].style]), GetColorBlue(color[board[x,y].style]), 255)
next x
next y
endfunction