bool bfs(int u) {
		for (int i = 0; i <= n; i++)
			belong[i] = i;
		memset(state, -1, sizeof(state[0])*(n+1));
		queue<int> q;
		q.push(u), state[u] = 0;
		while (!q.empty()) {
			u = q.front(), q.pop();
			for (int i = 0; i < g[u].size(); i++) {
				int v = g[u][i];
				if (state[v] == -1) {
					parent[v] = u, state[v] = 1;
					if (match[v] == 0) {
						for (int prev; u; v = prev, u = parent[v]) {
							prev = match[u];
							match[u] = v;
							match[v] = u;
						}
						return 1;
					}
					q.push(match[v]), state[match[v]] = 0;
				} else if (state[v] == 0 && belong[v] != belong[u]) {
					int l = lca(u, v);
					flower(v, u, l, q);
					flower(u, v, l, q);
				}
			}
		}
		return 0;
	}
示例#2
0
void main()
{
	initgraph(640,480);
	//»­Ö¦¸É
	setcolor(GREEN);
	line(189,3372,180,400); 
	line(310,160,325,68); 
	line(310,160,325,374); 
	line(150,140,189,374); 
	line(430,176,190,374); 
	line(370,110,187,374); 
	line(250,72,189,372); 
	line(253,192,190,374); 
	line(189,372,287,400); 
	line(189,372,182,400);
	line(189,372,200,120); 
	
	//»­»¨¶ä
	flower(320,160,RED); 
	flower(200,120,YELLOW); 
	flower(150,140,LIGHTRED); 
	flower(430,176,RGB(255,127,0)); 
	flower(370,110,RGB(239,179,52)); 
	flower(250,72,RGB(235,95,186)); 
	flower(325,68,RGB(228,119,98)); 
	flower(253,68,RGB(247,169,117)); 
	
	//»­ºûµû½á
	tie(195,354,LIGHTMAGENTA);
	
	//Í˳ö 
	getch() ;
	closegragh();

}
示例#3
0
//main display loop, this function will be called again and again by OpenGL
void display()
{
	//Misc.
	glClear(GL_COLOR_BUFFER_BIT);
	glLoadIdentity();

	radialGradient(WIDTH/2, HEIGHT/2, sqrt(2)*WIDTH/2);

	setColor(0, 0, 1);

	flower(100, 100, 100, 10);

	setColor(0, 0, 0);

	for (int i = 0; i < 4; i++) {
		bresenhamLine(D[i * 2], D[i * 2 + 1], D[i * 2 + 2], D[i * 2 + 3]);
	}

	for (int i = 0; i < 5; i++) {
		bresenhamLine(F[i * 2], F[i * 2 + 1], F[i * 2 + 2], F[i * 2 + 3]);
	}

	//draws pixel on screen, width and height must match pixel buffer dimension
	glDrawPixels(WIDTH, HEIGHT, GL_RGB, GL_FLOAT, PixelBuffer);

	//window refresh
	glFlush();
}
示例#4
0
文件: 1012.c 项目: wgjak47/ACM-UVA
main()
{
    int a;
    scanf("%d",&a);
    if (flower(a)==1)
    printf("YES");
    else printf("NO");
}
示例#5
0
bool run()
{
 flower("run");
 
 //process
 
 profile profile;  
 string message;
  
 if(is_executable())
 {
  //executable
 
  _make.run();
 
  //command
  
  message=_make.run_command().literal();
 } 
 else if(is_ast())
 {
  //ast
 
  shell("tail",_make.output_path());  
 }
 else
  stop(); 
  
 //report
 
 string buffer;

 buffer.space(profile.string_());
 buffer.space(execute("du","-h",_make.output_path()).inline_().literal());
 buffer.space(message);

 flower(buffer,"*");

 return true;
}
示例#6
0
 void show()
 {
  flower(_self_path,"*");
  
  log(*this);

  log();
  log(_make);
  
  log();
  log(describe());
  
  log();
  log(_make.describe());
 }
