Page 1 of 2

Example - load maps from ext. file

PostPosted: Mon Aug 04, 2008 7:55 pm
by Eliminator
this example shows how to make a level loading from external file and custom levels.

-all maps are 8x5 (you can change it in the source code, global->vars.) world[x][y]
-maplist must be saved in "maps.txt" file.
-maximum 10 maps in maplist. you can change this value in the view->create actor->script editor.
for(i=0;i<10;i++) //<<==Change this
{
fscanf(maps,"%s\n",mapname[i]);
}


-Dummy map:
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,

0 - nothing
1 - wall
2 - guy*
3 - portal 2 the next level*
*-must be 1 on each level

-you can add a new level actors and objects in global->creator:
example:

if(world[i][j]==4)
{
CreateActor("wall2", "wall2", "(none)", "(none)", mapX, mapY, false);
{

of course, u must create an "wall2" actor with anim. name "wall2". and don't forget to add these
objects to global->Destroyer.


...and don't laugh about the hero name...

Re: Example - load maps from ext. file

PostPosted: Tue Aug 05, 2008 12:48 pm
by speckford123
hey, nice work
i was thinking of making something like this but i guess you beat me to it
point for you :D

Re: Example - load maps from ext. file

PostPosted: Tue Aug 26, 2008 5:26 pm
by moonmoon
good job. :lol:

Re: Example - load maps from ext. file

PostPosted: Mon Sep 01, 2008 6:23 pm
by Lexcondran
wow im confused and have no idea what to do Ploos theres no noises and you did do a good job but iguess im not experienced enough to make my own level this confuses me :D

Re: Example - load maps from ext. file

PostPosted: Sat Sep 06, 2008 8:57 am
by Lexcondran
i have figured this stuff out and made something cool but still im wondering how to make this random.
so i changed the sizes from the small ness to 50x50 level rooms. and im messed it up and the map name thing does not appear or any other words.

Re: Example - load maps from ext. file

PostPosted: Sun Nov 02, 2008 3:12 am
by supa-tails
COUNTER STRIKE FTW! XD Im about to test this.

Re: Example - load maps from ext. file

PostPosted: Fri Feb 20, 2009 1:28 am
by jimmynewguy
guess this is a bumb, oh well, but anyway
how do you actually make a map? i feel kind of stupid but like in the script editor what would i put it i wanted a map like idk
ex.

2,0,0,0,0,0,0,0,
1,1,1,1,1,1,0,0,
0,0,0,0,0,0,0,0,
1,0,1,1,1,1,1,0,
0,3,0,0,0,0,0,0,

what would i do to save that as like level_1 for example, make an array variable? :roll: im confuzled :lol:

Re: Example - load maps from ext. file

PostPosted: Mon Feb 23, 2009 8:42 pm
by 4erv'
Okay, two questions:
1. what this "%s\n" means in fscanf(maps,"%s\n",mapname[i]);?
2. what the function MapL(); do?
:D

Re: Example - load maps from ext. file

PostPosted: Tue Feb 24, 2009 1:46 am
by skydereign
1. what this "%s\n" means in fscanf(maps,"%s\n",mapname[i]);?
It is the 'rules' fscanf follows or looks for. %s scans a string until \n, which is a newline.

2. what the function MapL(); do?
It loads the map by creating the actors, from a file.
Code: Select all
void MapL()
{
FILE *map = fopen(curmap, "r"); // sets map to direct into the file
mapX=0; // sets the x and y to 0
mapY=0;

    for(i=0;i<sizeY;i++)   // nested for loop to obtain xy coordinates
    {
        for(j=0;j<sizeX;j++)
        {
            fscanf(map,"%d, ",&world[i][j]);  // scans into map file, looks for an int; signed decimal notation
            if(world[i][j]==1) // If that ij is 1, create actor 1
            {
                CreateActor("FON", "FON", "(none)", "(none)", mapX, mapY, false);
            }
            if(world[i][j]==2) // If that ij is 1, create actor 2
            {
                CreateActor("Dollfucker", "st3_25x60", "(none)", "(none)", mapX, mapY, false);
            }
            if(world[i][j]==3) // If that ij is 1, create actor 3
            {
                CreateActor("portal", "portal", "(none)", "(none)", mapX, mapY, false);
            }
            mapX+=40; // Then move mapX for placement
        }
    mapX=0;  // after all x for the row is done, reset x and increase y, and repeat
    mapY+=40;
    }
    sprintf(cDEBUG.text,"MAP:%s",curmap);  // prints the map name
fclose(map); // closes map
}

Re: Example - load maps from ext. file

PostPosted: Tue Feb 24, 2009 7:26 pm
by 4erv'
Thank you! :D
+1 point

Re: Example - load maps from ext. file

PostPosted: Mon Jun 01, 2009 9:21 am
by Bee-Ant
I love this demo and using the method for my current game.
But i have a problem with 3 digit number. I mean :
125,658,425,133,966,546,
546,872,111,105,613,525,
466,651,826,136,665,251,
646,883,852,564,369,964,
etc
I use 75x75 array. But GE always stopped working everytime i click GameMode.
Whats wrong?
Anyone who knows this stuff,may i have your email address?thanx :D

Bee

Re: Example - load maps from ext. file

PostPosted: Mon Jun 01, 2009 9:32 am
by skydereign
3 digit numbers shouldn't be a problem, and I am assuming that your grid is 75x75, each place holds a three digit number. I can help you out, or just post a demo of it working for me. Are you trying just to hold ints? Or are you trying to save and load?

Re: Example - load maps from ext. file

PostPosted: Mon Jun 01, 2009 10:25 am
by Bee-Ant
Too complicated to explain..
I will just send you the demo, and check it yourself.
Thanx :D

Edit: i mean,GE stopped working when you exit from GameMode.
I can load the map,but ugly..
Im so sure i put the right code and array.

Re: Example - load maps from ext. file

PostPosted: Tue Jun 02, 2009 2:22 pm
by Bee-Ant
I have tested the function so many times, and there's a problem when loading high arrays. I tried use 75x75 and put the same number for each i and j. Theres 1 blank spot at 12,0 and 1 error spot(something like in this spot doesnt recognize any animation changing),and there are 15 blank spots in the end of arrays. It should make total square background right?but it doesnt. When i use 50x50,there's only 1 error spot, but makes total square background.

So i assume that this function capable to handle at low arrays only. I think below 50.

I thought that i misscalculate my arrays. Because when i use 75x75 the background cropped at j=15.

Oh yah,anyone knows how to use pointer at this stuff?using high array such wasting memory...

Thanx.

Re: Example - load maps from ext. file

PostPosted: Tue Jun 02, 2009 5:48 pm
by Bee-Ant
Ah, one more thing...
This function doesnt work on exported game.
I can use it on project mode only...
Hhh,i wonder why this happening...