예제 #1
0
파일: Game.cpp 프로젝트: winipcfg/GFGame
Asteroid* Game::SpawnAsteroid(const Vector2& position, const GameSide& side)
{
    // Main
    ObjectId objId = this->SpawnEntity();
    Asteroid* unit = new Asteroid(this, -1);
    this->addComponent(objId, unit);

    // Render Component
    BaseNode* graphic = new BaseNode(kSpriteAsteroid);    
    graphic->setPosition(position.x, position.y);  
    graphic->setScale(0.5f);
    GFGame::Components::RenderComponent* node = new GFGame::Components::RenderComponent(graphic);
    this->addComponent(objId, node);

    // Physics Component
    GFGame::Components::PhysicsComponent* physics = new GFGame::Components::PhysicsComponent();
    b2Body* body = GFort::Core::Physics::PhysicsHelper::CreateCircle(
        phys_controller_.World(),
        b2_dynamicBody,
        position,
        min(graphic->getContentSize().width, graphic->getContentSize().height) * 0.5 * graphic->getScale());
    body->SetFixedRotation(false);
    body->SetAngularDamping(0);
    body->SetAngularVelocity(10);

    // Set the dynamic body fixture.
    b2Fixture* fixture = body->GetFixtureList();	
    b2Filter filter = fixture[0].GetFilterData();
    filter.categoryBits = kCategoryBitsObstacle;
    filter.maskBits = kMaskBitsObstacle;
    fixture[0].SetFilterData(filter);

    physics->AddBody("root", body);
    graphic->SetBody(body);
    this->addComponent(objId, physics);
    unit->physics_component_ = physics;

    return unit;
    //return objId;
}
예제 #2
0
파일: document.cpp 프로젝트: hexfaker/puml
/*! Slot. This will create a new object at the specified position. The
  prototypeID of the new object will have been set by a previous signal
  to setNewObjectID. Uses NodeFactory.
*/
void Document::createObject(const QPoint &position) {
  assert(indexOfSelectedObject >= -1);
  assert(indexOfSelectedObject < static_cast<int>(nodes.size()));

  // testing
  int objectUnder = getIndexAt(position);
  if (objectUnder != -1) {
    setSelectedObject(position);
    return;
  }

  // create a new node using the factory
  BaseNode* newNode;
  newNode = NodeFactory::getInstance()->produce(newObjectID);
  newNode->setPosition(position);

  // add newnode to a vector of nodes.
  addNodeToList(newNode);

  // add the node to the ordering
  ordering.append(nodes.size()-1);

  // reset the selected property of previously selected node
  if (indexOfSelectedObject != -1) {
    nodes.at(indexOfSelectedObject)->setSelected(false);
  }

  // set the selected index to be the created object
  indexOfSelectedObject = nodes.size()-1;
  nodes.at(indexOfSelectedObject)->setSelected(true);

  setModified(true);
  emit modelChanged();

  this->showPropertiesDialog();
  setSelectedObject(position);
}