예제 #1
0
void GUI::Game::Object::draw(sf::RenderWindow& window, boost::shared_ptr<const ::Game::Player> viewer, bool selected) {
    // TODO: Load real graphics and track animations.
    static sf::Shape tmp, circle;
    if (!tmp.GetNbPoints()) {
        tmp.AddPoint(-0.8, -0.4);
        tmp.AddPoint(-0.0, -0.4);
        tmp.AddPoint(-0.0, -0.8);
        tmp.AddPoint(+0.8, -0.0);
        tmp.AddPoint(-0.0, +0.8);
        tmp.AddPoint(-0.0, +0.4);
        tmp.AddPoint(-0.8, +0.4);
        tmp.SetOutlineWidth(0.15);
    }
    if (!circle.GetNbPoints()) {
        circle = sf::Shape::Circle(0, 0, 1, sf::Color(0xff, 0xff, 0xff, 0x44), 0.2, sf::Color(0xff, 0xff, 0xff, 0xdd));
    }

    Vector2<SIUnit::Position> pos = object->getPosition();
    double r = object->getObjectType()->radius.getDouble();

    if (object->getOwner() == viewer) {
        circle.SetColor(sf::Color(0x33, 0x33, 0xcc));
        tmp.SetColor(sf::Color(0x33, 0x33, 0xcc));
    } else {
        circle.SetColor(sf::Color(0xcc, 0x33, 0x00));
        tmp.SetColor(sf::Color(0xdd, 0x00, 0x00));
    }

    if (selected) {
        circle.SetScale(r, r);
        circle.SetPosition(pos.x.getDouble(), pos.y.getDouble());
        window.Draw(circle);
    }

    tmp.SetScale(r, r);
    tmp.SetPosition(pos.x.getDouble(), pos.y.getDouble());
    tmp.SetRotation(-Math::toDegrees(object->getDirection().getDouble()));
    window.Draw(tmp);
}
예제 #2
0
void Collision(sf::RenderWindow &Window, sf::Sound &collision, sf::Shape player, sf::Shape &object)
{
    if(player.GetPosition().x + PLAYERWIDTH < object.GetPosition().x ||
       player.GetPosition().x > object.GetPosition().x + OBJECTWIDTH ||
       player.GetPosition().y + PLAYERHEIGHT < object.GetPosition().y ||
       player.GetPosition().y > object.GetPosition().y + OBJECTHEIGHT)
    {
        // No Collision
    }
    else
    {
        collision.Play();
        object.SetPosition(rand() % (ScreenWidth - OBJECTWIDTH), rand() % (ScreenHeight - OBJECTHEIGHT));
    }
}
예제 #3
0
void TestEntity::move(float dt)
{
    x += dx*dt;
    y += dy*dt;
    if (x < -(this->shape->maxSize))
    {
        x = WINDOW_X + shape->maxSize;
    }
    else if (x > WINDOW_X + this->shape->maxSize)
    {
        x = -(this->shape->maxSize);
    }
    if (y < -(this->shape->maxSize))
    {
        y = WINDOW_Y + shape->maxSize;
    }
    else if (y > WINDOW_Y + this->shape->maxSize)
    {
        y = -(this->shape->maxSize);
    }
    graphics.SetPosition(x, y);
}