//hi, it says that level[x,y] doesnt exist, weird cuz it seems to exist. What´s wrong?
mainwindow = New Window(640,480,16);
//mainwindow.SetFullScreenMode(640,480,16);
mainsurface = mainwindow.GetSurface();
mainsurface.SetAutoRefresh(OFF);
mainsurface.SetAutoBack(OFF);
//savelevel = New File();
//savelevel.Open("C:\Program Files\Jamagic\Projects\Project\savelevel.txt",File.READWRITE);
imggrass01 = New Surface("grass01");
bgimg = New Surface(1024,768,16);
drawtiles(bgimg);
bgspr = New Sprite(0,0,bgimg);
Var level[500,500] = 0;
resetlevel();
Var time = 0.0; //
bgspr = New Sprite(0,0,bgimg);
While (! Keyboard.IsKeyDown(Keyboard.ESCAPE))
{
//bgspr.Set(Display.GetScreenXMouse-mainwindow.GetX(),Display.GetScreenYMouse()-mainwindow.GetY());
bgspr.Set(0,0);
setnewtile();
time = System.GetElapsedTime();
mainsurface.EraseRect(0,0,640,480);
While(System.GetElapsedTime() < time + 33);
mainsurface.DrawText (1000 / (System.GetElapsedTime() - time) ,0,0) ;
UpdateSprites();
DrawSprites();
Refresh();
}
Function setnewtile()
{
If (Keyboard.IsKeyDown(Keyboard.LBUTTON))
{
x = mainwindow.GetXMouse() / 32;
y = mainwindow.GetYMouse() / 32;
level[x,y] = imggrass01;
bgimg.Copy(level[x,y],x*32,y*32,0,0,32,32);
drawtiles();
bgspr.Set(,,bgimg);
}
}
Function drawtiles()
{
For (y = 500; y > 0; y--)
For (x= 500; x > 0; x--)
{
If (Program.IsObject(level[x,y]) || Program.IsNumber(level[x,y]))
bgimg.Copy(level[x,y],x*32,y*32,0,0,32,32);
}
}
Function resetlevel()
{
For (y = 500; y > 0; y--)
For (x= 500; x > 0; x--)
{
level[x,y] = imggrass01;
}
}
It's your code order: You are calling drawtiles, when the array level has not been initialised yet.
mainwindow = New Window(640,480,16);
//mainwindow.SetFullScreenMode(640,480,16);
mainsurface = mainwindow.GetSurface();
mainsurface.SetAutoRefresh(OFF);
mainsurface.SetAutoBack(OFF);
imggrass01 = New Surface("grass01");
//savelevel = New File();
//savelevel.Open("C:\Program Files\Jamagic\Projects\Project\savelevel.txt",File.READWRITE);
Var level[501,501] = 0;
resetlevel();
Var time = 0.0; //
etc.
Also, go through the code, and sort it out, add indents and stuff. Most of the {s and }s are not needed, and you're calling functions with arguments that aren't needed
And there's also a Program.fillarray() function that can do some of the stuff you're doing for you.