Пример #1
0
void Renderer::createTumbler(const Maze& maze,
                             std::vector<SpritePiece>* pieces) {
  mTargetSize = maze.getSize() * CELL_SIZE;
  initTargets();

  auto cols = maze.getSize().x;
  auto rows = maze.getSize().y;
  sf::Sprite sprite;
  sprite.setTextureRect(sf::IntRect(0, 0, CELL_SIZE, CELL_SIZE));
  for (auto& target : mTargets) {
    auto view = target->getView();
    auto center = view.getCenter();
    auto pieceW = view.getSize().x;
    auto pieceH = view.getSize().y;
    auto x = center.x - pieceW / 2.0f;
    auto y = center.y - pieceH / 2.0f;
    auto vRect = sf::FloatRect(x, y, pieceW * 1.0f, pieceH * 1.0f);
    for (auto r = 0u; r < rows; ++r) {
      for (auto c = 0u; c < cols; ++c) {
        const auto& data = maze.getChipData(r, c);
        const auto& p = data.pos;
        const auto& chip = mMapchips.at(p[1]).at(p[0]);
        sprite.setTexture(chip);
        sprite.setPosition(c * CELL_SIZE * 1.0f, r * CELL_SIZE * 1.0f);
        if (vRect.intersects(sprite.getGlobalBounds())) {
          target->draw(sprite);
        }
      }
    }
  }

  createPieces(pieces);
}
Пример #2
0
void Renderer::createScreenshot(const sf::Vector2u& targetSize,
                                std::vector<SpritePiece>* pieces,
                                std::function<void(sf::RenderTarget*)> drawTo) {
  mTargetSize = targetSize;
  initTargets();
  for (auto& target : mTargets) {
    drawTo(target.get());
  }
  createPieces(pieces);
}
Пример #3
0
int main(void)
{
	GLFWwindow* window; //WskaŸnik na obiekt reprezentuj¹cy okno
	std::cout << "lol"<<std::endl;

	glfwSetErrorCallback(error_callback);//Zarejestruj procedurê obs³ugi b³êdów

	if (!glfwInit()) { //Zainicjuj bibliotekê GLFW
		fprintf(stderr, "Nie mo¿na zainicjowaæ GLFW.\n");
		exit(EXIT_FAILURE); 
	}

	window = glfwCreateWindow(700, 700, "OpenGL", NULL, NULL);  //Utwórz okno 500x500 o tytule "OpenGL" i kontekst OpenGL. 

	if (!window) //Je¿eli okna nie uda³o siê utworzyæ, to zamknij program
	{
		glfwTerminate();
		exit(EXIT_FAILURE);
	}

	glfwMakeContextCurrent(window); //Od tego momentu kontekst okna staje siê aktywny i polecenia OpenGL bêd¹ dotyczyæ w³aœnie jego.
	glfwSwapInterval(1); //Czekaj na 1 powrót plamki przed pokazaniem ukrytego bufora
	glfwSetKeyCallback(window, key_callback);

	if (glewInit() != GLEW_OK) { //Zainicjuj bibliotekê GLEW
		fprintf(stderr, "Nie mo¿na zainicjowaæ GLEW.\n");
		exit(EXIT_FAILURE);
	}

	initOpenGLProgram(window); //Operacje inicjuj¹ce

	float angle = 0; //K¹t obrotu torusa
	glfwSetTime(0); //Wyzeruj licznik czasu

	initTargets();

	//G³ówna pêtla
	while (!glfwWindowShouldClose(window)) //Tak d³ugo jak okno nie powinno zostaæ zamkniête
	{
		//std::cout << glfwGetTime()<<std::endl;
		ship.moveCamera(glfwGetTime(), nextMove);
		rotateTargets(glfwGetTime());
		addObjects();
		moveObjects();
		checkForCollision();
		glfwSetTime(0);
		drawScene(window,angle); //Wykonaj procedurê rysuj¹c¹
		glfwPollEvents(); //Wykonaj procedury callback w zaleznoœci od zdarzeñ jakie zasz³y.
		//Wyzeruj licznik czasu
	}

	glfwDestroyWindow(window); //Usuñ kontekst OpenGL i okno
	glfwTerminate(); //Zwolnij zasoby zajête przez GLFW
	exit(EXIT_SUCCESS);
}
Пример #4
0
void
GNEConnectorFrame::handleLaneClick(GNELane* lane, bool mayDefinitelyPass, bool allowConflict, bool toggle) {
    if (myCurrentLane == 0) {
        myCurrentLane = lane;
        myCurrentLane->setSpecialColor(&sourceColor);
        initTargets();
        buildIinternalLanes(lane->getParentEdge().getNBEdge()->getToNode());
        myNumChanges = 0;
        myViewNet->getUndoList()->p_begin("modify connections");
    } else if (myPotentialTargets.count(lane) || allowConflict) {
        const unsigned int fromIndex = myCurrentLane->getIndex();
        GNEEdge& srcEdge = myCurrentLane->getParentEdge();
        GNEEdge& destEdge = lane->getParentEdge();
        const std::string& destEdgeID = destEdge.getMicrosimID();
        std::vector<NBEdge::Connection> connections = srcEdge.getNBEdge()->getConnectionsFromLane(fromIndex);
        bool changed = false;
        NBConnection deletedConnection = NBConnection::InvalidConnection;
        LaneStatus status = getLaneStatus(connections, lane);
        if (status == CONFLICTED && allowConflict) {
            status = UNCONNECTED;
        }
        switch (status) {
            case UNCONNECTED:
                if (toggle) {
                    myViewNet->getUndoList()->add(new GNEChange_Connection(&srcEdge, fromIndex,
                                    destEdgeID, lane->getIndex(), mayDefinitelyPass, true), true);
                    lane->setSpecialColor(mayDefinitelyPass ? &targetPassColor : &targetColor);
                    changed = true;
                }
                break;
            case CONNECTED:
            case CONNECTED_PASS:
                myViewNet->getUndoList()->add(new GNEChange_Connection(&srcEdge, fromIndex, destEdgeID, lane->getIndex(),
                                status == CONNECTED_PASS, false), true);
                lane->setSpecialColor(&potentialTargetColor);
                changed = true;
                deletedConnection = NBConnection(srcEdge.getNBEdge(), fromIndex,
                                                 destEdge.getNBEdge(), lane->getIndex(),
                                                 (int)getTLLLinkNumber(connections, lane));
                break;
            case CONFLICTED:
                myViewNet->setStatusBarText("Another lane from the same edge already connects to that lane");
                break;
        }
        if (changed) {
            myNumChanges += 1;
            GNEJunction* affected = myViewNet->getNet()->retrieveJunction(srcEdge.getDest()->getMicrosimID());
            affected->invalidateTLS(myViewNet->getUndoList(), deletedConnection);
            buildIinternalLanes(myCurrentLane->getParentEdge().getNBEdge()->getToNode());
        }
    } else {
        myViewNet->setStatusBarText("Invalid target for connection");
    }
    updateDescription();
}
Пример #5
0
void Renderer::createDebugTumbler(cpBody* body, const sf::Vector2u& tumblerSize,
                                  std::vector<SpritePiece>* pieces) {
  mTargetSize = tumblerSize;
  initTargets();

  cpBodyEachShape(body, [](cpBody* body, cpShape* shape, void* data) {
    auto type = reinterpret_cast<ShapeType*>(cpShapeGetUserData(shape));
    if (*type != ShapeType::Segment) return;

    reinterpret_cast<Renderer*>(data)->drawBar(shape);
  }, this);

  createPieces(pieces);
}
Пример #6
0
void
GNEConnectorFrame::handleLaneClick(GNELane* lane, bool mayDefinitelyPass, bool allowConflict, bool toggle) {
    if (myCurrentLane == 0) {
        myCurrentLane = lane;
        myCurrentLane->setSpecialColor(&sourceColor);
        initTargets();
        myNumChanges = 0;
        myViewNet->getUndoList()->p_begin("modify connections");
    } else if (myPotentialTargets.count(lane) || allowConflict) {
        const int fromIndex = myCurrentLane->getIndex();
        GNEEdge& srcEdge = myCurrentLane->getParentEdge();
        GNEEdge& destEdge = lane->getParentEdge();
        std::vector<NBEdge::Connection> connections = srcEdge.getNBEdge()->getConnectionsFromLane(fromIndex);
        bool changed = false;
        LaneStatus status = getLaneStatus(connections, lane);
        if (status == CONFLICTED && allowConflict) {
            status = UNCONNECTED;
        }
        switch (status) {
            case UNCONNECTED:
                if (toggle) {
                    // create new connection
                    NBEdge::Connection newCon(fromIndex, destEdge.getNBEdge(), lane->getIndex(), mayDefinitelyPass);
                    myViewNet->getUndoList()->add(new GNEChange_Connection(&srcEdge, newCon, true), true);
                    lane->setSpecialColor(mayDefinitelyPass ? &targetPassColor : &targetColor);
                    srcEdge.getGNEJunctionDestiny()->invalidateTLS(myViewNet->getUndoList());
                }
                break;
            case CONNECTED:
            case CONNECTED_PASS: {
                // remove connection
                GNEConnection* con = srcEdge.retrieveConnection(fromIndex, destEdge.getNBEdge(), lane->getIndex());
                myViewNet->getNet()->deleteConnection(con, myViewNet->getUndoList());
                lane->setSpecialColor(&potentialTargetColor);
                changed = true;
                break;
            }
            case CONFLICTED:
                myViewNet->setStatusBarText("Another lane from the same edge already connects to that lane");
                break;
        }
        if (changed) {
            myNumChanges += 1;
        }
    } else {
        myViewNet->setStatusBarText("Invalid target for connection");
    }
    updateDescription();
}
Пример #7
0
void Level::start()
{
	_is_finished=0;
	_is_shooting=0;
	//
	int total_life=0;	
	for(unsigned int i=0;i<targets.size();i++)
	{
		delete targets.at(i);
	}
	targets.clear(); initTargets();
	for(unsigned int i=0;i<targets.size();i++)
	{
		total_life+=targets.at(i)->getLife();
	}
	Player::bullets=total_life/20;
	std::cout<<"bullets: "<<Player::bullets<<" life: "<<total_life<<std::endl;
}
Пример #8
0
Level::Level(int difficulty)
{
	loading=0;
	loading_message = std::string("Level #! Loading!");
	_is_finished=0;
	//
	this->difficulty = difficulty;
	//
	initTargets();
	initTrees();
	//
	_is_shooting=0;
	//
	bullet = new Object("models/9bulllet.obj");
	bullet->setScale(0.003,0.003,0.003);
	bullet->addAngle(90, 1,0,0);
	gun = new Object("models/L11A3.obj");
	gun->addAngle(20,1,0,0);
}