int main() {
  Flower f;
  Bee ba("A"), bb("B");
  Hummingbird ha("A"), hb("B");
  f.openNotifier.addObserver(ha.openObserver());
  f.openNotifier.addObserver(hb.openObserver());
  f.openNotifier.addObserver(ba.openObserver());
  f.openNotifier.addObserver(bb.openObserver());
  f.closeNotifier.addObserver(ha.closeObserver());
  f.closeNotifier.addObserver(hb.closeObserver());
  f.closeNotifier.addObserver(ba.closeObserver());
  f.closeNotifier.addObserver(bb.closeObserver());
  // Hummingbird B decides to sleep in:
  f.openNotifier.deleteObserver(hb.openObserver());
  // Something changes that interests observers:
  f.open();
  f.open(); // It's already open, no change.
  // Bee A doesn't want to go to bed:
  f.closeNotifier.deleteObserver(
    ba.closeObserver());
  f.close();
  f.close(); // It's already closed; no change
  f.openNotifier.deleteObservers();
  f.open();
  f.close();
} ///:~
//When user clicks left button of mouse, draw flowers that painted in different color--> implement stretch goal J
void RoyalSociety_jiangy9LucyApp::mouseDown( MouseEvent event )
{
	gl::enableAlphaBlending();
	if(event.isLeftDown()){
		Flower* addFlower = new Flower();
		addFlower->set((*mySurface).getData(),(float)event.getX(),(float)event.getY(), addFlowerColor);
		insertAfter(first_item->previous,addFlower);
		click++;
	}
}
Exemple #3
0
 Tree(const Point* a, const Point* sun, const double& size) :
     PointObj(a, size), sun(sun), sflowers(1), kleafsize(1.0), kleafrate(1.0)
 {
     DefaultColor();
     DefaultSize();
     f.SetNumsRandom();
 }
Exemple #4
0
    void DefaultSize()
    {
        center.SetXY(x, y-size*Fi);

        l.SetSize(kleafsize*size/35);
        f.SetSize(size/25);
    }
Exemple #5
0
 Tree() : PointObj(getmaxx()/2, getmaxy()/2+200, 400.0),
     sun((int)(getmaxx()*Fi), 0), sflowers(1),
     kleafsize(1.0), kleafrate(1.0)
 {
     DefaultColor();
     DefaultSize();
     f.SetNumsRandom();
 }
Exemple #6
0
void specialFlowers(Flower **f, int n, Flower &c) {
    Flower* max;
    int m;
    for(int i = 0; i < n; ++i) {
        if(*f[i] == c) {
            max = f[i];
            m = i;
            break;
        }
    }
    for(int i = m; i < n; ++i) {
        if(f[i]->price() > max->price()
          && *f[i] == c) {
            max = f[i];
        }
    }
    cout << *max << endl;
}
Exemple #7
0
    Tree(const int& x, const int& y, const double& size) :
        PointObj(x, y, size), sflowers(1), kleafsize(1.0), kleafrate(1.0)
    {
        DefaultColor();
        DefaultSize();
        f.SetNumsRandom();

        if(getmaxx()/2-x > 0.0) sun.SetXY(getmaxx(), 0);
        else sun.SetXY(0, 0);
    }
