コード例 #1
0
ファイル: AvlVisualizer.cpp プロジェクト: seemuch/avl
void AvlVisualizer::delObject(const std::string &name)
{
	if (objects.find(name) != objects.end())
		objects.erase(name);

	placeObject();
}
コード例 #2
0
ファイル: AvlVisualizer.cpp プロジェクト: seemuch/avl
void AvlVisualizer::addObject(AvlObject *obj, const std::string &name)
{
	if (objects.find(name) == objects.end()) {
		objects[name] = obj;
		obj->setVisualizer(this);
	}

	placeObject();
}
コード例 #3
0
ファイル: World.cpp プロジェクト: Smorgasfjord/VikingGame
World::World(std::vector<Platform> plats, GameModel* simplePlatformMod, Mountain mnt, GLHandles* handles)
{
   platforms = plats;
   mount = mnt;
   this->handles = handles;
   space = ChunkWorld(50,50,50);
   for (int i = 0; i < plats.size(); i++) {
      placeObject(&(plats[i]), simplePlatformMod);
   }
}
コード例 #4
0
void Synthesizer::step()
{
    if (done)
    {
        cout << "done" << endl;
        return;
    }

    cout << "Executing step: " << stageName(stage) << endl;
    
    if (stage == SynthesizerStagePlaceAgents)
    {
        placeAgents();
        stage = SynthesizerStageSelectAgentObjects;
        return;
    }

    if (stage == SynthesizerStageSelectAgentObjects)
    {
        selectAgentObjects();
        stage = SynthesizerStageSelectNextObject;
        return;
    }

    if (stage == SynthesizerStageSelectNextObject)
    {
        selectNextObject();
        stage = SynthesizerStageEvaluatePlacementA;
        return;
    }
    
    if (stage == SynthesizerStageEvaluatePlacementA)
    {
        makeLocations();
        evaluatePlacementA();
        stage = SynthesizerStageEvaluatePlacementB;
        return;
    }
    
    if (stage == SynthesizerStageEvaluatePlacementB)
    {
        evaluatePlacementB();
        stage = SynthesizerStagePlaceObject;
        return;
    }

    if (stage == SynthesizerStagePlaceObject)
    {
        placeObject();
        stage = SynthesizerStageSelectNextObject;
        return;
    }
}
コード例 #5
0
ファイル: random_map.cpp プロジェクト: leo-lu/common
	void generate(int maxFeatures)
	{
		// place the first room in the center
		if (!makeRoom(_width / 2, _height / 2, static_cast<Direction>(randomInt(4), true)))
		{
			std::cout << "Unable to place the first room.\n";
			return;
		}

		// we already placed 1 feature (the first room)
		for (int i = 1; i < maxFeatures; ++i)
		{
			if (!createFeature())
			{
				std::cout << "Unable to place more features (placed " << i << ").\n";
				break;
			}
		}

		if (!placeObject(UpStairs))
		{
			std::cout << "Unable to place up stairs.\n";
			return;
		}

		if (!placeObject(DownStairs))
		{
			std::cout << "Unable to place down stairs.\n";
			return;
		}

		for (char& tile : _tiles)
		{
			if (tile == Unused)
				tile = ' ';
			else if (tile == Floor || tile == Corridor)
				tile = ' ';
		}
	}
