GP32 Creating A Level Editor In Fenix


Bampt

Member
Joined
Mar 29, 2005
Messages
115
Location
Germany
Website
nextadventures.webs.com
Creating a Level Editor in Fenix

the basics:
First at all you´ll need to create a structure:
STRUCT lx[(Number of fields horizontal)]
ly[(Number of fields vertical)];
END
First choose your grid size.
if you want 20*20 Pixels as grid size and your levelmapsize is 500*500 you´ll need 25 fields horizontal and 25 fields vertical.
You could also add to the structure:
STRUCT lx[25]
ly[25];
en[25];
END
So you could also position some enemys on your map
or Items or other special things.


The Editor enviroment:
Now you have to do some graphical work...
Make a Map as big as your grid size and draw a white hollow rectangle on it.
This will be used as your coursor. Then you have to make 2 different fields for your level map(just in a hurry to see if the editor is working so far).

Now the coding part:
PROGRAM leveleditor;
GLOBAL
STRUCT lx[25]
ly[25];
en[25];
END
lmap;// Used as map identifier for your levelmap
xm;
ym;//See above
BEGIN
set_mode(m320x240);// 320x240 resolution
load_fpg("game.fpg");
lmap=new_map(500,500,8);// 500 for X and Y size and 8 for 8bit graphic
start_scroll(0,0,lmap,0,0,0);// Just to overview the whole levelmap
sel();
END

Now we call a process which gives you control over the whole thing over your mouse
here called: sel().

PROCESS sel();
PRIVATE
t=0;
fn=1;//For changing your fields
mgr;//identifier for your coursor graph
BEGIN
mgr=new_map(20,20,8);

REPEAT

map_put(0,mgr,99+fn,10,10);
map_put(0,mgr,(your coursor number),10,10);//It puts first the selected field on the coursor graph and the the white hollow rectangle is put above it
graph=mgr;

t++;
IF(KEY(_LEFT)&t>4) fn=fn-1;t=0;end
IF(KEY(_RIGHT)&t>4) fn=fn+1;t=0;end
IF(fn<1) fn=1;END//Makes you able to select different fields to put. It goes from 1 to endless

X=MOUSE.X;
Y=MOUSE.Y;//Get the mouse´s coordinates

IF(X>310) SCROLL.X0+=20;END
IF(X<10) SCROLL.X0-=20;END
IF(Y>230) SCROLL.Y0+=20;END
IF(Y<10)SCROLL.Y0-=20;END//Makes you scroll along with your mouse

X=X/20;
Y=Y/20;
X=X*20;
Y=Y*20;//Makes your coursor stay in the grid frequence

X=X+10;
Y=Y+10;//Just to adjust your coursor perfect to the grid

IF(MOUSE.LEFT)
MAP_PUT(0,lmap,99+fn,X+SCROLL.X0,Y+SCROLL.Y0);//Puts your graphic on your level Map
lx[(X+SCROLL.X0)/20].ly[(Y+SCROLL.Y0)/20]=fn;//Gives your structure the new information for the specific point.
END
IF(KEY(_S)) SAVE("level1.lvl",lx);END//Lets you save your work.
FRAME;
UNTIL(KEY(_esc))
END

Let the Editor load your level

Go to the head of the Program and put the following commands beneath the lmap=new_map(); command:

load("level1.lvl",lx);
for(xm=0;xm<25;xm++)
for(ym=0;ym<25;ym++)
IF(lx[xm].ly[ym]>0)
MAP_PUT(0,lmap,lx[xm].ly[ym]+99,(xm*20)+10,(ym*20)+10);
END
END
END
This loads your saved level and puts it on your levelmap

If there are any questions about this please e-mail me:
Nabz_2@freenet.de B)
 

Quiest

I like turtles!
Joined
Sep 2, 2004
Messages
3,411
Age
38
Location
Dteuschland ;)
Oh, thanks alot!

I`m too tired to read all now, but this also seems to be like a good tutorial of how to work with structs.

Very handy! :)
 
Top