Wednesday 3 December 2014

Game Engines Blog 5 - level editor



 We've pretty much finished out prototype for this semester's GDW. It has a tutorial and all of our gameplay mechanics implemented.

 

So for our offline tool I've implemented a level editor that allows you to move around and manipulate various gameplay triggers like spawn points and to be able to save their positions to a text file.

Here's some of the code for reading the spawn positions.

core_str::String fileSource;
    core_str::String fpath("/Save/Multiplayer_Spawns.txt");
    core_io::Path filePath((GetAssetsPath() + fpath));
    core_io::FileIO_ReadB fileRead(filePath);
    fileRead.Open();
    core_str::String filecontents;
    fileRead.GetContents(filecontents);
    const char * filecontents_char;
    filecontents_char = filecontents.c_str();
    int characterIncr = 0;
    int posIncr = 0;
    char character[50];
    for (int i = 0; i < 50; i++)
    {
        if (filecontents_char[i] == '-' ||
            filecontents_char[i] == '0' ||
            filecontents_char[i] == '1' ||
            filecontents_char[i] == '2' ||
            filecontents_char[i] == '3' ||
            filecontents_char[i] == '4' ||
            filecontents_char[i] == '5' ||
            filecontents_char[i] == '6' ||
            filecontents_char[i] == '7' ||
            filecontents_char[i] == '8' ||
            filecontents_char[i] == '9')
        {
            character[characterIncr] = filecontents_char[i];
            characterIncr++;
        }
           
        if (filecontents_char[i] == ',')
        {
            //convert to number
            characterIncr = 0;
            float number;
            number = (float)atoi(character);
           
            if (posIncr < 3)
                spawn_beacon[0].pos[posIncr] = number;
            else
                spawn_beacon[1].pos[posIncr - 3] = number;
            posIncr++;
            for (int a = 0; a < 20; a++)
            {
                character[a] = ',';
            }
           
        }
    }
    fileRead.Close();


and writing

core_str::String fileSource;
        core_str::String fpath("/Save/Multiplayer_Spawns.txt");
        core_io::Path filePath((GetAssetsPath() + fpath));
        core_io::FileIO_ReadAndWriteEmptyB fileWrite(filePath);
        fileWrite.Open();
        for (int x = 0; x < 2; x++)
            for (int i = 0; i < 3; i++)
            {
                char text[32];
                int num = (int)spawn_beacon[x].pos[i];
                sprintf(text, "%d", num);
                core_str::String line = core_str::Format(text);
                fileWrite.Write(line);

                fileWrite.Write(",");
            }
   
        fileWrite.Close();