Beispiel #1
0
    void draw()
    {
        player.draw();
        backgroundImage->draw(0, 0, zBackground);

        for (std::list<Star>::const_iterator i = stars.begin();
            i != stars.end(); ++i)
        {
            i->draw();
        }

        std::wstringstream score;
        score << L"Score: "; 
        score << player.getScore();
        font.draw(score.str(), 10, 10, zUI, 1, 1, Gosu::Colors::yellow);
    }
Beispiel #2
0
    void draw() noexcept override
    {
        for (auto& node:graph.getNodes()) {
            double val = betweenness.getValue(node);
            auto col = Gosu::interpolate(Gosu::Color::BLUE, Gosu::Color::RED, val);
            nodeImage.draw(node->x-10, node->y-10, zNodes, 1, 1, col);
            auto owner = nodeOwner.find(node);
            if (owner != nodeOwner.end()) {
                nodeFillImage.draw(node->x-10, node->y-10, zNodes, 1, 1, owner->second->getColor());
            }
            for (auto& edge: node->getEdges()) {
                double val2 = betweenness.getValue(edge->getTarget());
                auto col2 = Gosu::interpolate(Gosu::Color::BLUE, Gosu::Color::RED, val2);
                graphics().drawLine(
                    node->x, node->y, col,
                    edge->getTarget()->x, edge->getTarget()->y, col2,
                    zEdges
                );
            }
        }
        auto mousePos = mousePosition();
        drawLine(graphics(), Gosu::Color::WHITE, zUI,
            mousePos,
            mousePos + Position(20, 5),
            mousePos + Position(5, 20),
            mousePos
        );
        if (!connectingNode) {
            auto nearest = graph.getNearestNode(mousePos);
            graphics().drawLine(
                    mousePos.x, mousePos.y, Gosu::Color::YELLOW,
                    nearest->x, nearest->y, Gosu::Color::YELLOW,
                    zUI
                );
        }

        if (shortestDistSource) {
            // draw some sparkling green particles not signify a new edge that is being created
            Position targetPos;
            auto selected = selectNode();
            // snap to cursor && not to self
            if (selected && (selected != shortestDistSource)) {
                targetPos = *selected;
            } else {
                targetPos = mousePos;
            }
            graphics().drawLine(
                targetPos.x, targetPos.y, Gosu::Color::AQUA,
                shortestDistSource->x, shortestDistSource->y, Gosu::Color::AQUA,
                zUI
            );
        }
        
        if (connectingNode) {
            // draw some sparkling green particles not signify a new edge that is being created
            Position targetPos;
            auto selected = selectNode();
            // snap to cursor && not to self && not to already connected nodes
            if (selected && (selected != connectingNode) && !selected->getEdge(connectingNode)) {
                targetPos = *selected;
            } else {
                targetPos = mousePos;
            }
            graphics().drawLine(
                targetPos.x, targetPos.y, Gosu::Color::GREEN,
                connectingNode->x, connectingNode->y, Gosu::Color::GREEN,
                zUI
            );
        }

        if (!pathsToDraw.empty()) {
            for (auto pathToDraw : pathsToDraw) {
                for (auto it = pathToDraw.begin(); it != pathToDraw.end(); it++) {
                    auto next = it;
                    next++;
                    if (next == pathToDraw.end()) break;
                    graphics().drawLine(
                        (*it)->x, (*it)->y, Gosu::Color::AQUA,
                        (*next)->x, (*next)->y, Gosu::Color::AQUA,
                        zUI
                    );
                }
            }
        }

        {
            std::wstringstream wss;
            wss << Gosu::fps() << L" fps";
            font.draw(wss.str().c_str(), 0, 0, zUI);
        }
        double y = 20;
        auto currentPlayer = game.getCurrentPlayer();
        for (auto player : game.getPlayers()) {
            auto name = player->getName();
            auto wname = std::wstring(std::begin(name), std::end(name));
            if (player == currentPlayer) {
                font.draw(wname, 0, y-2, zUI, 1.4, 1.4, player->getColor());
            } else {
                font.draw(wname, 0, y, zUI, 1, 1, player->getColor());
            }
            y += 20;
        }
        
        double x = graphics().width() - 50;
        for (auto player : game.getPlayers()) {
            auto col = player->getColor();
            double score = player->getScore() * 30;
            graphics().drawQuad(
                x, 0, col,
                x+40, 0, col,
                x+40, score, col,
                x, score, col,
                zUI
            );
            std::wstringstream wss;
            wss << score;
            font.draw(wss.str().c_str(), x, score, zUI);
            x -= 50;
        }
    }