コード例 #6
0
ファイル: MapEditor.cpp プロジェクト: deol13/SmallGameProject
int MapEditor::mouseClick(float x, float y)
{
	lua_getglobal(L, "mouseClick");
	lua_pushnumber(L, x);
	lua_pushnumber(L, y);
	error = lua_pcall(L, 2, LUA_MULTRET, 0);
	int event = lua_tointeger(L, -1);
	lua_pop(L, 1);

	if (!error)
	{
		if (event == 1) //(Place
			placeObject(x, y);
		else if (event == 3) //Load
		{
			clean(false);
			getUIFromLua(true);
		}
	}
	return event; //0 = save and 2 = back
}
コード例 #7
0
ファイル: testApp.cpp プロジェクト: josephrmoore/dionysius
//--------------------------------------------------------------
void testApp::update(){
    current_color = ofColor(current_color.r, current_color.g, current_color.b, current_alpha);
    if(current_sides==0){
        current_bk = current_color;
        current_preview = ofColor(0,0,0);
    } else {
        if(current_color.r == current_bk.r && current_color.g == current_bk.g && current_color.b == current_bk.b){
            current_preview = ofColor(0,0,0);
        } else {
            current_preview = current_color;
        }
    }
    preview_object.update_geometry(current_point, current_sides, current_radius, current_preview, current_z, line, false);
    for(int i=0; i<objects.size(); i++){
        objects[i].update_geometry(objects[i].centroid, objects[i].verticies-1, objects[i].radius, objects[i].color, objects[i].z, objects[i].line, oskar);
    }
    ofBackground(current_bk);

    do {
        arduino = ofxGetSerialString(serial,';'); //read until end of line
        if(arduino != ""){
            output = arduino;
            values = ofSplitString(output, " ", true, true); // trues are ignoreempty & trim
            if(values.size()==20){
                current_point.x += ofToInt(values[0]);
                if(current_point.x > ofGetScreenWidth()+current_radius){
                    current_point.x = ofGetScreenWidth()+current_radius;
                }
                if(current_point.x < -current_radius-5){
                    current_point.x = -current_radius-5;
                }
                current_point.y += -ofToInt(values[1]);
                if(current_point.y > ofGetScreenHeight()+current_radius){
                    current_point.y = ofGetScreenHeight()+current_radius;
                }
                if(current_point.y < -current_radius-5){
                    current_point.y = -current_radius-5;
                }
                CGPoint point;  
                point.x = current_point.x;  
                point.y = current_point.y;  
                CGWarpMouseCursorPosition(point);
                if(ofToInt(values[2]) == 1 && j1_up == false){
                    // J1 UP
                    if(current_object < (objects.size()-1) && objects.size()>0){
                        current_object++;
                    } else {
                        current_object = 0;
                    }
                    j1_up = true;
                } else {
                    j1_up = false;
                }
                if(ofToInt(values[3]) == 1 && j1_down == false){
                    // J1 DOWN
                    if((current_object) > -1 && objects.size()>0){
                        current_object--;
                    } else {
                        current_object = (objects.size()-1);
                    }
                    j1_down = true;
                } else {
                    j1_down = false;
                }
                if(ofToInt(values[4]) == 1 && j1_left == false){
                    // J1 LEFT
                    if((current_object) > -1 && objects.size()>0){
                        current_object--;
                    } else {
                        current_object = (objects.size()-1);
                    }
                    j1_left = true;
                } else {
                    j1_left = false;
                }
                if(ofToInt(values[5]) == 1 && j1_right == false){
                    // J1 RIGHT
                    if(current_object < (objects.size()-1) && objects.size()>0){
                        current_object++;
                    } else {
                        current_object = 0;
                    }
                    j1_right = true;
                } else {
                    j1_right = false;
                }
                if(ofToInt(values[6]) == 0 && ok_button == false){
                    // OK button
                    if(current_sides!=0){
                        if(current_object<0){
                            if(current_sides!=0){
                                placeObject();
                            }
                        } else {
                            edit();
                        }
                    }
                    ok_button = true;
                } else {
                    ok_button = false;
                }
                if(ofToInt(values[7]) == 0 && delete_button == false){
                    // DELETE
                    if(current_object>=0){
                        deleteObject(current_object);            
                    }
                    delete_button = true;
                } else {
                    delete_button = false;
                }
                if(values[8] == "0" && j2_up == false){                    
                    // J2 UP
                    float bri = current_color.getBrightness();
                    bri+=step;
                    current_color.setBrightness(bri);
                    j2_up = true;
                } else {
                    j2_up = false;
                }
                if(values[9] == "0" && j2_down == false){
                    // J2 DOWN
                    float bri = current_color.getBrightness();
                    bri-=step;
                    current_color.setBrightness(bri);
                    j2_down = true;
                } else {
                    j2_down = false;
                }
                if(values[10] == "0" && j2_left == false){
                    // J1 LEFT
                    float sat = current_color.getSaturation();
                    if(sat>step){
                        sat-=(2*step);
                        current_color.setSaturation(sat);
                    }
                    j2_left = true;
                } else {
                    j2_left = false;
                }
                if(values[11] == "0" && j2_right == false){
                    // J2 RIGHT
                    float sat = current_color.getSaturation();
                    if(sat<(255-step)){
                        sat+=(2*step);
                        current_color.setSaturation(sat);
                    }
                    j2_right = true;
                } else {
                    j2_right = false;
                }
                current_sides = (int)(ofMap(ofToInt(values[12]), 58, 1006, 0, 20));
                current_radius = (int)(ofMap(ofToInt(values[13]), 0, 1020, 0, ofGetScreenWidth()/2));
                current_color.setHue(ofMap(ofToInt(values[14]), 58, 1021, 0, 255));
                current_z = (int)(ofMap(ofToInt(values[15]), 58, 1008, 0, objects.size()));
                current_alpha = (int)(ofMap(ofToInt(values[16]), 58, 1020, 0, 255));
                if(ofToInt(values[17]) == 0 && delete_button == false){
                    // CLOSE SHAPE
                    line.close();
                    close = true;
                } else {
                    close = false;
                }
                if(ofToInt(values[18]) == 0 && delete_button == false){
                    // VERTEX
                    if(current_sides==1){
                        line.addVertex(current_point);
                    }
                    vertex = true;
                } else {
                    vertex = false;
                }
                if(ofToInt(values[19]) == 0){
                    // OSKAR MODE
                    oskar = false;
                } else {
                    oskar = true;
                }
            }
        }
        if (arduino == "") continue;
        //do something with str
    } while (arduino != "");
    if(current_sides != 1){
        if(line.getArea() != 0){
            line.clear();            
        }
    }
}
コード例 #8
0
ファイル: testApp.cpp プロジェクト: josephrmoore/dionysius
//--------------------------------------------------------------
void testApp::keyPressed(int key){
    if(key == '+'){
        step++;
    }
    if(key == '_'){
        step--;
    }
    if(key == OF_KEY_LEFT){
        float sat = current_color.getSaturation();
        if(sat>step){
            sat-=(2*step);
            current_color.setSaturation(sat);
        }
    }
    if(key == OF_KEY_RIGHT){
        float sat = current_color.getSaturation();
        if(sat<(255-step)){
            sat+=(2*step);
            current_color.setSaturation(sat);
        }
    }
    if(key == OF_KEY_UP){
        float bri = current_color.getBrightness();
        bri+=step;
        current_color.setBrightness(bri);
    }
    if(key == OF_KEY_DOWN){
        float bri = current_color.getBrightness();
        bri-=step;
        current_color.setBrightness(bri);
    }
    if(key == 'k'){
        if(current_alpha>0){
            current_alpha-=step;
        }
    }
    if(key == 'l'){
        if(current_alpha<255){
            current_alpha+=step;
        }
    }
    if(key == 'i'){
        info_on = !info_on;
    }
    if(key == 'c'){
        line.close();
    }
    if(key == 'v'){
        if(current_sides==1){
            line.addVertex(current_point);
        }
    }
    if(key == 'a'){
        if((current_object) > -1 && objects.size()>0){
            current_object--;
        } else {
            current_object = (objects.size()-1);
        }
    }
    if(key == 'd'){
        if(current_object < (objects.size()-1) && objects.size()>0){
            current_object++;
        } else {
            current_object = 0;
        }
    }
    if(key == 'w'){
        if(current_object < (objects.size()-1) && objects.size()>0){
            current_object++;
        } else {
            current_object = 0;
        }
    }
    if(key == 's'){
        if((current_object) > 0 && objects.size()>0){
            current_object--;
        } else {
            current_object = (objects.size()-1);
        }
    }
    if(key == 'o'){
        oskar = !oskar;
    }
    if(key == '1'){
        wheel_state = 1;  
    }
    if(key == '2'){
        wheel_state = 2;
    }
    if(key == '3'){
        wheel_state = 3;
    }
    if(key == '-'){
        if(wheel_state == 1){
            if(current_sides>0){
                current_sides-=1;
            }
        } else if (wheel_state == 2){
            if(current_radius>1){
                current_radius-=step;
            }
        } else if (wheel_state == 3){
            float hue = current_color.getHue();
            hue-=step;
            current_color.setHue(hue);
        }
    }
    if(key == '='){
        if(wheel_state == 1){
            current_sides+=1;
        } else if (wheel_state == 2){
            current_radius+=step;
        } else if (wheel_state == 3){
            float hue = current_color.getHue();
            hue+=step;
            current_color.setHue(hue);
        }
    }
    if(key == 'z'){
        if(current_z>0){
            current_z--;            
        }
    }
    if(key == 'x'){
        if(current_z<objects.size() && objects.size()>0){
            current_z++;
        }
    }
    if(key == ' ' || key == OF_KEY_RETURN){
        if(current_sides!=0){
            if(current_object<0){
                if(current_sides!=0){
                    placeObject();
                }
            } else {
                edit();
            }
        }

    }
    if(key == OF_KEY_BACKSPACE){
        if(current_object>=0){
            deleteObject(current_object);            
        }
    }
}
コード例 #9
0
void CMapGenerator::createConnections2()
{
	for (auto & connection : connectionsLeft)
	{
		auto zoneA = connection.getZoneA();
		auto zoneB = connection.getZoneB();

		int3 guardPos(-1, -1, -1);

		int3 posA = zoneA->getPos();
		int3 posB = zoneB->getPos();

		auto strength = connection.getGuardStrength();

		if (posA.z != posB.z) //try to place subterranean gates
		{
			auto sgt = VLC->objtypeh->getHandlerFor(Obj::SUBTERRANEAN_GATE, 0)->getTemplates().front();
			auto tilesBlockedByObject = sgt.getBlockedOffsets();

			auto factory = VLC->objtypeh->getHandlerFor(Obj::SUBTERRANEAN_GATE, 0);
			auto gate1 = factory->create(ObjectTemplate());
			auto gate2 = factory->create(ObjectTemplate());

			while (!guardPos.valid())
			{
				bool continueOuterLoop = false;
				//find common tiles for both zones
				auto tileSetA = zoneA->getPossibleTiles(),
					tileSetB = zoneB->getPossibleTiles();

				std::vector<int3> tilesA(tileSetA.begin(), tileSetA.end()),
					tilesB(tileSetB.begin(), tileSetB.end());

				std::vector<int3> commonTiles;

				//required for set_intersection
				boost::sort(tilesA);
				boost::sort(tilesB);

				boost::set_intersection(tilesA, tilesB, std::back_inserter(commonTiles), [](const int3 &lhs, const int3 &rhs) -> bool
				{
					//ignore z coordinate
					if (lhs.x < rhs.x)
						return true;
					else
						return lhs.y < rhs.y;
				});

				vstd::erase_if(commonTiles, [](const int3 &tile) -> bool
				{
					return (!tile.x) || (!tile.y); //gates shouldn't go outside map (x = 0) and look bad at the very top (y = 0)
				});

				if (commonTiles.empty())
					break; //nothing more to do

				boost::sort(commonTiles, [posA, posB](const int3 &lhs, const int3 &rhs) -> bool
				{
					//choose tiles which are equidistant to zone centers
					return (std::abs<double>(posA.dist2dSQ(lhs) - posB.dist2dSQ(lhs)) < std::abs<double>((posA.dist2dSQ(rhs) - posB.dist2dSQ(rhs))));
				});

				for (auto tile : commonTiles)
				{
					tile.z = posA.z;
					int3 otherTile = tile;
					otherTile.z = posB.z;

					float distanceFromA = posA.dist2d(tile);
					float distanceFromB = posB.dist2d(otherTile);

					if (distanceFromA > 5 && distanceFromB > 5)
					{
						if (zoneA->areAllTilesAvailable(this, gate1, tile, tilesBlockedByObject) &&
							zoneB->areAllTilesAvailable(this, gate2, otherTile, tilesBlockedByObject))
						{
							if (zoneA->getAccessibleOffset(this, sgt, tile).valid() && zoneB->getAccessibleOffset(this, sgt, otherTile).valid())
							{
								EObjectPlacingResult::EObjectPlacingResult result1 = zoneA->tryToPlaceObjectAndConnectToPath(this, gate1, tile);
								EObjectPlacingResult::EObjectPlacingResult result2 = zoneB->tryToPlaceObjectAndConnectToPath(this, gate2, otherTile);

								if ((result1 == EObjectPlacingResult::SUCCESS) && (result2 == EObjectPlacingResult::SUCCESS))
								{
									zoneA->placeObject(this, gate1, tile);
									zoneA->guardObject(this, gate1, strength, true, true);
									zoneB->placeObject(this, gate2, otherTile);
									zoneB->guardObject(this, gate2, strength, true, true);
									guardPos = tile; //set to break the loop
									break;
								}
								else if ((result1 == EObjectPlacingResult::SEALED_OFF) || (result2 == EObjectPlacingResult::SEALED_OFF))
								{
									//sealed-off tiles were blocked, exit inner loop and get another tile set
									continueOuterLoop = true;
									break;
								}
								else
									continue; //try with another position
							}
						}
					}
				}
				if (!continueOuterLoop) //we didn't find ANY tile - break outer loop			
					break;
			}
			if (!guardPos.valid()) //cleanup? is this safe / enough?
			{
				delete gate1;
				delete gate2;
			}
		}
		if (!guardPos.valid())
		{
			auto factory = VLC->objtypeh->getHandlerFor(Obj::MONOLITH_TWO_WAY, getNextMonlithIndex());
			auto teleport1 = factory->create(ObjectTemplate());
			auto teleport2 = factory->create(ObjectTemplate());

			zoneA->addRequiredObject(teleport1, strength);
			zoneB->addRequiredObject(teleport2, strength);
		}
	}
}