bool flow(int s){
	memset(mtp, -1, sizeof(mtp));
	while(qu.size()) qu.pop();
	qu.push(s);
	mtp[s] = 0; bk[s] = pr[s] = -1;

	while(qu.size() && pr[s] == -1){
		int u = qu.front(); qu.pop();
		for(int v=0; v<V; v++){
			
			if (el[u][v] == 0) continue;
			if (ffa(v) == ffa(u)) continue;

			if(pr[v] == -1){
				do{
					int t = pr[u];
					pr[v] = u; pr[u] = v;
					v = t; u = t==-1?-1:bk[t];
				}while( v != -1 );
				break;
			}else if(mtp[v] == 0){
				int w = lca(u, v);	
				if(ffa(w) != ffa(u)) bk[u] = v;
				if(ffa(w) != ffa(v)) bk[v] = u;
				flower(u, w);
				flower(v, w);
			}else if(mtp[v] != 1){
				bk[v] = u;
				mtp[v] = 1;
				mtp[pr[v]] = 0;
				qu.push(pr[v]);
			}
		}
	}
	return pr[s] != -1;
}
inline bool bfs(int x){
	for(int i=1;i<=n;++i)st[i]=i;
	memset(S+1,-1,sizeof(int)*n);
	queue<int>q;qpush(x);
	while(q.size()){
		x=q.front(),q.pop();
		for(size_t i=0;i<g[x].size();++i){
			int y=g[x][i];
			if(S[y]==-1){
				pa[y]=x,S[y]=1;
				if(!match[y]){
					for(int lst;x;y=lst,x=pa[y])
						lst=match[x],match[x]=y,match[y]=x;
					return 1;
				}
				qpush(match[y]);
			}else if(!S[y]&&st[y]!=st[x]){
				int l=lca(y,x);
				flower(y,x,l,q),flower(x,y,l,q);
			}
		}
	}
	return 0;
}
 vector<int> countSmaller(vector<int>& nums) {
     vector<flower> n;
     for (int i =0;i<nums.size();i++){
         n.push_back(flower(i,nums[i],0));
     }
     mergeSort(0,nums.size()-1,n);
     //for (auto i:n){
       //  cout << i.val << endl;
     //}
     sort(n.begin(),n.end());
     vector<int> r;
     for (auto i: n){
         r.push_back(i.count);
     }
     return r;
 }
