The Daily Click ::. Forums ::. Klik Coding Help ::. Help me with this jamagic code!
 

Post Reply  Post Oekaki 
 

Posted By Message

Dogzer



Registered
  07/02/2011
Points
  1029
8th April, 2004 at 16:09:32 -

//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;
}
}

 
n/a

Shen

Possibly Insane

Registered
  14/05/2002
Points
  3497
8th April, 2004 at 16:49:02 -

What line does it give you the error on? What is the x and what is the y?

 
gone fishin'

Dogzer



Registered
  07/02/2011
Points
  1029
8th April, 2004 at 17:34:38 -

run it on jamagic.. and make a random 32x32 image called "grass01"

 
n/a

Dogzer



Registered
  07/02/2011
Points
  1029
8th April, 2004 at 17:35:05 -

run it on jamagic.. and make a random 32x32 image called "grass01"

the line is: bgimg.Copy(level[x,y],x*32,y*32,0,0,32,32);


www.morphlings.com/jose/grass01.bmp

Image Edited by the Author.

 
n/a

Shen

Possibly Insane

Registered
  14/05/2002
Points
  3497
8th April, 2004 at 18:15:24 -

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.

 
gone fishin'

Kramy



Registered
  08/06/2002
Points
  1888
9th April, 2004 at 12:58:08 -

You can access all of your surface commands through a window.

MainWindow.setautorefresh(false);
is the same as
MainSurface.setautorefresh(false);

The only difference is using a single Window or object makes more sense to the reader.

 
Kramy
   

Post Reply



 



Advertisement

Worth A Click