Exemple #8
0
void Tree::Divis(const Point* begin, const Point* end, const int& color)
{
    double* dl = new double(begin->Range(end));
    if(*dl < kleafrate*size/33.3)
    {
        delete dl;
        return;
    }

    Point middle;

    double* rnd = new double(RND());

    if(begin->GetX() == end->GetX() || begin->GetY() == end->GetY())
    {
        int krnd = (*rnd <= 0.5) ? 1 : -1;

        if(begin->GetX() == end->GetX())
            middle.SetXY(begin->GetX() + ((begin->GetX() + krnd * *dl/2 > 0.0) ?
                                          krnd : -krnd) * *dl/2, min(begin->GetY(), end->GetY()) + *dl/2);

        if(begin->GetY() == end->GetY())
            middle.SetXY(min(begin->GetX(), end->GetX()) + *dl/2,
                         begin->GetY() + ((begin->GetY() + krnd * *dl/2 > 0.0) ?
                                          krnd : -krnd) * *dl/2);
    }
    else if(*rnd <= 0.5) middle.SetXY(begin->GetX(), end->GetY());
    else middle.SetXY(end->GetX(), begin->GetY());

    delete dl;

    double *chance = new double(center.Range(&sun)/middle.Range(&sun));

    if(sflowers != 0 && *rnd < 0.025 * *chance)
    {
        f = middle;
        f.Draw(color);
    }
    else
    {
        l = middle;
        if(*rnd < Fi / *chance / 0.8) l.Draw(color3);
        else l.Draw(color4);
    }

    delete chance;
    delete rnd;

    Divis(begin, &middle, color);
    Divis(&middle, end, color);
}
void getKeyboardPress(unsigned char key, int x, int y)
{
	switch (key)
	{
	case 27:
		exit(0);
	case 'w':
		walk_up();
		break;
	case 's':
		walk_down();
		break;
	case 'a':
		//cout << "a";
		walk_left();
		break;
	case 'd':
		walk_right();
		break;
	case 'q':
		turn_left();
		break;
	case 'e':
		turn_right();
		break;
	case 'f':
		if ((CreatFlower == false) && (CreatTree == false))
		{
			Flower* tem = new Flower;
			int temx, temy, temz;
			get_Groung_position(mouse_x, mouse_y, temx, temy, temz);
			tem->setPosition(temx, temz);
			tem->setAlpha(0.35f);
			flower_display_list.push_back(tem);
			CreatFlower = true;
		}
		coutstat();
		break;
	case 't':
		if ((CreatFlower == false) && (CreatTree == false))
		{
			Tree* tem = new Tree;
			int temx, temy, temz;
			get_Groung_position(mouse_x, mouse_y, temx, temy, temz);
			tem->setPosition(temx, temz);
			tree_display_list.push_back(tem);
			CreatTree = true;
		}
		coutstat();
		break;
	case 'z':
		save_all();
		break;
	case 'l':
		load_all();
		break;
	case 'r':
		if (CreatFlower == true)
		{
			flower_display_list[flower_display_list.size() - 1]->change_petal_R(0.1f);
		}
		coutstat();
		break;
	case 'g':
		if (CreatFlower == true)
		{
			flower_display_list[flower_display_list.size() - 1]->change_petal_G(0.1f);
		}
		coutstat();
		break;

	case 'b':
		if (CreatFlower == true)
		{
			flower_display_list[flower_display_list.size() - 1]->change_petal_B(0.1f);
		}
		coutstat();
		break;

	case 'n':
		if (CreatFlower == true)
		{
			flower_display_list[flower_display_list.size() - 1]->change_petal_NUM(1);
		}
		if (CreatTree == true)
		{
			tree_display_list[tree_display_list.size() - 1]->change_tree_level(1);
		}
		coutstat();
		break;

	case 'm':
		if (CreatFlower == true)
		{
			flower_display_list[flower_display_list.size() - 1]->change_petal_NUM(-1);
		}
		if (CreatTree == true)
		{
			tree_display_list[tree_display_list.size() - 1]->change_tree_level(-1);
		}
		coutstat();
		break;

	case 'p':
		is_snow = 1 - is_snow;
		snowcount = 0;
		coutstat();
		break;

	case 'o':
		if (have_wind) stop_wind();
		else start_wind();
		coutstat();
		break;

	case 'i':
		snow_down();
		break;

	case 'j':
		change_snow_level(-5);
		coutstat();
		break;

	case 'k':
		change_snow_level(5);
		coutstat();
		break;
	}

	

}
Exemple #10
0
int main(int argc, char *argv[])
{
	const char *handlerName = NULL;
	bool dumpIR = false;
	Flower flower;
	bool testMode = false;
	bool lexMode = false;
	int opt;
	int rv = 0;

	while ((opt = getopt(argc, argv, "tO:hLe:l")) != -1) { // {{{
		switch (opt) {
		case 'h':
			usage(argv[0]);
			return 0;
		case 'L':
			dumpIR = true;
			break;
		case 'l':
			lexMode = true;
			break;
		case 't':
			testMode = true;
			break;
		case 'O':
			flower.setOptimizationLevel(atoi(optarg));
			break;
		case 'e':
			handlerName = optarg;
			break;
		default:
			usage(argv[0]);
			return 1;
		}
	} // }}}

	if (optind >= argc) {
		printf("Expected argument after options.\n");
		return EXIT_FAILURE;
	}

	while (argv[optind]) {
		const char *fileName = argv[optind];
		++optind;

		if (lexMode) {
			printf("%s:\n", fileName);
			return lexdump(fileName);
		}

		if (testMode) {
			printf("%s:\n", fileName);
			rv = flower.runAll(fileName);
		} else {
			flower.run(fileName, handlerName);
		}

		if (dumpIR)
			flower.dump();

		flower.clear();
	}

	FlowRunner::shutdown();

	return rv;
}
void RoyalSociety_jiangy9LucyApp::setup()
{
	mySurface = new Surface(windowWidth, windowHeight, true);

	sky = new rectangle();
	grass = new rectangle();
	river = new rectangle();
	
	sun = new Circle();

	lineOne = new HorizonalLine();
	lineTwo = new HorizonalLine();
	lineThree = new VerticalLine();
	lineFour = new VerticalLine();

	line_1 = new Diagonal();
	line_2 = new Diagonal();
	line_3 = new Diagonal();
	line_4 = new Diagonal();
	line_5 = new Diagonal();
	line_6 = new Diagonal();
	line_7 = new Diagonal();
	line_8 = new Diagonal();
	line_9 = new Diagonal();
	line_10 = new Diagonal();
	line_11 = new Diagonal();

	line_12 = new Diagonal();
	line_13 = new Diagonal();
	line_14 = new Diagonal();
	line_15 = new Diagonal();
	line_16 = new Diagonal();
	line_17 = new Diagonal();
	line_18 = new Diagonal();
	line_19 = new Diagonal();
	line_20 = new Diagonal();
	line_21 = new Diagonal();
	line_22 = new Diagonal();

	line_23 = new Diagonal();
	line_24 = new Diagonal();
	line_25 = new Diagonal();
	line_26 = new Diagonal();
	line_27 = new Diagonal();
	line_28 = new Diagonal();
	line_29 = new Diagonal();
	line_30 = new Diagonal();
	line_31 = new Diagonal();
	line_32 = new Diagonal();
	line_33 = new Diagonal();

	line_34 = new Diagonal();
	line_35 = new Diagonal();
	line_36 = new Diagonal();
	line_37 = new Diagonal();
	line_38 = new Diagonal();
	line_39 = new Diagonal();
	line_40 = new Diagonal();
	line_41 = new Diagonal();
	line_42 = new Diagonal();
	line_43 = new Diagonal();
	line_44 = new Diagonal();

	flower1 = new Flower();
	flower2 = new Flower();
	flower3 = new Flower();
	flower4 = new Flower();
	flower5 = new Flower();
	flower6 = new Flower();
	flower7 = new Flower();
	flower8 = new Flower();

	//set up the first item of linked list
	first_item = new node;
	first_item->data = NULL;
	first_item->next = first_item;
	first_item->previous = first_item;

	currentNode = first_item->next;
	press = 0;

	gl::enableAlphaBlending();
	trans = 0.0f;

	click = 0;
	addFlowerColor = Color8u(255,174,201);

	reverseObject = 0;

	uint8_t* dataArray = (*mySurface).getData();

	//add objects into linked list --> implement main goals A
	sky->setRectangle(dataArray,0,0,windowWidth,400,1.0f,Color8u(146,227,241));        // sky
	insertAfter(first_item->previous,sky);
	grass->setRectangle(dataArray,0,401,windowWidth,500,1.0f,Color8u(33,237,64));      // grass
	insertAfter(first_item->previous,grass);

	//use transparency to build a color-changing river --> implement main goals G
	river->setRectangle(dataArray,0,650,windowWidth,windowHeight,sin(trans),Color8u(48,57,177));       // river
	insertAfter(first_item->previous,river);

	sun->setCircle(dataArray,40.0f,100.0f,100.0f,Color8u(241,3,3));              // sun
	insertAfter(first_item->previous,sun);
	
	lineOne->set(dataArray,10,50,100,Color8u(255,127,39));
	insertAfter(first_item->previous,lineOne);
	lineTwo->set(dataArray,150,190,100,Color8u(255,127,39));
	insertAfter(first_item->previous,lineTwo);

	lineThree->set(dataArray,10,50,100,Color8u(255,127,39));
	insertAfter(first_item->previous,lineThree);
	lineFour->set(dataArray,150,190,100,Color8u(255,127,39));
	insertAfter(first_item->previous,lineFour);

	
	line_1->set(dataArray,30,30,60,60,Color8u(255,127,39));
	insertAfter(first_item->previous,line_1);
	line_2->set(dataArray,30,31,60,61,Color8u(255,127,39));
	insertAfter(first_item->previous,line_2);
	line_3->set(dataArray,30,32,60,62,Color8u(255,127,39));
	insertAfter(first_item->previous,line_3);
	line_4->set(dataArray,30,33,60,63,Color8u(255,127,39));
	insertAfter(first_item->previous,line_4);
	line_5->set(dataArray,30,34,60,64,Color8u(255,127,39));
	insertAfter(first_item->previous,line_5);
	line_6->set(dataArray,30,35,60,65,Color8u(255,127,39));
	insertAfter(first_item->previous,line_6);
	line_7->set(dataArray,30,36,60,66,Color8u(255,127,39));
	insertAfter(first_item->previous,line_7);
	line_8->set(dataArray,30,37,60,67,Color8u(255,127,39));
	insertAfter(first_item->previous,line_8);
	line_9->set(dataArray,30,38,60,68,Color8u(255,127,39));
	insertAfter(first_item->previous,line_9);
	line_10->set(dataArray,30,39,60,69,Color8u(255,127,39));
	insertAfter(first_item->previous,line_10);
	line_11->set(dataArray,30,40,60,70,Color8u(255,127,39));
	insertAfter(first_item->previous,line_11);

	line_12->set(dataArray,135,135,165,165,Color8u(255,127,39));
	insertAfter(first_item->previous,line_12);
	line_13->set(dataArray,135,136,165,166,Color8u(255,127,39));
	insertAfter(first_item->previous,line_13);
	line_14->set(dataArray,135,137,165,167,Color8u(255,127,39));
	insertAfter(first_item->previous,line_14);
	line_15->set(dataArray,135,138,165,168,Color8u(255,127,39));
	insertAfter(first_item->previous,line_15);
	line_16->set(dataArray,135,139,165,169,Color8u(255,127,39));
	insertAfter(first_item->previous,line_16);
	line_17->set(dataArray,135,140,165,170,Color8u(255,127,39));
	insertAfter(first_item->previous,line_17);
	line_18->set(dataArray,135,141,165,171,Color8u(255,127,39));
	insertAfter(first_item->previous,line_18);
	line_19->set(dataArray,135,142,165,172,Color8u(255,127,39));
	insertAfter(first_item->previous,line_19);
	line_20->set(dataArray,135,143,165,173,Color8u(255,127,39));
	insertAfter(first_item->previous,line_20);
	line_21->set(dataArray,135,144,165,174,Color8u(255,127,39));
	insertAfter(first_item->previous,line_21);
	line_22->set(dataArray,135,145,165,175,Color8u(255,127,39));
	insertAfter(first_item->previous,line_22);


	line_23->set(dataArray,35,165,65,135,Color8u(255,127,39));
	insertAfter(first_item->previous,line_23);
	line_24->set(dataArray,35,166,65,136,Color8u(255,127,39));
	insertAfter(first_item->previous,line_24);
	line_25->set(dataArray,35,167,65,137,Color8u(255,127,39));
	insertAfter(first_item->previous,line_25);
	line_26->set(dataArray,35,168,65,138,Color8u(255,127,39));
	insertAfter(first_item->previous,line_26);
	line_27->set(dataArray,35,169,65,139,Color8u(255,127,39));
	insertAfter(first_item->previous,line_27);
	line_28->set(dataArray,35,170,65,140,Color8u(255,127,39));
	insertAfter(first_item->previous,line_28);
	line_29->set(dataArray,35,171,65,141,Color8u(255,127,39));
	insertAfter(first_item->previous,line_29);
	line_30->set(dataArray,35,172,65,142,Color8u(255,127,39));
	insertAfter(first_item->previous,line_30);
	line_31->set(dataArray,35,173,65,143,Color8u(255,127,39));
	insertAfter(first_item->previous,line_31);
	line_32->set(dataArray,35,174,65,144,Color8u(255,127,39));
	insertAfter(first_item->previous,line_32);
	line_33->set(dataArray,35,175,65,145,Color8u(255,127,39));
	insertAfter(first_item->previous,line_33);

	line_34->set(dataArray,135,60,165,30,Color8u(255,127,39));
	insertAfter(first_item->previous,line_34);
	line_35->set(dataArray,135,61,165,31,Color8u(255,127,39));
	insertAfter(first_item->previous,line_35);
	line_36->set(dataArray,135,62,165,32,Color8u(255,127,39));
	insertAfter(first_item->previous,line_36);
	line_37->set(dataArray,135,63,165,33,Color8u(255,127,39));
	insertAfter(first_item->previous,line_37);
	line_38->set(dataArray,135,64,165,34,Color8u(255,127,39));
	insertAfter(first_item->previous,line_38);
	line_39->set(dataArray,135,65,165,35,Color8u(255,127,39));
	insertAfter(first_item->previous,line_39);
	line_40->set(dataArray,135,66,165,36,Color8u(255,127,39));
	insertAfter(first_item->previous,line_40);
	line_41->set(dataArray,135,67,165,37,Color8u(255,127,39));
	insertAfter(first_item->previous,line_41);
	line_42->set(dataArray,135,68,165,38,Color8u(255,127,39));
	insertAfter(first_item->previous,line_42);
	line_43->set(dataArray,135,69,165,39,Color8u(255,127,39));
	insertAfter(first_item->previous,line_43);
	line_44->set(dataArray,135,70,165,40,Color8u(255,127,39));
	insertAfter(first_item->previous,line_44);

	//draw flowers in different colors from deep to light --> implement main goal H
	flower1->set(dataArray,490.0f,100.0f,Color8u(237,28,36));
	insertAfter(first_item->previous,flower1);
	flower2->set(dataArray,560.0f,150.0f,Color8u(240,66,74));
	insertAfter(first_item->previous,flower2);
	flower3->set(dataArray,600.0f,200.0f,Color8u(242,94,101));
	insertAfter(first_item->previous,flower3);
	flower4->set(dataArray,560.0f,250.0f,Color8u(244,117,123));
	insertAfter(first_item->previous,flower4);
	flower5->set(dataArray,490.0f,300.0f,Color8u(245,139,145));
	insertAfter(first_item->previous,flower5);
	flower6->set(dataArray,420.0f,250.0f,Color8u(248,165,169));
	insertAfter(first_item->previous,flower6);
	flower7->set(dataArray,350.0f,200.0f,Color8u(250,190,193));
	insertAfter(first_item->previous,flower7);
	flower8->set(dataArray,420.0f,150.0f,Color8u(252,220,222));
	insertAfter(first_item->previous,flower8);
}
Exemple #12
0
	bool SceneManager::LoadScene( string file_name )
	{
		cout<<"=========Loading Scene Config================"<<endl;
		ofxXmlSettings file;
		if(!file.loadFile(file_name))
		{
			cout<<"Cannot load "<<file_name<<endl;
			return false;
		}
		if(!file.tagExists("LevelIndex"))
		{
			cout<<"Cannot find LevelIndex"<<endl;
			return false;
		}

        ReadColorSet(file);
        
		file.pushTag("LevelIndex");
		for(size_t i =0; i < file.getNumTags("Level"); ++i)
		{
			vector<string> group_name;
			for(size_t i =0; i < file.getNumTags("Group"); ++i)
			{
				file.pushTag("Group",i);
				string name = file.getValue("Name","NONE");
				group_name.push_back(name);
				file.popTag();
			}
			level_index_.push_back(group_name);
		}
		file.popTag();

		SceneType scene;

		for(size_t i =0; i < file.getNumTags("Group"); ++i)
		{
			file.pushTag("Group",i);
			string name = file.getValue("Name","NONE");
			//if(name == group_name[i])
			{
				string type = file.getValue("Type","NONE");
				if(type == "Flower")
				{
					vector<Flower*> group_model;
					if(file.tagExists("GroupObj"))
					{
						file.pushTag("GroupObj");
						for(size_t j =0; j < file.getNumTags("Model"); ++j)
						{
							file.pushTag("Model",j);
							string url = file.getValue("ObjURL", "NA");
							ofVec3f pos;
							file.pushTag("Position");
							pos.set(file.getValue("X",0), file.getValue("Y",0), file.getValue("Z",0));
							file.popTag();
							float rotation = file.getValue("Rotation",0);
							float max_scale = file.getValue("MaxScale",0.1);
							float scale_speed = file.getValue("ScaleSpeed", 0.01);
							float staying_time = file.getValue("StayingTime", 1);
							float holding_time = file.getValue("HoldingTime", 1);
							float circle_size = file.getValue("CircleSize", 200);
							file.pushTag("CircleColor");
							ofColor color;
							color.set(file.getValue("R",255), file.getValue("G",255), file.getValue("B",255), file.getValue("A",255));
							file.popTag();
							file.pushTag("ModelColor");
							ofColor mcolor;
							mcolor.set(file.getValue("R",255), file.getValue("G",255), file.getValue("B",255), file.getValue("A",255));
							file.popTag();


							bool falling = file.getValue("FallingEnable", false);
							float pitch = file.getValue("Pitch", 1.0f);

							Flower* flower = new Flower();
							flower->loadModel(url);
							flower->setPosition(pos.x,pos.y,pos.z);
							flower->setRotation(0,180,1,0,0);
							flower->setRotation(1,rotation,0,0,1);
							flower->SetMaxScale(max_scale);
							flower->SetScaleSpeed(scale_speed);
							flower->staying_time_ = staying_time + ofRandom(-3, 3);
							flower->holding_time_ = holding_time;
							flower->SetCircleSize(circle_size);
							flower->SetCircleColor(color);
							flower->SetColor(mcolor);
							flower->SetFalling(falling);
							flower->SetPitch(pitch);
							flower->Enable(false);
							group_model.push_back(flower);
							file.popTag();
						}
						file.popTag();

						float group_staying_time= file.getValue("StayingTime",1);

						Group flower_group(name, group_staying_time, group_model, Group::LEAF);
						scene.push_back(flower_group);
					}
				}
				else
                if(type == "Mushroom")
                {
                    vector<Flower*> group_model;
					if(file.tagExists("GroupObj"))
					{
						file.pushTag("GroupObj");
						for(size_t j =0; j < file.getNumTags("Model"); ++j)
						{
							file.pushTag("Model",j);
							string url = file.getValue("ObjURL", "NA");
							ofVec3f pos;
							file.pushTag("Position");
							pos.set(file.getValue("X",0), file.getValue("Y",0), file.getValue("Z",0));
							file.popTag();
							float rotation = file.getValue("Rotation",0);
							float max_scale = file.getValue("MaxScale",0.1);
							float scale_speed = file.getValue("ScaleSpeed", 0.01);
							float staying_time = file.getValue("StayingTime", 1);
							float holding_time = file.getValue("HoldingTime", 1);
							float circle_size = file.getValue("CircleSize", 200);
							file.pushTag("CircleColor");
							ofColor color;
							color.set(file.getValue("R",255), file.getValue("G",255), file.getValue("B",255), file.getValue("A",255));
							file.popTag();
							file.pushTag("ModelColor");
							ofColor mcolor;
							mcolor.set(file.getValue("R",255), file.getValue("G",255), file.getValue("B",255), file.getValue("A",255));
							file.popTag();
                            
                            
							bool falling = file.getValue("FallingEnable", false);
							float pitch = file.getValue("Pitch", 1.0f);
                            
							Mushroom* flower = new Mushroom();
							flower->loadModel(url);
							flower->setPosition(pos.x,pos.y,pos.z);
							flower->setRotation(0,180,1,0,0);
							flower->setRotation(1,rotation,0,0,1);
							flower->SetMaxScale(max_scale);
							flower->SetScaleSpeed(scale_speed);
							flower->staying_time_ = staying_time + ofRandom(-3, 3);
							flower->holding_time_ = holding_time;
							flower->SetCircleSize(circle_size);
							flower->SetCircleColor(color);
							flower->SetColor(mcolor);
							flower->SetFalling(falling);
							flower->SetPitch(pitch);
							flower->Enable(false);
							group_model.push_back(flower);
							file.popTag();
						}
						file.popTag();
                        
						float group_staying_time= file.getValue("StayingTime",1);
                        
						Group flower_group(name, group_staying_time, group_model, Group::MUSHROOM);
						scene.push_back(flower_group);
					}
                }
                else
                if (type == "Fruit")
                {
                    vector<Flower*> group_model;
					if(file.tagExists("GroupObj"))
					{
						file.pushTag("GroupObj");
						for(size_t j =0; j < file.getNumTags("Model"); ++j)
						{
							file.pushTag("Model",j);
							string url = file.getValue("ObjURL", "NA");
							ofVec3f pos;
							file.pushTag("Position");
							pos.set(file.getValue("X",0), file.getValue("Y",0), file.getValue("Z",0));
							file.popTag();
							float rotation = file.getValue("Rotation",0);
							float max_scale = file.getValue("MaxScale",0.1);
							float scale_speed = file.getValue("ScaleSpeed", 0.01);
							float staying_time = file.getValue("StayingTime", 1);
							float holding_time = file.getValue("HoldingTime", 1);
							float circle_size = file.getValue("CircleSize", 200);
							file.pushTag("CircleColor");
							ofColor color;
							color.set(file.getValue("R",255), file.getValue("G",255), file.getValue("B",255), file.getValue("A",255));
							file.popTag();
							file.pushTag("ModelColor");
							ofColor mcolor;
							mcolor.set(file.getValue("R",255), file.getValue("G",255), file.getValue("B",255), file.getValue("A",255));
							file.popTag();
                            
                            
							bool falling = file.getValue("FallingEnable", false);
							float pitch = file.getValue("Pitch", 1.0f);
                            
							Flower* flower = new Flower();
							flower->loadModel(url);
							flower->setPosition(pos.x,pos.y,pos.z);
							flower->setRotation(0,180,1,0,0);
							flower->setRotation(1,rotation,0,0,1);
							flower->SetMaxScale(max_scale);
							flower->SetScaleSpeed(scale_speed);
							flower->staying_time_ = staying_time + ofRandom(-3, 3);
							flower->holding_time_ = holding_time;
							flower->SetCircleSize(circle_size);
							flower->SetCircleColor(color);
							flower->SetColor(mcolor);
							flower->SetFalling(falling);
							flower->SetPitch(pitch);
							flower->Enable(false);
							group_model.push_back(flower);
							file.popTag();
						}
						file.popTag();
                        
						float group_staying_time= file.getValue("StayingTime",1);
                        
						Group flower_group(name, group_staying_time, group_model, Group::FRUIT);
						scene.push_back(flower_group);
					}

                }
                else
				if(type == "Tree")
				{
					vector<Flower*> group_model;
					if(file.tagExists("GroupObj"))
					{
						file.pushTag("GroupObj");
						for(size_t j =0; j < file.getNumTags("Model"); ++j)
						{
							file.pushTag("Model",j);
							string url = file.getValue("ObjURL", "NA");
							ofVec3f pos;
							file.pushTag("Position");
							pos.set(file.getValue("X",0), file.getValue("Y",0), file.getValue("Z",0));
							file.popTag();
							float rotation = file.getValue("Rotation",0);
							float max_scale = file.getValue("MaxScale",0.1);
							float scale_speed = file.getValue("ScaleSpeed", 0.01);
							float staying_time = file.getValue("StayingTime", 1);
							float holding_time = file.getValue("HoldingTime", 1);
							float circle_size = file.getValue("CircleSize", 200);
							file.pushTag("CircleColor");
							ofColor color;
							color.set(file.getValue("R",255), file.getValue("G",255), file.getValue("B",255), file.getValue("A",255));
							file.popTag();
							file.pushTag("ModelColor");
							ofColor mcolor;
							mcolor.set(file.getValue("R",255), file.getValue("G",255), file.getValue("B",255), file.getValue("A",255));
							file.popTag();


							bool falling = file.getValue("FallingEnable", false);
							float pitch = file.getValue("Pitch", 1.0f);

							Tree* flower = new Tree();
							flower->loadModel(url);
							flower->setPosition(pos.x,pos.y,pos.z);
							flower->setRotation(0,180,1,0,0);
							flower->setRotation(1,rotation,0,0,1);
                            flower->setScale(0.4, 0.4, 0.4);
							flower->SetMaxScale(max_scale);
							flower->SetScaleSpeed(scale_speed);
							flower->staying_time_ = staying_time + ofRandom(-3, 3);
							flower->holding_time_ = holding_time;
							flower->SetCircleSize(circle_size);
							flower->SetCircleColor(color);
							flower->SetColor(mcolor);
							flower->SetFalling(falling);
							flower->SetPitch(pitch);
							flower->Enable(false);
							group_model.push_back(flower);
							file.popTag();
						}
						file.popTag();

						float group_staying_time= file.getValue("StayingTime",1);

						Group flower_group(name, group_staying_time, group_model, Group::TREE);
						scene.push_back(flower_group);
					}
				}
                else
                    if(type == "Cloud")
                    {
                        vector<Flower*> group_model;
                        if(file.tagExists("GroupObj"))
                        {
                            file.pushTag("GroupObj");
                            for(size_t j =0; j < file.getNumTags("Model"); ++j)
                            {
                                file.pushTag("Model",j);
                                string url = file.getValue("ObjURL", "NA");
                                ofVec3f pos;
                                file.pushTag("Position");
                                pos.set(file.getValue("X",0), file.getValue("Y",0), file.getValue("Z",0));
                                file.popTag();
                                float rotation = file.getValue("Rotation",0);
                                float max_scale = file.getValue("MaxScale",0.1);
                                float scale_speed = file.getValue("ScaleSpeed", 0.01);
                                float staying_time = file.getValue("StayingTime", 1);
                                float holding_time = file.getValue("HoldingTime", 1);
                                float circle_size = file.getValue("CircleSize", 200);
                                file.pushTag("CircleColor");
                                ofColor color;
                                color.set(file.getValue("R",255), file.getValue("G",255), file.getValue("B",255), file.getValue("A",255));
                                file.popTag();
                                file.pushTag("ModelColor");
                                ofColor mcolor;
                                mcolor.set(file.getValue("R",255), file.getValue("G",255), file.getValue("B",255), file.getValue("A",255));
                                file.popTag();
                                
                                
                                bool falling = file.getValue("FallingEnable", false);
                                float pitch = file.getValue("Pitch", 1.0f);
                                
                                Cloud* flower = new Cloud();
                                flower->loadModel(url);
                                flower->setPosition(pos.x,pos.y,pos.z);
                                flower->setRotation(0,180,1,0,0);
                                flower->setRotation(1,rotation,0,0,1);
                                flower->SetMaxScale(max_scale);
                                flower->SetScaleSpeed(scale_speed);
                                flower->staying_time_ = staying_time + ofRandom(-3, 3);
                                flower->holding_time_ = holding_time;
                                flower->SetCircleSize(circle_size);
                                flower->SetCircleColor(color);
                                flower->SetColor(mcolor);
                                flower->SetFalling(falling);
                                flower->SetPitch(pitch);
								flower->InitDroplet();
                                flower->Enable(false);
                                group_model.push_back(flower);
                                file.popTag();
                            }
                            file.popTag();
                            
                            float group_staying_time= file.getValue("StayingTime",1);
                            
                            Group flower_group(name, group_staying_time, group_model, Group::CLOUD);
                            scene.push_back(flower_group);
                        }
                    }
				

			}
			file.popTag();

			
		}

		dynamic_objects_ =  scene;
		return true;
	}
