Exemplo n.º 1
0
t_bool protocol_see(t_core* core, t_player* player, t_action* action)
{
  char *view;

  if (!protocol_stack(core, player) || player->type != BOT)
    return (protocol_send(core, action, "ko\n"));
  view = player_view(player);
  protocol_send(core, action, view);
  free(view);
  return (TRUE);
}
Exemplo n.º 2
0
//font taken from http://www.fontspace.com/melifonts/sweet-cheeks
int main(int argc, char** argv) {

    sf::RenderWindow window(sf::VideoMode(WIDTH, HEIGHT), "SFML testy");
    sf::Texture tex_mask;
    tex_mask.loadFromFile("data/mask2.png");
    //sf::Sprite spr_mask(tex_mask);

    sf::Texture tex_map;
    tex_map.loadFromFile("data/map.jpg");
    sf::Sprite spr_map(tex_map);

    sf::Color mask_color = sf::Color::Cyan;

    sf::Shader shader;
    shader.loadFromFile("data/mask.frag", sf::Shader::Fragment);
    shader.setParameter("mask", tex_mask);
    shader.setParameter("texture", sf::Shader::CurrentTexture);
    shader.setParameter("mask_color", mask_color);

    sf::View view(sf::FloatRect(0,0,WIDTH,HEIGHT));
    view.setViewport(sf::FloatRect(0.75f, 0, 0.25f, 0.25f));

    sf::View player_view(sf::FloatRect(0,0,WIDTH,HEIGHT));

    sf::RenderTexture render;
    render.create(WIDTH,HEIGHT);
    sf::Sprite spr_render(render.getTexture());

    sf::RenderTexture render2;
    render2.create(WIDTH,HEIGHT);
    sf::Sprite spr_render2(render2.getTexture());


    int speed = 5;
    while (window.isOpen()) {
        sf::Event event;        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed)
                window.close();
            else if(event.type == sf::Event::KeyPressed) {
                switch(event.key.code) {
                    case sf::Keyboard::Escape:
                    {
                        window.close();
                    } break;
                    case sf::Keyboard::Up :
                    {
                        spr_map.move(0,-speed);
                    } break;
                    case sf::Keyboard::Down :
                    {
                        spr_map.move(0,speed);
                    } break;
                    case sf::Keyboard::Left :
                    {
                        spr_map.move(-speed,0);
                    } break;
                    case sf::Keyboard::Right :
                    {
                        spr_map.move(speed,0);
                    } break;

                    case sf::Keyboard::V :
                    {
                        player_view.rotate(10);
                    } break;
                    case sf::Keyboard::B :
                    {
                        player_view.rotate(-10);
                    } break;
                    default: break;
                }
            }
        }

        {
            render.clear(sf::Color::Red);
            sf::View old_view = window.getView();
            render.setView(player_view);
            render.draw(spr_map);
            render.setView(old_view);
            render.display();
        }
        {
            render2.clear(sf::Color(0,0,0,0));
            sf::View old_view = window.getView();
            view.setCenter(player_view.getCenter());
            render2.setView(view);
            render2.draw(spr_render,&shader);
            render2.setView(old_view);
            render2.display();
        }


        window.clear();
        window.draw(spr_render);
        window.draw(spr_render2);
        window.display();
    }
    return 0;
}
int main()
{
	// Create the main window 
	sf::RenderWindow window(sf::VideoMode(800, 600, 32), "Focus camera on player");
	sf::RenderWindow *pWindow = &window;
	sf::View player_view(sf::FloatRect(0, 0, window.getSize().x, window.getSize().y));
	//player_view.zoom(0.5f);
	unsigned int size = 100;
	sf::View minimap(sf::FloatRect(player_view.getCenter().x, player_view.getCenter().y, size, window.getSize().y*size / window.getSize().x));
	minimap.setViewport(sf::FloatRect(1.f - (1.f*minimap.getSize().x) / window.getSize().x - 0.02f, 1.f - (1.f*minimap.getSize().y) / window.getSize().y - 0.02f, (1.f*minimap.getSize().x) / window.getSize().x, (1.f*minimap.getSize().y) / window.getSize().y));
	minimap.zoom(4.f);

	//load a font
	sf::Font font;
	font.loadFromFile("C:\\Windows\\Fonts\\GARA.TTF");

	Player* p = new Player();

	sf::Sprite background;
	sf::Texture backgroundTexture;
	backgroundTexture.loadFromFile("Assets/testingBackground.png");
	background.setTexture(backgroundTexture);
	background.setPosition(sf::Vector2f(-600, -300));

	sf::Sprite background2;
	sf::Texture backgroundTexture2;
	backgroundTexture2.loadFromFile("Assets/minmap.png");//minimap
	background2.setTexture(backgroundTexture2);
	background2.setPosition(sf::Vector2f(-600, -300));

	player_view.setViewport(sf::FloatRect(0, 0, 1, 1));
	//minimapView.setViewport(sf::FloatRect(0.75f, 0, 0.25f, 0.25f));

	// Start game loop 
	while (window.isOpen())
	{
		// Process events 
		sf::Event Event;
		while (window.pollEvent(Event))
		{
			// Close window : exit 
			if (Event.type == sf::Event::Closed)
				window.close();

			// Escape key : exit 
			if ((Event.type == sf::Event::KeyPressed) && (Event.key.code == sf::Keyboard::Escape))
				window.close();


		}

		player_view.setCenter(p->getPosition());
		window.setView(player_view);

		p->Update();
		//prepare frame
		window.clear();
		
		//draw frame items
		window.draw(background);
		p->draw(*pWindow);
		window.setView(minimap);
		minimap.setCenter(p->getPosition());
		//background.setColor(sf::Color::Blue);
		window.draw(background2);//2
		p->draw(*pWindow);

		// Finally, display rendered frame on screen 
		window.display();
	} //loop back for next frame

	return EXIT_SUCCESS;
}