示例#10
0
GLfloat* calculateColor(GLfloat u, GLfloat v){
	switch(fracCount)
	{
		case 0: 
					juliaSpecial=0.5;
					return greenJulia(u,v);
					break;
		case 1:

			juliaSpecial=0.0;
			return mandelbrot(u,v);
					break;
		case 2:

			//color=0;
			juliaSpecial=0.5;
			return mandelbrot3(u,v);
			break;
		case 3:
			//	printf("Flower\n");
				juliaSpecial=0.0;
				//color=0.0;
				return flower(u,v);
				break;
		case 4:
			//printf("Star\n");
			juliaSpecial=0.9;
			//color=45;
			return starFractal(u,v);
			break;
		case 5: 
			//printf("Julia\n");
			//color=0;
			juliaSpecial=0.5;
			return julia(u,v);
					break;
		default: 
			//printf("default\n");
			//juliaSpecial=0.0;
			fracCount=0;
			glutPostRedisplay();
			//return mandelbrot(u,v);
			break;

	}
}
示例#11
0
void flower(string message)
{
 flower(message,"-");
}
int main()
{
  //shape
  typedef Flower2D<Z2i::Space> Flower; 
  Flower2D<Z2i::Space> flower(Z2i::Point(0,0), 20, 5, 5, 0);
  
  //! [shapeGridCurveEstimator-dig]
  //implicit digitization of a shape of type Flower 
  //into a digital space of type Space
  double h = 1; 
  GaussDigitizer<Z2i::Space,Flower> dig;  
  dig.attach( flower );
  dig.init( flower.getLowerBound()+Z2i::Vector(-1,-1),
            flower.getUpperBound()+Z2i::Vector(1,1), h ); 
  //! [shapeGridCurveEstimator-dig]
  
  //! [shapeGridCurveEstimator-prepareTracking]
  //Khalimsky space
  Z2i::KSpace ks;
  ks.init( dig.getLowerBound(), dig.getUpperBound(), true );
  //adjacency (4-connectivity)
  SurfelAdjacency<2> sAdj( true );
  //! [shapeGridCurveEstimator-prepareTracking]

  //! [shapeGridCurveEstimator-tracking]
  //searching for one boundary element
  Z2i::SCell bel = Surfaces<Z2i::KSpace>::findABel( ks, dig, 1000 );
  //tracking
  vector<Z2i::Point> boundaryPoints;
  Surfaces<Z2i::KSpace>
    ::track2DBoundaryPoints( boundaryPoints, ks, sAdj, dig, bel );
  //! [shapeGridCurveEstimator-tracking]

  //! [shapeGridCurveEstimator-instantiation]
  Z2i::Curve c;
  c.initFromVector( boundaryPoints );  
  //! [shapeGridCurveEstimator-instantiation]
  
  DGtal::Board2D aBoard;
  aBoard << c; 
  aBoard.saveEPS("DisplayGridCurve1.eps");  
  
  //! [shapeGridCurveEstimator-getRange]
  //range of points
  typedef Z2i::Curve::PointsRange Range; 
  Range r = c.getPointsRange(); 
  //! [shapeGridCurveEstimator-getRange]
  
  //! [shapeGridCurveEstimator-lengthEstimation]
  //length estimation
  DSSLengthEstimator< Range::ConstIterator > DSSlength;
  DSSlength.init( h, r.begin(), r.end(), c.isClosed() );
  double length1 = DSSlength.eval();
  trace.info() << "Length (h=" << h << "): " << length1 << endl; 
  //! [shapeGridCurveEstimator-lengthEstimation]

//@TODO correct init method of trueLengthEstimator (remove &flower)
  //! [shapeGridCurveEstimator-trueLengthEstimation]
  typedef ParametricShapeArcLengthFunctor< Flower > Length;
  TrueGlobalEstimatorOnPoints< 
    Range::ConstIterator, 
    Flower, 
    Length  >  trueLengthEstimator;
  trueLengthEstimator.init( h, r.begin(), r.end(), &flower, c.isClosed());
  double trueLength = trueLengthEstimator.eval(); 
  trace.info() << "ground truth: " << trueLength << endl; 
  //! [shapeGridCurveEstimator-trueLengthEstimation]

  //! [shapeGridCurveEstimator-higher]
  //implicit digitization at higher resolution
  h = 0.1; 
  dig.init( flower.getLowerBound()+Z2i::Vector(-1,-1),
            flower.getUpperBound()+Z2i::Vector(1,1), h ); 
  //a greater domain is needed in the Khalimsky space
  ks.init( dig.getLowerBound(), dig.getUpperBound(), true );
  //searching for one boundary element
  bel = Surfaces<Z2i::KSpace>::findABel( ks, dig, 10000 );
  //tracking
  Surfaces<Z2i::KSpace>
    ::track2DBoundaryPoints( boundaryPoints, ks, sAdj, dig, bel );
  //reset grid curve and its points range
  c.initFromVector( boundaryPoints );
  Range r2 = c.getPointsRange(); 
  //estimate length
  DSSlength.init( h, r2.begin(), r2.end(), c.isClosed() );
  double length2 = DSSlength.eval();
  trace.info() << "Length (h=" << h << "): " << length2 << endl;  
  //! [shapeGridCurveEstimator-higher]
  
  aBoard.clear(); 
  aBoard << c; 
  aBoard.saveEPS("DisplayGridCurve01.eps");  
  
  return 0;

}
示例#13
0
void mainLevel(RenderWindow &window)
{
	//>>>>>>>>>>>>>>>---Level---<<<<<<<<<<<<<<<<<<<<<<<<<<<
	 Level lvl;
	 lvl.LoadFromFile("map.tmx");

	//>>>>>>>>>>>>>>>>---Load basic image for level1----<<<<<<<<<<<<<<<<<
	Texture texture;
	texture.loadFromFile("images/level1empty.jpg");
	Sprite level(texture);

	Texture texture2; 
	texture2.loadFromFile("images/levelShad.png");
	Sprite level2(texture2);

	Texture texture3;
	texture3.loadFromFile("images/level12.png");
	Sprite level3(texture3);
	//>>>>>>>>>>>>>>>>---Music---<<<<<<<<<<<<<<<<<<<<<<<<<<
	 Music mainSong;
	 Music skyrim, muse, bathMus;
	 bathMus.openFromFile("music/bath.ogg");
	 Object mus = lvl.GetObject("muse");
	 muse.openFromFile("music/synd.ogg"); muse.setVolume(100);
	 skyrim.openFromFile("music/skyrim.ogg"); skyrim.setVolume(100);
	 mainSong.openFromFile("music/level1.ogg");
	 mainSong.play();
	 mainSong.setLoop(true);
	 mainSong.setVolume(75);

	 //>>>>>>>>>>>>>>>>---Create a cat---<<<<<<<<<<<<<<<<<<<
	 Object player = lvl.GetObject("cat");
	 Object fish = lvl.GetObject("fish");
	 Object mo = lvl.GetObject("mouse");
	 Object ob = lvl.GetObject("catPlace");


	 Player cat("cat.png", lvl, 68, 429, 60, 120, player.rect.left,  player.rect.top, ELSE);
	 
	 Clock clock;
	 Clock gameTimeClock;
	 int sinkCnt = 0;

	 //>>>>>>>>>>>>>>>>---Sounds----<<<<<<<<<<<<<<<<<<<
	SoundBuffer buf1, buf2;
	buf1.loadFromFile("music/meow1.ogg");
	buf2.loadFromFile("music/meow2.ogg");
	Sound meow1, meow2;
	meow1.setBuffer(buf1);
	meow2.setBuffer(buf2);

	SoundBuffer buf, buf3;
	buf.loadFromFile("music/steklo.ogg");
	buf3.loadFromFile("music/mouse.ogg");
	Sound glass; Sound mouseS;
	glass.setBuffer(buf); glass.setVolume(100);
	mouseS.setBuffer(buf3);
	
	 //Objects
	 Furniture posters("tayles1.png",  160, 660, 210, 250, 280, 215, POSTERS);
	 Furniture bed("tayles1.png", 420, 80, 280, 310, 250, 440, ELSE); 
	 Furniture toys("tayles1.png", 120, 470, 180, 150, 220, 545, TOYS);
	 Furniture upShelf("tayles1.png", 700, 652.5, 120, 97.5, 350, 83, SHELF);
	 Furniture cabinet("tayles1.png", 75, 40, 250, 350, 605, 305, CABINET); 
	 Furniture mop("tayles1.png", 515, 785, 165, 241, 587, 385, MOP); 
	 Furniture flower("tayles1.png",780, 65, 170, 330, 147, 285, ELSE);
	 Furniture ball("tayles1.png", 905, 615, 40, 55, 357, 190, BALL); 
	 Furniture books("tayles1.png", 860, 735, 125, 80, 290, 187, BOOKS); 
	 Furniture brokenBall("tayles1.png",920, 540, 90, 42, 430, 430, ELSE); 
	 Furniture key("tayles1.png", 1, 1, 25, 25, 430, 425, KEY);
	 Furniture cabinetEnd("cabinet.png", 20, 50, 270, 350, 590, 290, ELSE); 
	 Furniture girl("girlHair.png", 1,1, 96, 45, 1075, 350, ELSE);
	 
	 Furniture door("tayles2.png", 0, 560, 80, 340, 870, 350, ELSE);
	 Furniture puddle("tayles1.png",789, 1000, 204, 75, 1057, 559, ELSE);
	 Furniture brokenLight("tayles2.png", 10, 110, 50, 70, 795, 430, ELSE);
	 Furniture light("tayles2.png", 20, 20, 35, 70, 220, 565, ELSE);
	 Furniture bath("tayles2.png", 80, 50, 320, 380, 1010, 330, BATH);
	 Furniture openBath("bathr.png", 264, 79, 339, 369, 1015, 315, ELSE);
	 Furniture carpet("tayles2.png", 100, 500, 100, 140, 870, 530, ELSE);
	 Furniture mirror("tayles2.png", 90, 700, 110, 290, 1200, 300, ELSE);
	 Furniture sink("tayles2.png", 290, 440, 150, 240, 1190, 450, SINK);
	 Furniture sinkWater("bathr.png", 22, 180, 197, 427, 1200, 540, ELSE);
	 Furniture mou("mouse.png",  2, 21, 32, 25, mo.rect.left, mo.rect.top, ELSE);
	 
	 
	 std::list<Furniture> fList;
	 std::list<Furniture>::iterator it;
	 fList.push_back(posters);
	 fList.push_back(toys);
	 fList.push_back(upShelf);
	 fList.push_back(cabinet);
	 fList.push_back(mop);
	 fList.push_back(ball);
	 fList.push_back(books);
	 fList.push_back(key);
	 fList.push_back(puddle);
	 fList.push_back(brokenLight);
	 fList.push_back(bath);
	 fList.push_back(sink);
	 for(it = fList.begin(); it != fList.end(); it++){
		 it->setSub((void *)&it, writeMess);
	 }

	 int cntMeow = 1, cntGame = 0, click = 0, clickBath = 1, clickSink = 1;
	 bath.isPlayed = true;
	 sink.isPlayed = true;


	  while (window.isOpen())
    {
		
		float time = clock.getElapsedTime().asMicroseconds();
		float sinkTime = gameTimeClock.getElapsedTime().asSeconds();
		if(clickSink < 2)
			gameTimeClock.restart();
		clock.restart();
		time = time/500;
		Vector2i pos = Mouse::getPosition(window);
		
		Event event;
		while (window.pollEvent(event))
		{
			if (event.type == sf::Event::Closed)
				window.close();

			if (event.type == Event::MouseButtonPressed)
				if (event.key.code == Mouse::Left){

					if (fish.rect.contains(pos.x, pos.y) && key.isPlayed == true){
						mainSong.stop();
						finish();
						window.close();
					}
					if (cat.sprite.getGlobalBounds().contains(pos.x, pos.y))
					{
						cntMeow++;
						if(cntMeow == 5)
						{
							meow2.play();
							cntMeow = 0;
						}
						else
							meow1.play();
					}
					 
					toys.trueMove(pos);
					if(light.isPlayed == false) light.trueMove(pos);
					if(ball.isPlayed == true && books.isPlayed == true) key.trueMove(pos);
					if(puddle.isPlayed == true) mop.trueMove(pos);
					click = light.clickedThings(pos);
					clickBath = bath.clickedThings(pos);
					clickSink = sink.clickedThings(pos);


					if (upShelf.sprite.getGlobalBounds().contains(pos.x, pos.y)){
						skyrim.play();
					}
					if (mus.rect.contains(pos.x, pos.y)){
						muse.play();
					}
					if (girl.sprite.getGlobalBounds().contains(pos.x, pos.y) && cat.room == 2){
						mainSong.pause();
						gameOver();
						mainSong.play();
					}
					if(mou.isPlayed == false)
						{
							if (mou.sprite.getGlobalBounds().contains(pos.x, pos.y))
							{
								mainSong.pause();
								mouseS.play();
								//gameRunning();
								mou.isPlayed = true;
								mainSong.play();
							}
						}

						if(books.isPlayed == false)
						{
							if (books.sprite.getGlobalBounds().contains(pos.x, pos.y))
							{
								mainSong.pause();
								MiniGame_Books();
								books.isPlayed = true;
								mainSong.play();
							}
						}
				}
					
			if (event.type == Event::MouseButtonReleased)
				if (event.key.code == Mouse::Left){
					toys.isMove = false;
					key.isMove = false;
					if(light.isPlayed == false) light.isMove = false;
					 mop.isMove = false;
				}
		}
		if(sinkTime > 5 && clickSink == 2) puddle.isPlayed = true;

		if(clickBath == 2 && cat.room == 2)
			bathMus.play();

		if(click == -1){}
		else if(click == 1 || click == 2)
			cat.room = click;
		toys.intersect("toys",lvl); toys.move(pos); 
		if(mop.isPlayed == false)
		{
			mop.intersect("mop", lvl);
			mop.move(pos);
		}
		if(light.isPlayed == false) 
		{
			light.intersect("light", lvl);
			light.move(pos);
		}
		if(ball.isPlayed == true && books.isPlayed == true){
			if(mop.isPlayed == true)
				key.intersect("key", lvl);
			if(key.isPlayed == false)
				key.move(pos);
		}
		if(ball.isPlayed == false && books.isPlayed == true){
			if(cat.sprite.getGlobalBounds().intersects(ob.rect))
			{
				if(cntMeow == 0)
				{
					ball.falling(event, window, pos, lvl, time);
					glass.play();
					ball.isPlayed = true;
					ball.intersect("ball", lvl);
				}
			}
		}
        
      
		cat.Update(time);

		window.clear(Color::Black);
		lvl.Draw(window);
		if(cat.room == 0)
			window.draw(level);
		if(cat.room == 1)
			window.draw(level2); 
		if(cat.room == 2)
			window.draw(level3);
			
		window.draw(posters.sprite);
		window.draw(bed.sprite);
		if(key.isPlayed == true)
			window.draw(cabinetEnd.sprite);
		else
			window.draw(cabinet.sprite);
		window.draw(upShelf.sprite);
		window.draw(flower.sprite);
		if(ball.isPlayed == false)
			window.draw(ball.sprite);
		else
		{
			window.draw(brokenBall.sprite);
			window.draw(key.sprite);
		}
		window.draw(books.sprite);

		
		if(mou.isPlayed == false){
			window.draw(mou.sprite);
		}
		else
			window.draw(light.sprite);
		window.draw(toys.sprite);


		if(cat.room == 2){
				
			 if(clickBath == 2){
				window.draw(girl.sprite);
				window.draw(openBath.sprite);
			 }
			 else
				 window.draw(bath.sprite);
			window.draw(mirror.sprite);

			 if(clickSink == 2)
				window.draw(sinkWater.sprite);
			 else
				 window.draw(sink.sprite);

			 if(puddle.isPlayed == true && mop.isPlayed == false)
				window.draw(puddle.sprite);
		}

		if(cat.room == 1 || cat.room == 2){
			if(light.isPlayed == false)
			window.draw(brokenLight.sprite);
			window.draw(carpet.sprite);
			window.draw(door.sprite);
		}
		if(mop.isPlayed == false)
			window.draw(mop.sprite);
		window.draw(cat.sprite);

		for(it = fList.begin(); it != fList.end(); it++)
			{
				if(it->sprite.getGlobalBounds().contains(pos.x, pos.y))
				{
					if(it->f.cb_fn != NULL)
					{
						cb_fn fn;
						fn = (cb_fn)it->f.cb_fn;
						fn(&window, it->type, &pos);
					}
				}
			}
		
		window.display();
    }

}
示例#14
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();
        }
    }
}
示例#15
0
 void clean()
 {
  flower("clean");
  
  _make.clean(); 
 }
