Please help... I'm making a code and i have a big problem.
All begin in good way 60fps but in a few seconds, performance down gradualmente until 8fps or less.
What am i doing wrong? Also, i uploaded the exe too. Thanks
CODE:
//SetVirtualResolution ( 640, 480 )
ScreenWidth = GetDeviceWidth ( )
ScreenHeight = GetDeviceHeight ( )
platform$ = GetDeviceName ( )
//ScreenWidth = 1024
//ScreenHeight = 800
//////////////// CREATE TYPES /////////////////
Type TGrid
l, t as integer
width, height as integer
CellSize as integer
SelectFlag as integer = 0 //boolean 0 1
ClickFlag as integer //boolean 0 1
MX, MY, GX, GY as integer
SelectX as integer
SelectY as integer
SwapCount as Integer = 0
FallCount as integer = 0
NoMatchFlag as integer = 0 //boolean 0 1
EndType
Global Grid as TGrid
Type TMatch
X as Integer //First Tile Match X
Y as integer //First Tile Match Y
Direction as Integer //Direction of Match - 0 = left to right, 1 = top to bottom
Length as Integer //Number of tiles matched
EndType
Global Match as TMatch
Global Dim listaMatch[100] as TMatch
//////////// END CREATE TYPES /////////////////
// Array Lenght
Global arrayX = 6
Global arrayY = 5
Global numPieces = 3
Global Dim MatchArray[arrayX, arrayY]
Global Dim GridArray [arrayX, arrayY]
Grid.width = 64
Grid.height = 64
Grid.l = ScreenWidth //(ScreenWidth - ARRAY_X * Grid.width)/2
Grid.t = ScreenHeight //(ScreenHeight - ARRAY_Y * Grid.height)/2
Global MatchCount as integer
Global FinishedFlag as integer
////////////////////// LOAD IMAGES //////////////////
//imgGems = Loadimage("gems.png") //Load gems
//imgTiles = LoadImage("tile64.jpg") //Load Tiles
///////////////////// END LOAD IMAGES ///////////////
///////////////// SPRITES //////////////////////////
//sprGems = CreateSprite(imgGems) //Create a sprite with gems
//SetSpriteAnimation(sprGems, 48, 48, 6)
//SetSpriteSize ( sprGems, 40, -1 ) //width 100% of screen
///////////////// SPRITES //////////////////////////
////////////////////// LOAD SUNDS //////////////////
sndExplo = LoadSound ("sounds\comor.wav")
////////////////////// END LOAD SOUNDS //////////////////
//////////////////// CREATION FUNCTIONS ////////////////
LoadLevel("1")
Populate()
//////////////// END CREATION FUNCTIONS ////////////////
////////////////////// MAIN LOOP ////////////////////
do
if GetPointerPressed()=1
endif
//While CheckCompleteOut = 0
//CheckCompleteOut = CheckComplete()
fps = ScreenFPS()
Print(fps)
//for y = 0 to arrayY-1
// for x = 0 to arrayX-1
// Print(MatchArray[x,y])
// next x
//next y
//////////// DRAW FUNCTIONS ///////////////
//DrawTiles()
DrawGems()
//////////// END DRAW FUNCTIONS ///////////
sync()
//endwhile
//sync()
loop
//////////////////// END MAIN LOOP///////////////////
/////////////////// FUNCTIONS ///////////////////////
Function LoadLevel(level$)
level$ = "levels\level" + level$ + ".txt"
fileID = OpenToRead (level$)
for y = 0 to arrayY-1
for x = 0 to arrayX-1
fileLine$ = ReadLine( fileID )
GridArray[x,y] = val(fileLine$)
next x
next y
EndFunction
////////////////////////// DRAW //////////////////////////////////
//////////////////////////////////////////////////////////////////
Function DrawTiles()
for y = 0 to ARRAYX-1
for x = 0 to ARRAYY-1
if GridArray[x,y] > 0
sprTiles = CreateSprite(imgTiles) //Create a sprite with gems
SetSpriteAnimation(sprTiles, 48, 48, 1)
SetSpriteSize (sprTiles, 5, -1) //width 40% of screen
SetSpritePosition (sprTiles, GetSpriteWidth(sprTiles)*x+5, GetSpriteHeight(sprTiles)*y+5)
SetSpriteFrame (sprTiles, GridArray[x,y])
Endif
Next x
Next y
EndFunction
Function DrawGems()
imgGems = LoadImage("gems.png") //Load gems
for y = 0 to ARRAYX-1
for x = 0 to ARRAYY-1
if GridArray[x,y] <> 0 and MatchArray[x,y] > 0
sprGems = CreateSprite(imgGems) //Create a sprite with gems
SetSpriteAnimation(sprGems, 48, 48, 6)
SetSpriteSize (sprGems, 5, -1) //width 40% of screen
SetSpritePosition (sprGems, GetSpriteWidth(sprGems)*x+5, GetSpriteHeight(sprGems)*y+5)
SetSpriteFrame (sprGems, MatchArray[x,y])
Endif
Next x
Next y
EndFunction
////////////////////////// END DRAW //////////////////////////////
//////////////////////////////////////////////////////////////////
Function Populate() //Do board loop
for y = 0 to arrayY-1
for x = 0 to arrayX-1
if GridArray[x,y] <> 0
MatchArray[x,y]= Random(1, numPieces)
else
MatchArray[x,y]= 0
endif
next x
next y
EndFunction
Function CheckMatches()
//Empty array listaMatch
Global dim ListaMatch[] as TMatch
Global dim ListaMatch[1000] as TMatch
Matched as Integer
listaCount as Integer = 0
//Check horizontal matches Direction = 0
for y = 0 to ARRAYY-1
for x = 0 to ARRAYX-1
If GridArray[x, y] <> 0 And MatchArray[x, y] > 0
Matched = 1
while x+Matched < ARRAY_X and MatchArray[x+Matched,y] = MatchArray[x,y]
Matched = Matched + 1
EndWhile
if Matched >= 3
listaMatch[listaCount].x = x
listaMatch[listaCount].y = y
listaMatch[listaCount].Direction = 0
listaMatch[listaCount].Length = Matched
listaCount = listaCount + 1
x = x + Matched - 1
endif
endif
Next
Next
//Check vertical matches Direction = 1
for x = 0 to ARRAY_X-1
for y = 0 to ARRAY_Y-1
If GridArray[x, y] <> 0 And MatchArray[x, y] > 0
Matched = 1
while y+Matched < ARRAY_Y and MatchArray[x,y+Matched] = MatchArray[x,y]
Matched = Matched + 1
EndWhile
if Matched >= 3
listaMatch[listaCount].x = x
listaMatch[listaCount].y = y
listaMatch[listaCount].Direction = 1
listaMatch[listaCount].Length = Matched
listaCount = listaCount + 1
y = y + Matched - 1
endif
endif
Next
Next
//Count items in array listaMtach
MatchCount = 0
for i = 1 to 100
if listaMatch[i].x > 0
MatchCount = MatchCount + 1
else
exit
endif
next
EndFunction MatchCount
Function CheckComplete() //checks to see if all cells have been cleared
If Grid.SwapCount > 0
CheckCompleteOut = 0
exitfunction CheckCompleteOut
endif
For y = 0 To ARRAYY - 1
For x = 0 To ARRAYX - 1
If GridArray[x, y] > 0
CheckCompleteOut = 0
exitfunction CheckCompleteOut
endif
Next
Next
CheckCompleteOut = 1
EndFunction CheckCompleteOut
--------------------------
Doing Something