Example #1
0
Simulation::Simulation(STATE previous) : StateMachine(previous, GAMEPLAY, GAMEPLAY)
{
    printf("Starting Simulation...\n");
    gameRunning = true;
    simulationSTATE = _SIM_CONTINUE_;
    Resource *resource = Game::getGlobalGame()->getResourceMNGR();
    int screenWidth = Game::getGlobalGame()->getWidth();
    int screenHeight = Game::getGlobalGame()->getHeight();

    resource->AddImage("assets/base.gfx", "simulation-bg-Far");
    resource->AddImage("assets/base.gfx", "simulation-bg-Mid");
    resource->AddImage("assets/base.gfx", "simulation-bg-Close");
    resource->AddImage("assets/base.gfx", "simulation-bg-Nebula");
    resource->AddImage("assets/army.gfx", "human-ships");

    background[0] = resource->GetImage("simulation-bg-Far");
    background[1] = resource->GetImage("simulation-bg-Mid");
    background[2] = resource->GetImage("simulation-bg-Close");
    background[3] = resource->GetImage("simulation-bg-Nebula");
//
    SDL_SetTextureBlendMode(background[0]->getSDLTexture(), SDL_BLENDMODE_ADD);
    SDL_SetTextureBlendMode(background[1]->getSDLTexture(), SDL_BLENDMODE_ADD);
    SDL_SetTextureBlendMode(background[2]->getSDLTexture(), SDL_BLENDMODE_ADD);
    SDL_SetTextureBlendMode(background[3]->getSDLTexture(), SDL_BLENDMODE_ADD);

    if (!Game::getGlobalGame()->getArmy1()){
    	printf ("primeiro ponteiro nulo\n");
    }else if (!Game::getGlobalGame()->getArmy2()){
        printf ("segundo ponteiro nulo\n");
    }else{
    	printf ("ambos nao nulos");
    }
    //simulationWorld = new World("rbrararb", "rarbrbra");
    Game::getGlobalGame()->generateSprites(Game::getGlobalGame()->getArmy1()->getDictionary());
    Game::getGlobalGame()->generateSprites(Game::getGlobalGame()->getArmy2()->getDictionary());
    simulationWorld = new World(Game::getGlobalGame()->getArmy1(), Game::getGlobalGame()->getArmy2());

    camera = new Camera(0, 0, screenWidth, screenHeight, screenWidth*2, screenHeight*1.5f);
    bgOffsetX = bgOffsetY = 0;

    renderCombat = SDL_CreateTexture(Game::getGlobalGame()->getRenderer(), SDL_PIXELFORMAT_RGBA8888,
                        SDL_TEXTUREACCESS_TARGET, 2048, 2048);

    if(renderCombat == NULL)
    {
        printf("SDL_CreateTexture failed: %s\n", SDL_GetError());
        exit(-9);
    }

    selectedUnit = NULL;
    printf("Simulation Ready!\n");
}
Example #2
0
int Dictionary::loadDictionary(const char *inputFile, Resource &resource)
{
    fstream dictInput(inputFile, fstream::in);
    if (!dictInput.is_open())
    {
        printf("Arquivo de configuracao nao pode ser carregado: %s\n", inputFile);
        return -1;
    }

    printf("Loading Dictionary: %s\n", inputFile);
    title = inputFile;
    title = title.substr( 0, title.find_last_of('.') );
    title = title.substr( title.find_last_of("\\/")+1 );
    printf("\tName: %s\n", title.c_str());

    while (!dictInput.eof())
    {
        string tag;
        dictInput >> tag;
        if (tag == "gfxShips:")
        {
            string tmp;

            dictInput >> tag;
            dictInput >> tmp;

            baseGFX = resource.AddImage(tag.c_str(), tmp);
//            printf("Path: %s, Key: %s, %p\n", path.c_str(), tmp.c_str(), shipsGFX);
        }
        else if (tag == "DESCRP:")