int main(int argc, char* argv[])
{
  Hammer h;
  Knee k1(1);

  QObject::connect(&h, SIGNAL(hit(bool)), &k1, SLOT(reflex(bool)));
  h.setHardHit(true);
  h.setHardHit(false);
  return 0;
}
예제 #2
0
//--------------------------------------------------------------
void PinballChinoManager::onReleaseBallLauncherEvent(void){
    
    for(int i = 0; i < myScenario.ScenarioObjects.size(); i++)
    {
        if (myScenario.ScenarioObjects[i]->type == 5)
        {
            Hammer* hammer = (Hammer*) myScenario.ScenarioObjects[i];
            hammer->onReleaseEvent();
        }
    }
    
}
예제 #3
0
bool Board::fireHammer(Grid location, zf::Direction direction)
{
    if(isMoving())
    {
        return false;
    }
    Grid directionGrid = Grid(0,0);
    switch(direction)
    {
        case zf::North:
            directionGrid = Grid(-1,0);
            break;
        case zf::South:
            directionGrid = Grid(1,0);
            break;
        case zf::East:
            directionGrid = Grid(0,1);
            break;
        case zf::West:
            directionGrid = Grid(0,-1);
            break;
    }
    Grid nextGrid = location + directionGrid;
    Brick* brick = getBrickAt(nextGrid.row , nextGrid.col);
    if(brick != 0)
    {
        return false; // if there is a brick blocking directly, don't allow it to shoot.
    }
    //find the first block that it will hit
    // move nextGrid back first
    nextGrid -= directionGrid;
    while(brick == 0)
    {
        nextGrid += directionGrid;
        Grid temp = nextGrid + directionGrid;
        if(!inShootableRange(temp.row,temp.col)) // if the next is not in shootable range , break
        {
            // prevent out of bound
            break;
        }
        brick = getBrickAt(temp.row, temp.col);
    }
    _knock = 0;
    Hammer* hammer = new Hammer(_game,this);
    putHammerInto(location.row,location.col,hammer);
    _currentMovingDirection = directionGrid; 
    hammer->moveToLocation(nextGrid.row, nextGrid.col);
    return true;
}
//--------------------------------------------------------------
void Scenario::pushObject(ofxBulletWorldRigid &world, int typeObject, ofVec3f pos){
    
 //   ScenarioObjects.push_back(&m_obstable1);

/*
    ofVec3f pos;
    pos.x = ScenarioXml.getValue("positionX",0.0, 0);
    pos.y = ScenarioXml.getValue("positionY",0.0, 0);
    pos.z = ScenarioXml.getValue("positionZ",0.0, 0);
*/

    switch(typeObject){

        case SimpleObject::ShapeTypeBall:{
            Ball *oBall = new Ball(currentMissions);
            oBall->setup(world, pos);
            oBall->setDefaultZ();
            ScenarioObjects.push_back(oBall);
        }
        break;
            
        case SimpleObject::ShapeTypeHammer:{
            Hammer *oHammer = new Hammer(currentMissions);
            oHammer->setup(world, pos);
            oHammer->setDefaultZ();
            ScenarioObjects.push_back(oHammer);
        }
        break;
            
        case SimpleObject::ShapeTypeLever:{
            Lever *oLever = new Lever(currentMissions);
            int dir = 0;
            oLever->setup(world, pos, "cylinder.stl", ofVec3f(0.05, 0.05, 0.05), dir);
            oLever->setDefaultZ();
            ScenarioObjects.push_back(oLever);
        }
        break;
            
        case SimpleObject::ShapeTypeObstacle:{
            Obstacle *oObstable = new Obstacle(currentMissions);
            oObstable->setup(world, pos, "cylinder.stl", ofVec3f(0.05, 0.05, 0.05));
            oObstable->setDefaultZ();
            ScenarioObjects.push_back(oObstable);
        }
        break;
            
    }
}
void Scenario::loadFromXml(ofxBulletWorldRigid &world){
    ofxXmlSettings ScenarioXml;
    
    if(ScenarioXml.loadFile(PinballChinoManager::projectName+"/scenario.xml")){
        
        ScenarioXml.pushTag("scenario");
        
        int numberOfSavedObjects = ScenarioXml.getNumTags("object");
        
        for(int i = 0; i < numberOfSavedObjects; i++){
            
            ScenarioXml.pushTag("object", i);
            SimpleObject::shapeType Type = (SimpleObject::shapeType)ScenarioXml.getValue("type", 0);
            int objId = ScenarioXml.getValue("id", 0);
            
            
            ofVec3f pos, scale;
			
            pos.x = ScenarioXml.getValue("positionX",0.0, 0);
            pos.y = ScenarioXml.getValue("positionY",0.0, 0);
            pos.z = ScenarioXml.getValue("positionZ",0.0, 0);
            
            scale.x = ScenarioXml.getValue("scaleX",0.0, 0);
            scale.y = ScenarioXml.getValue("scaleY",0.0, 0);
            scale.z = ScenarioXml.getValue("scaleZ",0.0, 0);
			
			ofQuaternion rotation;
            ofVec4f rot;
			
			rot.x = ScenarioXml.getValue("rotationX",0.0,0);
			rot.y = ScenarioXml.getValue("rotationY",0.0,0);
			rot.z = ScenarioXml.getValue("rotationZ",0.0,0);
            rot.w = ScenarioXml.getValue("rotationW",0.0,0);
			rotation.set(rot);
			
            string path;
            path = ScenarioXml.getValue("path","", 0);
            
            //TODO uncomment the line below when the xml is properly configured
            //string strcolor = ScenarioXml.getValue("color", "0xFFFFFF", 0);
			int color = ScenarioXml.getValue("color", 0xFFFFFF, 0);
			
			int pointsCollision = ScenarioXml.getValue("pointsCollision", 0, 0);

			int invisible = 0; // Visible by default event if this value is not implemented in the Xml editor
			invisible = ScenarioXml.getValue("invisible", 0, 0);
			
            switch(Type){
                case SimpleObject::ShapeTypeBall:{
                    Ball *oBall = new Ball(currentMissions);
                    float mass = ScenarioXml.getValue("mass", 0.0);
                    float radius = ScenarioXml.getValue("radius", 0.0);
                    float restitution = ScenarioXml.getValue("restitution", 0.0);
                    float friction = ScenarioXml.getValue("friction", 0.0);
                    oBall->setup(world, pos, mass, radius, restitution, friction);
                    oBall->SetObjectId(objId);
					oBall->setRotation(rotation);
                    oBall->color = color;
					oBall->setVisibility(invisible);
					
                    ScenarioObjects.push_back(oBall);
                }
                break;
                    
                case SimpleObject::ShapeTypeHammer:{
                    Hammer *oHammer = new Hammer(currentMissions);
                    oHammer->setup(world, pos);
                    oHammer->SetObjectId(objId);
					oHammer->setRotation(rotation);
                    oHammer->color = color;
					oHammer->setVisibility(invisible);
                    ScenarioObjects.push_back(oHammer);
					
					oHammer->setupRot();
                }
                break;
                    
                case SimpleObject::ShapeTypeLever:{
                    Lever *oLever = new Lever(currentMissions);
                    int dir = ScenarioXml.getValue("LeverType", 0);
                    oLever->setup(world, pos, path, scale, dir);
                    oLever->SetObjectId(objId);
					oLever->setRotation(rotation);
                    oLever->color = color;
					oLever->setVisibility(invisible);
                    ScenarioObjects.push_back(oLever);

                }
                break;
                    
                case SimpleObject::ShapeTypeObstacle:{
                    Obstacle *oObstable = new Obstacle(currentMissions);
                    //oObstable->setup(world, pos, "3DModels/chino_6.dae");
                    oObstable->setup(world, pos, path, scale);
                    oObstable->SetObjectId(objId);
					oObstable->setRotation(rotation);
                    oObstable->color = color;
					oObstable->setVisibility(invisible);
                    ScenarioObjects.push_back(oObstable);
					oObstable->setPointsCollision(pointsCollision);
					oObstable->setupRot();

                }
                break;
                
                case SimpleObject::ShapeTypeGravity:{
                    Gravity *oGravity = new Gravity(currentMissions);
                    //oObstable->setup(world, pos, "3DModels/chino_6.dae");
                    oGravity->setup(world, pos, path, scale);
                    oGravity->SetObjectId(objId);
					oGravity->setRotation(rotation);
                    oGravity->color = color;
					oGravity->setVisibility(invisible);
                    ScenarioObjects.push_back(oGravity);
					oGravity->setPointsCollision(pointsCollision);
					oGravity->setupRot();
                    
                }
                break;
                   
                case SimpleObject::ShapeTypeTeleporter:{
                    Teleporter *oTeleporter = new Teleporter(currentMissions);
                    //oObstable->setup(world, pos, "3DModels/chino_6.dae");
                    oTeleporter->setup(world, pos, path, scale);
                    oTeleporter->SetObjectId(objId);
					oTeleporter->setRotation(rotation);
                    oTeleporter->color = color;
					oTeleporter->setVisibility(invisible);
                    ScenarioObjects.push_back(oTeleporter);
					oTeleporter->setPointsCollision(pointsCollision);
					oTeleporter->setupRot();
                    
                }
                break;
					
				case SimpleObject::ShapeTypeRamp:{
					Ramp *oRamp = new Ramp(currentMissions);
					//oObstable->setup(world, pos, "3DModels/chino_6.dae");
					oRamp->setup(world, pos, path, scale);
					oRamp->SetObjectId(objId);
					oRamp->setRotation(rotation);
					oRamp->color = color;
					oRamp->setVisibility(invisible);
					ScenarioObjects.push_back(oRamp);
					oRamp->setPointsCollision(pointsCollision);
					oRamp->setupRot();
				}
					break;
					
				case SimpleObject::ShapeTypeObstacleTriShapeMesh:{
					ObstacleTriShapeMesh *oObstacleTriShapeMesh= new ObstacleTriShapeMesh(currentMissions);
					
					oObstacleTriShapeMesh->setup(world, pos, path, scale);
					oObstacleTriShapeMesh->SetObjectId(objId);
					oObstacleTriShapeMesh->setRotation(rotation);
					oObstacleTriShapeMesh->color = color;
					oObstacleTriShapeMesh->setVisibility(invisible);
					ScenarioObjects.push_back(oObstacleTriShapeMesh);
					oObstacleTriShapeMesh->setPointsCollision(pointsCollision);
					oObstacleTriShapeMesh->setupRot();
				}
					break;
					
                case SimpleObject::ShapeTypeAnimatedObject:{
                    AnimatedObject *oAnimatedObject = new AnimatedObject(currentMissions);
                    //oObstable->setup(world, pos, "3DModels/chino_6.dae");
                    oAnimatedObject->setup(world, pos, path, scale);
                    oAnimatedObject->SetObjectId(objId);
					oAnimatedObject->setRotation(rotation);
                    oAnimatedObject->color = color;
					oAnimatedObject->setVisibility(invisible);
                    ScenarioObjects.push_back(oAnimatedObject);
					oAnimatedObject->setPointsCollision(pointsCollision);
					oAnimatedObject->setupRot();
                    
                }
                break;
                
                case SimpleObject::ShapeTypeAnimatedMotionPath:{
                    string pathMotionModel;
                    pathMotionModel = ScenarioXml.getValue("pathMotionModel","", 0);
                    AnimatedMotionPath *oAnimatedMotionPath = new AnimatedMotionPath(currentMissions);
                    oAnimatedMotionPath->setup(world, pos, path, pathMotionModel, scale);
                    oAnimatedMotionPath->SetObjectId(objId);
					oAnimatedMotionPath->setRotation(rotation);
                    oAnimatedMotionPath->color = color;
					oAnimatedMotionPath->setVisibility(invisible);
                    ScenarioObjects.push_back(oAnimatedMotionPath);
					oAnimatedMotionPath->setPointsCollision(pointsCollision);
					oAnimatedMotionPath->setupRot();
                    
                }
                break;
                    
                case SimpleObject::ShapeTypeAnimatedMesh:{
                    AnimatedMesh *oAnimatedMesh = new AnimatedMesh(currentMissions);
                    //oObstable->setup(world, pos, "3DModels/chino_6.dae");
                    oAnimatedMesh->setup(world, pos, path, scale);
                    oAnimatedMesh->SetObjectId(objId);
					oAnimatedMesh->setRotation(rotation);
                    oAnimatedMesh->color = color;
					oAnimatedMesh->setVisibility(invisible);
                    ScenarioObjects.push_back(oAnimatedMesh);
					oAnimatedMesh->setPointsCollision(pointsCollision);
					oAnimatedMesh->setupRot();
                    
                }
                break;
                case SimpleObject::ShapeTypeGeneratedMesh:{
                    GeneratedMesh *oGeneratedMesh = new GeneratedMesh(currentMissions);
                    //oObstable->setup(world, pos, "3DModels/chino_6.dae");
                    oGeneratedMesh->setup(world, pos, path, scale);
                    oGeneratedMesh->SetObjectId(objId);
					oGeneratedMesh->setRotation(rotation);
                    oGeneratedMesh->color = color;
					oGeneratedMesh->setVisibility(invisible);
                    ScenarioObjects.push_back(oGeneratedMesh);
					oGeneratedMesh->setPointsCollision(pointsCollision);
					oGeneratedMesh->setupRot();
                    
                }
                break;
                    
                case SimpleObject::ShapeTypeBounds:{
                    Bounds *oBounds = new Bounds(currentMissions);
                    oBounds->setup(world, pos, path, scale);
                    oBounds->SetObjectId(objId);
					oBounds->setRotation(rotation);
                    oBounds->color = color;
					oBounds->setVisibility(invisible);
                    ScenarioObjects.push_back(oBounds);
					
					oBounds->setupRot();
                }
                break;

            }
            ScenarioXml.popTag();
        }
        
        ScenarioXml.popTag(); //pop position
    }
    
    else{
        
        ofLogError("Scenario file did not load!");
        
    }
    
}
예제 #6
0
파일: client.cpp 프로젝트: bjovke/ACE_TAO
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      if (parse_args (argc, argv) != 0)
        return 1;

      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("(%P|%t) - Acquiring Name Service\n")));


      CORBA::Object_var nmobj = orb->resolve_initial_references ("NameManager");
      FT_Naming::NamingManager_var naming_manager =
        FT_Naming::NamingManager::_narrow (nmobj.in());

      TAO_Naming_Client name_svc;
      try {

        ACE_Time_Value timeout (10); // Wait up to 10 seconds for the naming service
        if (name_svc.init (orb.in (), &timeout) != 0)
          ACE_ERROR_RETURN ((LM_DEBUG,
                             ACE_TEXT ("client: Could not connect to ")
                             ACE_TEXT ("naming service.\n")),
                            1);
      }
      catch (const CORBA::Exception& ex)
      {
        ex._tao_print_exception (
          ACE_TEXT ("Exception caught while initializing name ")
          ACE_TEXT ("service facade:"));
        return 1;
      }


      Hammer hammer;

      if (hammer.setup(orb.in(), naming_manager.in()) == -1)
        {
          return 1;
        }

      CosNaming::Name name (1);
      name.length (1);
      name[0].id = CORBA::string_dup ("basic_name");

      CORBA::Object_var tmp;
      Test::Basic_var basic;

      // Iterate enough so we get a few wrap-arounds
      for (int i = 0; i < 15; i++)
      {
        if (i == 3) {
          hammer.activate (THR_NEW_LWP | THR_JOINABLE, hammers);
        }

        try {

          // Each time we invoke resolve, we get a different member
          tmp =
            name_svc->resolve (name);

          // Narrow it to a Basic object
          basic =
            Test::Basic::_narrow (tmp.in ());

        }
        catch (CORBA::Exception& ex)
          {
            ex._tao_print_exception (ACE_TEXT ("Error resolving name.\n"));
          }

        if (CORBA::is_nil (basic.in ()))
          {
            ACE_ERROR_RETURN ((LM_DEBUG,
                               ACE_TEXT ("Server obj ref not obtained ")
                               ACE_TEXT ("from Load Balancing Name Service\n"),
                               ior),
                              1);
          }

        try {
          CORBA::String_var the_string =
            basic->get_string ();

          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("(%P|%t) - Client request handled ")
                      ACE_TEXT ("by object at <%C>\n"),
                      the_string.in ()));

        }
        catch (CORBA::Exception& ex)
          {
            ex._tao_print_exception (
              ACE_TEXT ("Error invoking get_string on Basic object.\n"));
            return 1;
          }

        // Remove one member after we wrapped around to make sure naming manager can
        // handle it successufully
        if (i == 7)
          {
            try {
              // Try removing a member
              basic->remove_member ();
            }
            catch (CORBA::Exception& ex)
              {
                ex._tao_print_exception (
                  ACE_TEXT ("Error invoking get_string on Basic object.\n"));
                return 1;
              }
          }
      }

      hammer.wait ();

      try {

        basic->shutdown ();

        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("(%P|%t) - Shutting down server\n")));
      }
      catch (CORBA::Exception& ex)
      {
        ex._tao_print_exception (
          ACE_TEXT ("Error invoking get_string on Basic object.\n"));
        return 1;
      }
      orb->destroy ();
  }
  catch (const CORBA::Exception& ex)
  {
    ex._tao_print_exception (
      ACE_TEXT ("Exception caught in client.cpp:"));
    return 1;
  }

  return 0;
}