None of your NEXT statements have a variable. I would think that would cause an error.
Off hand, I can't see why anything would end up with an index of -1. Also, you have a lot of globals that I don't think need to be global, such as cubeDirection. You can easily make that a function parameter and pass it that way.
An option to figure this out would be to comment out sections of code and run it. Try to narrow down what piece of code is causing the error. Yes line 188 says it has the error but the problem could lie elsewhere and just cascade down to that spot.
I've corrected your code tag and indentation
SetErrorMode(2)
Global gWidth as integer
Global gHeight as integer
Global gFullScreen as integer
Global gAllowResize as integer
Global vWidth as integer
Global vHeight as integer
gWidth = GetDeviceWidth()
gHeight = GetDeviceHeight()
gFullScreen = 0
gAllowResize = 0
// set window properties
SetWindowTitle( "g" )
SetWindowSize( gWidth, gHeight, gFullScreen )
SetWindowAllowResize( gAllowResize ) // allow the user to resize the window
vWidth = 1024
vHeight = 768
// set display properties
SetVirtualResolution( vWidth, vHeight) // doesn't have to match the window
SetOrientationAllowed( 0, 1, 0, 0 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 60, 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
#include "Constants.agc"
Global imgTileAtlas
imgTileAtlas = LoadImage("tiles.png")
//Global GreyCube = 1
Global RedCube = 2
//Global OrangeCube = 3
//Global YellowCube = 4
//Global GreenCube = 5
//Global BlueCube = 6
//Global PurpleCube = 7
//Global PinkCube = 8
Global GreyCube
//Global RedCube
Global OrangeCube
Global YellowCube
Global GreenCube
Global BlueCube
Global PurpleCube
Global PinkCube
Global GameTileArrayStartX as integer
Global GameTileArrayStartY as integer
GameTileArrayStartX = -64
GameTileArrayStartY = -64
Global GameTileArray as integer[16,14]
Global LevelFile
Global LevelData as string
LevelFile = OpenToRead("levels/level1.txt")
LevelData = ReadLine(LevelFile)
CloseFile(LevelFile)
Global tx as integer
global ty as integer
for xiter = 1 to Len(LevelData)
if tx = 16
tx = 0
ty = ty + 1
endif
GameTileArray[tx,ty] = val(Mid(LevelData,xiter, 1))
tx = tx + 1
next xiter
Type Cube
id as integer
sprite as integer
x as float
y as float
speed as float
thrust as float
gravity as float
hasStopped as integer
canMove as integer
isMoving as integer
endtype
Global RedCubeList as Cube[]
Global GreyCubeList as Cube[]
for x = 0 to 15
for y = 0 to 13
if GameTileArray[x,y] = 1
local gc as Cube
gc.id = 1
gc.x = GameTileArrayStartX + x * 64
gc.y = GameTileArrayStartY + y * 64
gc.sprite = CreateSprite(imgTileAtlas)
SetSpriteAnimation(gc.sprite, 64, 64, 1)
GreyCubeList.insert(gc)
endif
if GameTileArray[x,y] = 2
local rc as Cube
rc.id = 2
rc.canMove = 1
rc.hasStopped = 1
rc.isMoving = 0
rc.thrust = 10
rc.gravity = 0.5
rc.x = GameTileArrayStartX + x * 64
rc.y = GameTileArrayStartY + y * 64
rc.sprite = CreateSprite(imgTileAtlas)
SetSpriteActive(rc.sprite, 1)
SetSpriteAnimation(rc.sprite, 64, 64, 2)
PlaySprite(rc.sprite, 1, 1, 2, 2)
RedCubeList.insert(rc)
TotalNumberOfNonGreyCubes = TotalNumberOfNonGreyCubes + 1
endif
next y
next x
for xrc = 0 to RedCubeList.length
SetSpritePosition(RedCubeList[xrc].sprite, RedCubeList[xrc].x, RedCubeList[xrc].y)
next xrc
for grc = 0 to GreyCubeList.length
SetSpritePosition(GreyCubeList[grc].sprite, GreyCubeList[grc].x, GreyCubeList[grc].y)
next grc
Global TotalNumberOfNonGreyCubes as integer
Global TotalCubesMoving as integer
global CubeDirection as integer
CubeDirection = -1
do
//print (TotalCubesMoving)
//print (TotalNumberOfNonGreyCubes)
print (RedCubeList.length)
if GetRawKeyPressed(Key_Left) = 1 and CubeDirection = -1
CubeDirection = 0
for xrc2 = 0 to RedCubeList.length
RedCubeList[xrc2].hasStopped = 0
next xrc2
TotalCubesMoving = TotalNumberOfNonGreyCubes
endif
MoveCubes()
Print( ScreenFPS() )
Sync()
loop
function MoveCubes()
If CubeDirection = 0
MoveCubesLeft()
endif
endfunction
function MoveCubesLeft()
for xrc = 0 to RedCubeList.length
//Print(Round(RedCubeList[xrc].x / 64 - 1 ))
SetSpritePosition(RedCubeList[xrc].sprite, RedCubeList[xrc].x, RedCubeList[xrc].y)
if RedCubeList[xrc].hasStopped = 0
RedCubeList[xrc].x = RedCubeList[xrc].x - RedCubeList[xrc].thrust
RedCubeList[xrc].thrust = RedCubeList[xrc].thrust + RedCubeList[xrc].gravity
local tx as integer
local ty as integer
tx = RedCubeList[xrc].x / 64
ty = RedCubeList[xrc].y / 64
print (tx)
print (ty)
if GameTileArray[tx,ty] = 1
if mod(RedCubeList[xrc].x, 64) < RedCubeList[xrc].thrust * 2
RedCubeList[xrc].x = RedCubeList[xrc].x - mod(RedCubeList[xrc].x, 64)
RedCubeList[xrc].isMoving = 0
RedCubeList[xrc].hasStopped = 1
RedCubeList[xrc].thrust = 10
TotalCubesMoving = TotalCubesMoving - 1
endif
endif
endif
next xrc
EndFunction