Ejemplo n.º 1
0
void BmpMap::pixel(Game &game, int x, int y, const QColor& c){
    if( c==QColor(0, 0, 0) ){
      if( game.rand()%10==0 )
        game.add("grass")->setPosition(x, y, 0);
      } else
    if( c==QColor(0, 255, 0) ){
      game.add("tree0")->setPosition(x, y, 0);
      } else

    if( c.red()==0 && c.blue()==0 &&
        c.green() <= 127){
      for(int i=0; i<1; ++i){
        std::string name = "rock0";
        name.push_back('0'+rand()%5+1 );

        if( rand()%10==0 )
          game.add( name )->setPosition(x,
                                        y, 0);
        }
      } else

    if( c==QColor(128, 128, 128) ){
      int mx =  Map::coordX(x),
          my =  Map::coordX(y);
      game.map.setHeight( mx, my,
                          std::min(-4.0f, game.map.height(mx,my)));

      for(int i=-3; i<=3; ++i)
        for(int r=-3; r<=3; ++r){
          float w = std::max(1.0-sqrt(i*i+r*r)/3.0, 0.0);
          game.map.setHeight( mx+i, my+r,
                              std::min(-4.0f*w, game.map.height(mx+i,my+r)));
          game.map.excludeQuad(mx+i, my+r, 0);
          }

      } else

    if( c==QColor(255, 255, 0) ){
      game.add("gold")->setPosition(x, y, 0);
      } else

    if( c==QColor(255, 255, 255) ){
      if( game.playler(curPl).isActive() && curPl<9 ){
        GLObject *obj = game.add("castle");
        obj->setPosition(x, y, 0);
        obj->setPlayler( curPl );

        for(int i=0; i<6; ++i){
          GLObject *obj = game.add("worker");
          obj->setPosition(x+(i%3)*0.5, y+(i/3)*0.5, 0);
          obj->setPlayler( curPl );
          }
        }

      ++curPl;
      }

    }
void WorldLoader::readString(std::string s){
    jsonRoot = parseJSON(s);
    JSONValue& jo = *jsonRoot;
    
    if (!serverMode){
        //Read and load the textures
        std::cout<<"Reading textures\n";
        std::vector<std::string> textures = jo["textures"].keys();
        
        for (std::vector<std::string>::iterator it=textures.begin(); it!=textures.end(); it++){
            //std::cout<<*it<<std::endl;
            tm.addTexture(*jo["textures"][*it],*it);
        }
    }
    //Read Projection details..
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(parseDouble(*jo["projection"]["fov"]),
                    parseDouble(*jo["projection"]["aspectRatio"]),
                    parseDouble(*jo["projection"]["near"]),
                    parseDouble(*jo["projection"]["far"])
    );

    //std::cout<<jo.stringise()<<std::endl;

    //load objects..
    int objectsCount = jo["objects"].length();
    //std::cout<<"Loading "<<objectsCount<<" objects."<<std::endl;
    for (int i=0; i<objectsCount; i++){
        GLObject* glo;
        if (*jo["objects"][i]["type"] == "cube"){
            glo = new GLCube();
            glo->setTextureManager(&tm);
            glo->setTexturePrefix(*jo["objects"][i]["texturePrefix"]);
            if (serverMode){
                jo["objects"][i].setMapValue("oid",parseJSON("\"" + getNewRandomOID() + "\""));
            }
            glo->setObjectID(*jo["objects"][i]["oid"]);
            
            
            //set up transformations..
            double position[3], rotation[3], size[3];
            std::istringstream  issp(*jo["objects"][i]["position"]),
                                isso(*jo["objects"][i]["orientation"]),
                                isss(*jo["objects"][i]["dimensions"]);
            
            issp>>position[0]>>position[1]>>position[2];
            isso>>rotation[0]>>rotation[1]>>rotation[2];
            isss>>size[0]>>size[1]>>size[2];
            glo->setPosition(position[0], position[1], position[2]);
            glo->setRotation(rotation[0], rotation[1], rotation[2]);
            glo->setSize(size[0], size[1], size[2]);
        }else{