示例#16
0
void mainLevel(RenderWindow &window)
{
	//>>>>>>>>>>>>>>>---Level---<<<<<<<<<<<<<<<<<<<<<<<<<<<
	 Level lvl;
	 lvl.LoadFromFile("map.tmx");

	//>>>>>>>>>>>>>>>>---Load basic image for level1----<<<<<<<<<<<<<<<<<
	Texture texture;
	texture.loadFromFile("images/level1empty.jpg");
	Sprite level(texture);

	Texture texture2; 
	texture2.loadFromFile("images/levelShad.png");
	Sprite level2(texture2);

	Texture texture3;
	texture3.loadFromFile("images/level12.png");
	Sprite level3(texture3);
	//>>>>>>>>>>>>>>>>---Music---<<<<<<<<<<<<<<<<<<<<<<<<<<
	 Music mainSong;
	 mainSong.openFromFile("music/level1.ogg");
	 mainSong.play();
	 mainSong.setLoop(true);
	 mainSong.setVolume(75);

	 //>>>>>>>>>>>>>>>>---Create a cat---<<<<<<<<<<<<<<<<<<<
	 Object player = lvl.GetObject("cat");
	 Player cat("cat.png", lvl, player.rect.left, player.rect.top, 60, 120, 55, 25);
	 Clock clock;

	 //>>>>>>>>>>>>>>>>---Sounds----<<<<<<<<<<<<<<<<<<<
	SoundBuffer buf1, buf2;
	buf1.loadFromFile("music/meow1.ogg");
	buf2.loadFromFile("music/meow2.ogg");
	Sound meow1, meow2;
	meow1.setBuffer(buf1);
	meow2.setBuffer(buf2);

	SoundBuffer buf;
	buf.loadFromFile("music/steklo.ogg");
	Sound glass;
	glass.setBuffer(buf); glass.setVolume(100);

	 //Objects
	 Furniture posters("tayles1.png",  160, 660, 210, 250, 280, 215);
	 Furniture bed("tayles1.png", 420, 80, 280, 310, 250, 440);
	 Furniture toys("tayles1.png", 120, 470, 180, 150, 220, 545);
	 Furniture upShelf("tayles1.png", 700, 652.5, 120, 97.5, 350, 83);
	 Furniture cabinet("tayles1.png", 75, 40, 250, 350, 605, 305);
	 Furniture mop("tayles1.png", 515, 785, 165, 241, 587, 385);
	 Furniture flower("tayles1.png",780, 65, 170, 330, 147, 285);
	 Furniture ball("tayles1.png", 905, 615, 40, 55, 357, 190);
	 Furniture books("tayles1.png", 860, 735, 125, 80, 290, 187);
	 Furniture brokenBall("tayles1.png",920, 540, 90, 42, 430, 430);
	 
	 Furniture door("tayles2.png", 0, 560, 80, 340, 870, 350);
	 Furniture brokenLight("tayles2.png", 10, 110, 50, 70, 795, 430);
	 Furniture light("tayles2.png", 20, 20, 35, 70, 220, 565);
	 Furniture bath("tayles2.png", 80, 50, 320, 380, 1010, 330);
	 Furniture carpet("tayles2.png", 100, 500, 100, 140, 870, 530);
	 Furniture mirror("tayles2.png", 90, 700, 110, 290, 1200, 300);
	 Furniture sink("tayles2.png", 290, 440, 150, 240, 1190, 450);
	 int cntMeow = 0;
	 Object ob = lvl.GetObject("catPlace");
	  while (window.isOpen())
    {
		
		float time = clock.getElapsedTime().asMicroseconds();
		clock.restart();
		time = time/500;
		Vector2i pos = Mouse::getPosition(window);

        Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();

			if (event.type == Event::MouseButtonPressed){
					if (event.key.code == Mouse::Left)
					{
						int cntMeow = meow(meow1, meow2, cat, pos);
						//>>>>>>BALL<<<<<<<<<<<<<<
						if(cat.sprite.getGlobalBounds().intersects(ob.rect))
						{
							if(cntMeow == -1)
							{
								ball.falling(event, window, pos, lvl, time);
								glass.play();
								ball.moving(event, window, pos, "ball", lvl);
							}
						}
						cat.clickedThings(window, light);
						//BOOKS>>>>----<<<<<<
						if(books.isPlayed == false)
						{
							if (books.sprite.getGlobalBounds().contains(pos.x, pos.y))
							{
								mainSong.pause();
								MiniGame_Books();
								books.isPlayed = true;
								mainSong.play();
							}
						}

					}
			}		
					
					toys.moving(event, window, pos, "toys", lvl);
					if(light.isPlayed == false)
						light.moving(event, window, pos, "light", lvl);
					

	
        }
		
		

		cat.Update(time);

		window.clear(Color::Black);
		lvl.Draw(window);
		if(cat.room == 0)
			window.draw(level);
		if(cat.room == 1)
			window.draw(level2); 
		if(cat.room == 2)
			window.draw(level3);
			
		window.draw(posters.sprite);
		window.draw(bed.sprite);
		window.draw(light.sprite);
		window.draw(toys.sprite);
		window.draw(upShelf.sprite);
		window.draw(cabinet.sprite);
		window.draw(mop.sprite);
		window.draw(flower.sprite);
		if(ball.isPlayed == false)
			window.draw(ball.sprite);
		else
			window.draw(brokenBall.sprite);
		window.draw(books.sprite);



		if(cat.room == 2){
			window.draw(bath.sprite);
			window.draw(mirror.sprite);
			window.draw(sink.sprite);
		}

		if(cat.room == 1 || cat.room == 2){
			if(light.isPlayed == false)
			window.draw(brokenLight.sprite);
			window.draw(carpet.sprite);
			window.draw(door.sprite);
		}
		

		window.draw(cat.sprite);
		
		window.display();
    }

}
示例#17
0
	void game::generate_library()
	{
		m_library = std::make_shared<library>();

		// buffs
		rl::person::status_t poison(10, [&](rl::person &c, rl::person::status_t &s) { c.health() = c.health() - 1; });
		poison.register_apply([&](rl::person &target, rl::person::status_t &s)
		{
			m_broadcasts.emplace_back("* poisoned *", color(0, 1, 0), target.position(), 0.5);
		});
		poison.appearance({ '-', 0xffff00 });
		poison.name("Poison");
		poison.tag("poison");
		m_library->insert(poison);

		// skills

		rl::person::action_t::range_t bite_range(0, 1);
		rl::person::action_t bite(rl::person::action_t::target_fn([&](rl::person::caster_t *user, rl::person::target_t unit)
		{
			if (user && unit)
			{
				point start = user->position();

				// status
				//unit->accept(rl::effect(m_library->prototype<rl::person::status_t>("poison")));

				// popup
				m_broadcasts.emplace_back(std::to_string(-8), color(1, 0, 0), unit->position(), 0.75);

				// visual
				m_projectiles.push_back(projectile({ '>', 0xff0000 }, {},
					[start, unit](projectile::timespan_t phase)
				{
					point fin = unit->position();
					vector pos = fin + vector((fin - start).normalized()) * -0.25;
					vector up = pos + vector(0, 0.25);
					return up.lerp(pos, (std::min)(phase, 1.0));
				}, 3.14 * -0.5, 0.25));
				m_projectiles.push_back(projectile({ '>', 0xff0000 }, {},
					[start, unit](projectile::timespan_t phase)
				{
					point fin = unit->position();
					vector pos = fin + vector((fin - start).normalized()) * -0.25 + vector(0.15, 0);
					vector up = pos + vector(0, 0.25);
					return up.lerp(pos, (std::min)(phase, 1.0));
				}, 3.14 * -0.5, 0.25));
				m_projectiles.push_back(projectile({ '>', 0xff0000 }, {},
					[start, unit](projectile::timespan_t phase)
				{
					point fin = unit->position();
					vector pos = fin + vector((fin - start).normalized()) * -0.25 - vector(0.15, 0);
					vector up = pos + vector(0, 0.25);
					return up.lerp(pos, (std::min)(phase, 1.0));
				}, 3.14 * -0.5, 0.25));
				m_projectiles.push_back(projectile({ '>', 0xff0000 }, {},
					[start, unit](projectile::timespan_t phase)
				{
					point fin = unit->position();
					vector pos = fin + vector((fin - start).normalized()) * -0.25;
					vector down = pos - vector(0, 0.25);
					return down.lerp(pos, (std::min)(phase, 1.0));
				}, 3.14 * 0.5, 0.25));
				m_projectiles.push_back(projectile({ '>', 0xff0000 }, {},
					[start, unit](projectile::timespan_t phase)
				{
					point fin = unit->position();
					vector pos = fin + vector((fin - start).normalized()) * -0.25 + vector(0.15, 0);
					vector down = pos - vector(0, 0.25);
					return down.lerp(pos, (std::min)(phase, 1.0));
				}, 3.14 * 0.5, 0.25));
				m_projectiles.push_back(projectile({ '>', 0xff0000 }, {},
					[start, unit](projectile::timespan_t phase)
				{
					point fin = unit->position();
					vector pos = fin + vector((fin - start).normalized()) * -0.25 - vector(0.15, 0);
					vector down = pos - vector(0, 0.25);
					return down.lerp(pos, (std::min)(phase, 1.0));
				}, 3.14 * 0.5, 0.25));
			}
		}), rl::person::action_t::target_check_fn([&, bite_range](rl::person::caster_t *user, rl::person::target_t unit)
		{
			return user && unit && user != unit.get() && rl::person::action_t::in_range(bite_range, distance(user->position(), unit->position()));
		}));
		bite.name("Bite");
		bite.range(bite_range);
		bite.tag("bite");
		m_library->insert(bite);

		rl::person::action_t pyroblast(rl::person::action_t::target_fn([&](rl::person::caster_t *user, rl::person::target_t unit)
		{
			if (user)
			{
				//broadcast({ "puff!", 0xffffff, user->position() });
			}
			if (user && unit)
			{
				vector start = user->position();
				vector fin = unit->position();
				//m_projectiles.push_back(projectile('*', 0xff0000, color(30, 10, 10), [=](projectile::timespan_t phase) { return start.lerp(fin, (std::min)(phase, 1.0)); }));
			}
		}), rl::person::action_t::target_check_fn([&](rl::person::caster_t *user, rl::person::target_t unit)
		{
			return true;
		}));
		pyroblast.tag("pyroblast");
		m_library->insert(pyroblast);

		// heal
		rl::person::action_t::ground_fn h([&](rl::person::caster_t *user, const point &position)
		{
			user->health() = user->health() + 1;
		});
		rl::person::action_t::ground_check_fn hc([&](rl::person::caster_t *user, const point &position)
		{
			return true;
		});
		rl::person::action_t heal(h, hc);
		heal.tag("heal");
		m_library->insert(heal);

		// teleport
		rl::person::action_t::ground_fn teleport_fn([&](rl::person::caster_t *user, const point &position)
		{
			m_scene->focus(position);
			m_scene->move(*user, position);
		});
		rl::person::action_t::ground_check_fn teleport_check_fn([&](rl::person::caster_t *user, const point &position)
		{
			return true;
		});
		rl::person::action_t teleport(teleport_fn, teleport_check_fn);
		teleport.tag("teleport");
		m_library->insert(teleport);

		// npc

		rl::npc rat;
		rat.fraction(0);
		rat.appearance({ 'r', 0xff0000, 0.62f });
		rat.health() = 100;
		rat.tag("mob_rat");
		rat.name("Rat");
		rat.add_skill(bite);
		m_library->insert(rat);

		// ore
		rl::item ore;
		ore.appearance('o');
		ore.name("copper ore");
		ore.tag("ore_copper");
		ore.stackable(true);
		m_library->insert(ore);

		// placeables
		rl::unit lantern;
		lantern.appearance({ ' ', color(1, 1, 1) });
		lantern.light({ { 3, 3, 3 }, true, true });
		lantern.tag("lantern");
		m_library->insert(lantern);

		rl::door door;
		door.appearance({ ' ', 0x333333 }, { '+', 0x333333 });
		door.tag("door");
		m_library->insert(door);

		// items
		{
			rl::item ff;
			ff.name("Firetail Mushroom");
			ff.tag("f_red");
			m_library->insert(ff);
		}
		{
			rl::item flora;
			flora.name("Glowing Moss");
			flora.tag("f_green");
			m_library->insert(flora);
		}
		{
			rl::item flora;
			flora.name("Cave Lily");
			flora.tag("f_blue");
			m_library->insert(flora);
		}

		// flora
		rl::deposit f1(m_library->make<rl::item>("f_red"));
		f1.tag("fireflower");
		f1.name("Gribus Ognelisius");
		f1.appearance({ '*', color(1, 0, 0), 0.75 });
		f1.light({ { 3, 0, 0 }, true, true });
		f1.invincible(true);
		m_library->insert(f1);

		rl::deposit f2(m_library->make<rl::item>("f_blue"));
		f2.tag("iceflower");
		f2.appearance({ '*', color(0, 0, 1), 0.75 });
		f2.light({ { 0, 0, 3 }, true, true });
		f2.invincible(true);
		m_library->insert(f2);

		rl::deposit flower(m_library->make<rl::item>("f_green"));
		flower.tag("felflower");
		flower.appearance({ '*', color(0, 1, 0), 0.75 });
		flower.light({ { 0, 3, 0 }, true, true });
		flower.invincible(true);
		m_library->insert(flower);
	}