Example #1
0
bool GuiDemo::setup(void)
{
	gkBlendFile* blend = gkBlendLoader::getSingleton().loadFile(gkUtils::getFile(m_blend), "", GUIDEMO_GROUP_NAME);
	if (!blend)
	{
		gkPrintf("File loading failed.\n");
		return false;
	}

	m_scene = blend->getMainScene();
	if (!m_scene)
	{
		gkPrintf("No usable scenes found in blend.\n");
		return false;
	}


	m_scene->createInstance();

	// add input hooks
	gkWindowSystem::getSingleton().addListener(this);

	gkBlendLoader::getSingleton().loadFile(gkUtils::getFile(ASSETS_BLEND_FILE), "", GUIDEMO_GROUP_NAME);

	loadGUI();


	return true;
}
Example #2
0
owperGUI::owperGUI(string initHivePath/*=""*/, samHive* preloadedSam/*=NULL*/) {
    sam = NULL;
    loadGUI();

    if(!initHivePath.empty()) {
        changeHiveFile(initHivePath, preloadedSam);
    }
}
Example #3
0
// inizializza le risorse per il gioco
void gameinit() {
	if (SDLSetup(&surf))
		exit(2);

	// re-inizializzazione GUI
	void (*calls[])(void) = {menuExit, menuReturn, menuNewGame, menuOptions};
	if (loadGUI(calls))
		exit(4);

	// re-inizializzazione OpenGL
	glViewport(0, 0, scrW, scrH);

	if(options.mblur)
		glClear(GL_ACCUM_BUFFER_BIT);

	glEnable(GL_DEPTH_TEST);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	glEnable(GL_CULL_FACE);
}
Example #4
0
GameState::GameState() : State(STATE_GAME)
{
	// load art service for queueing
	auto animationService = new AnimationService;
	Locator::provide(SERVICE_ANIMATION, animationService);

	// load entities
	auto entityService = new EntityService;
	Locator::provide(SERVICE_ENTITY, entityService);

	// load gui in a really shady way
	animationService->loadGUI();

	// load art
	animationService->processQueuedSprites();

	// load world
	WorldService *worldService = new WorldService(Config::getString("debug.world-name"),
												  Config::getResource("world.tileset"));
	Locator::provide(SERVICE_WORLD, worldService);

	world = &worldService->getWorld();

	// load camera
	Locator::provide(SERVICE_CAMERA, new CameraService(*world));

	// create some humans
	int count = Config::getInt("debug.humans.count");

	for (int i = 0; i < count; ++i)
	{
		int x = Utils::random(0, world->getTileSize().x);
		int y = Utils::random(0, world->getTileSize().y);

		createTestHuman(*world, x, y, animationService->getRandomAnimationName(ENTITY_HUMAN), Direction::random());
	}
}
Example #5
0
int main(void){
    bool Continue = true;
    sf::VideoMode vm = sf::VideoMode(800, 600);
    sf::RenderWindow App(vm, "Maze",sf::Style::Default);
    while(Continue){
        sf::View view = App.getDefaultView();
        App.setView(view);
        unsigned int row = 100;
        unsigned int col = 100;
        float randomness = 0.5f;
        float binomial = 0.0f;
        bool isIsometric = false;
        {
            Menu modeSelection(App);
            while(!modeSelection.isReady()){
                modeSelection.handleInput();
                modeSelection.render();
            }
            isIsometric = modeSelection.isIsometric();
            Continue = modeSelection.wantToContinue();
            if(!Continue){
                break;
            }
        }
        // textures
        std::vector<sf::Texture> texs;
        if(isIsometric){
            sf::Texture t;
            t.loadFromFile("data/landscapeTiles_067.png");
            texs.emplace_back(t);
            sf::Texture t2;
            t2.loadFromFile("data/landscapeTiles_036.png");
            texs.emplace_back(t2);
        }else{
            sf::Texture t;
            t.loadFromFile("data/floor.jpg");
            texs.emplace_back(t);
            sf::Texture t2;
            t2.loadFromFile("data/Shrub.jpg");
            texs.emplace_back(t2);
        }
        //row = App.getSize().x / (texs[0].getSize().x / 2) * 5;
        //col = App.getSize().y / (texs[0].getSize().y / 2) * 5;
        auto m = createGrid(texs,row,col,isIsometric);
        Graph g;
        auto cgThread = std::thread([&](){
            createGraph(&g,m);
        });
        sf::Texture buttonTexture;
        buttonTexture.loadFromFile("data/button.png");
        sf::Font font;
        font.loadFromFile("data/Outwrite.ttf");
        auto buttons = loadGUI(buttonTexture,font);
        Tile* origen = nullptr;
        Tile* dest = nullptr;
        bool running = true;
        unsigned int currentFingerID = 0;
        int currentX = 0;
        int currentY = 0;
        float zoomLevel = 0;
        float oldDistance = 0;
        bool settingOrigen = false;
        bool settingDest = false;
        std::vector<sf::Event::TouchEvent> touchEvents;
        cgThread.join();
        /// set buttons actions
        buttons[0].setAction([&](){
            if(origen){
                origen->setColor(sf::Color::Cyan);
                std::thread([&](){
                    g.genMaze(g.getNode(origen),randomness,sf::Sprite(texs[1]),binomial);
                }).detach();
            }else if(dest){
                dest->setColor(sf::Color::Cyan);
                std::thread([&](){
                    g.genMaze(g.getNode(dest),randomness,sf::Sprite(texs[1]),binomial);
                }).detach();
            }
        });
        buttons[1].setAction([&](){
            settingOrigen = true;
        });
        buttons[2].setAction([&](){
            settingDest = true;
        });
        buttons[3].setAction([&](){
           if(origen && dest){
               std::thread([&](){
                    g.aStar(g.getNode(origen),g.getNode(dest)); 
               }).detach();
           }
        });
        buttons[4].setAction([&](){
            if(origen && dest){
               std::thread([&](){
                    g.bfs(g.getNode(origen),g.getNode(dest)); 
               }).detach();
           }
        });
        buttons[5].setAction([&](){
            if(origen && dest){
               std::thread([&](){
                    g.gbfs(g.getNode(origen),g.getNode(dest)); 
               }).detach();
           }
        });
        buttons[6].setAction([&](){
            if(origen && dest){
               std::thread([&](){
                    g.dfs(g.getNode(origen),g.getNode(dest)); 
               }).detach();
           }
        });
        while(running){
            sf::Event event;
            while(App.pollEvent(event)){
                switch(event.type){
                    case sf::Event::Closed:
                            running = false;
                        break;
                    case sf::Event::MouseEntered:
                    case sf::Event::KeyReleased:
                        if(event.key.code == sf::Keyboard::Escape){
                            running = false;
                        }
                        if(event.key.code == sf::Keyboard::Down){
                            auto v = App.getView();
                            v.move(0,100);
                            App.setView(v);
                        }
                        if(event.key.code == sf::Keyboard::Up){
                            auto v = App.getView();
                            v.move(0,-100);
                            App.setView(v);
                        }
                        if(event.key.code == sf::Keyboard::Right){
                            auto v = App.getView();
                            v.move(100,0);
                            App.setView(v);
                        }
                        if(event.key.code == sf::Keyboard::Left){
                            auto v = App.getView();
                            v.move(-100,0);
                            App.setView(v);
                        }
                        break;
                    case sf::Event::LostFocus:
                    case sf::Event::MouseLeft:
                            running = false;
                        break;
                    case sf::Event::TouchBegan:
                            touchEvents.emplace_back(event.touch);
                        break;
                    case sf::Event::TouchMoved:{
                            if(touchEvents.size() >= 2){
                                touchEvents[event.touch.finger].x = event.touch.x;
                                touchEvents[event.touch.finger].y = event.touch.y;
                                auto diffX = touchEvents[0].x - touchEvents[1].x;
                                auto diffY = touchEvents[0].y - touchEvents[1].y;
                                auto newDistance = (diffX*diffX+diffY*diffY);
                                const auto zoomLimit = 15.0;
                                if((newDistance - oldDistance) > 10){
                                    view = App.getView();
                                    if(zoomLevel < zoomLimit){
                                        ++zoomLevel;
                                        view.zoom(0.9);
                                    }
                                    App.setView(view);
                                }else if((newDistance - oldDistance) < -10){
                                    view = App.getView();
                                    if(zoomLevel > -zoomLimit){
                                        --zoomLevel;
                                        view.zoom(1.1);
                                    }
                                    App.setView(view);
                                }
                                oldDistance = newDistance;
                            }else{
                                currentFingerID = event.touch.finger;
                                currentX = event.touch.x;
                                currentY = event.touch.y;
                                view = App.getView();
                                auto amountX = touchEvents[currentFingerID].x-currentX;
                                auto amountY = touchEvents[currentFingerID].y-currentY;
                                touchEvents[currentFingerID].x = currentX;
                                touchEvents[currentFingerID].y = currentY;
                                view.move(amountX,amountY);
                                App.setView(view);
                            }
                    }   break;
                    case sf::Event::TouchEnded:{
                            touchEvents.clear();
                            auto pos = static_cast<sf::Vector2f>(App.mapPixelToCoords(sf::Vector2i(event.touch.x,event.touch.y), App.getView()));
                            if(settingOrigen){
                                origen = getTile(m,pos);
                                if(origen){
                                    origen->setColor(sf::Color::Red);
                                }
                                settingOrigen = false;
                            }
                            if(settingDest){
                                dest = getTile(m,pos);
                                if(dest){
                                    dest->setColor(sf::Color::Blue);
                                }
                                settingDest = false;
                            }
                            view = App.getView();
                            App.setView(App.getDefaultView());
                            pos = static_cast<sf::Vector2f>(App.mapPixelToCoords(sf::Vector2i(event.touch.x,event.touch.y), App.getView()));
                            App.setView(view);
                            for(auto& b:buttons){
                                if(b.contains(pos)){
                                    b.getAction()();
                                }
                            }
                        }
                        break;
                    case sf::Event::SensorChanged:
                        break;
                    default:
                        break;
                }
            }
            App.clear(sf::Color::Black);
            for(auto i=0u;i<col;++i){
                for(auto j=0u;j<row;++j){
                    App.draw(m[i][j].getSprite());
                }
            }
            for(auto b:buttons){
                view = App.getView();
                App.setView(App.getDefaultView());
                App.draw(b);
                App.setView(view);
            }
            App.display();
        }
    }
    App.close();
    return 0;
}