Exemple #13
0
void
WorkerBee::onState(State state, sf::Time dt)
{
    Vec2d empty(-1.0, -1.0);

    // first state
    if (state == IN_HIVE) {
        // if bee has pollen transfer it to hive
        if (getPollen() > 0) {
            transferPollen(dt);
            flower_location_ = empty;
            setDebugStatus("in_hive_leaving_pollen");
        } else {
            // if bee has not enough energy to leave hive, eat its nectar
            if (getEnergy() < energy_leave_hive_
                && getHive().getNectar() > 0) {
                setDebugStatus("in_hive_eating");
                eatFromHive(dt);
            }
            // if there is a flower in memory and enough energy, target move
            // to this flower
            else if (flower_location_ != empty
                     && getEnergy() > energy_collect_pollen_) {
                setDebugStatus("in_hive_leaving");
                setMoveTarget(flower_location_);
                // change state to to flower
                nextState();
            } else {
                setDebugStatus("in_hive_no_flower");
            }
        }
    }

    // second state
    else if (state == TO_FLOWER) {
        setDebugStatus("to_flower");

        if (getEnergy() < energy_collect_pollen_) {
            nextState();
            nextState();
        }

        Flower* flower  = getAppEnv().getCollidingFlower(getVisionRange());

        if (flower) {
            setMoveTarget(flower->getPosition());
            setMoveState(MoveState::TARGET);
            if (isPointInside(flower->getPosition())) {
                nextState();
            }
        } else if (isPointInside(flower_location_)) {
            // go back to hive and clear location
            nextState();
            nextState();
            setFlowerLocation(Vec2d(-1,-1));
        }
    }

    // third state
    else if (state == COLLECT_POLLEN) {
        // if there is a flower at flower location and it has pollen and
        // bee has not enough pollen, eat pollen from flower
        Flower* flower(getAppEnv().getCollidingFlower(getCollider()));
        if ((getPollen() < max_pollen_)
            && (flower != nullptr)
            && (flower->getPollen() > 0)) {
            eatPollen(flower, dt);
        } else {
            // else skip collection
            nextState();
        }
    } else if (state == RETURN_HIVE) {
        // if bee is in hive change state to in hive
        if (getHive().isColliderInside(getCollider())) {
            nextState();
        }
    }
}