Jump to content

LoadMap does not load saved in program code map and even remove light


Dreikblack
 Share

Recommended Posts

After save:

image.thumb.png.10b7727763f037b7873e4eb250254f4e.png

After load:

image.thumb.png.859e2d7cdd7737608981a5499bd45b5d.png

#include "UltraEngine.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    //Get the displays
    auto displays = GetDisplays();

    //Create a window
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);

    //Create a world
    auto world = CreateWorld();

    //Create a framebuffer
    auto framebuffer = CreateFramebuffer(window);

    //Create a camera    
    auto camera = CreateCamera(world);
    camera->SetClearColor(0.125);
    camera->SetPosition(0, 1, -4);

    //Create light
    auto light = CreateBoxLight(world);
    light->SetRange(-10, 10);
    light->SetArea(15, 15);
    light->SetRotation(45, 35, 0);
    light->SetColor(2);

    //Create the ground
    auto ground = CreateBox(world, 20, 1, 20);
    ground->SetPosition(0, -0.5, 0);
    ground->SetColor(0, 1, 0);

    //Create a scene
    auto scene0 = CreateMap();
    scene0->AddEntity(ground);
    scene0->AddEntity(light);
    ground = NULL;
    light = NULL;

    auto scene = CreateMap();
    //Add some boxes
    for (int n = 0; n < 2; ++n)
    {
        auto box = CreateBox(world);
        box->SetColor(0, 0, 1);
        box->SetPosition(Random(-5, 5), Random(5, 10), Random(-5, 5));
        box->SetMass(1);
        scene->AddEntity(box);
    }

    //Main loop
    while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false)
    {
        if (window->KeyHit(KEY_A))
        {
            auto box = CreateBox(world);
            box->SetColor(1, 0, 1);
            box->SetPosition(1, 1, 1);
            box->SetMass(1);
            scene->AddEntity(box);
        }
        if (window->KeyHit(KEY_D))
		{
			for (auto box : scene->entities)
			{
                if (box->As<Model>())
                    scene->RemoveEntity(box);
                break;
			}
        }
        if (window->KeyHit(KEY_S))
        {
            //Save the scene to a file
            scene->Save("game.sav");
        }
        //Load the scene when space key is pressed
        if (window->KeyHit(KEY_SPACE))
        {
            scene = LoadMap(world, "game.sav");
        }

        world->Update();
        world->Render(framebuffer);
    }
    return 0;
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...