当前位置: 首页>>代码示例>>C++>>正文


C++ Food::getPosition方法代码示例

本文整理汇总了C++中Food::getPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ Food::getPosition方法的具体用法?C++ Food::getPosition怎么用?C++ Food::getPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Food的用法示例。


在下文中一共展示了Food::getPosition方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: update

		void update(void){
			f.update();
			razer_convert_keycode_to_pos(keys_history[0],&pos);
			if (last_pos.x!=pos.x || last_pos.y!=pos.y){
				last_pos.x=pos.x; last_pos.y=pos.y;
				//cout <<"key pos = "<<(pos).x<<","<<(pos).y<<endl;
			}
			direction_t d=LEFT;
			if(pos.x == 16 && pos.y == 4)
				d=UP;
			else if(pos.x == 16 && pos.y == 5)
				d=DOWN;
			else if(pos.x == 15 && pos.y == 5)
				d=LEFT;
			else if(pos.x == 17 && pos.y == 5)
				d=RIGHT;
			s.move(d);
			g.update();
			s.update();
			razer_update_keys(chroma,chroma->keys);
			usleep(400000);
			Cord sc = s.getFront();
			Cord fc = g.getPosition();
			if(sc.x==fc.x && sc.y==fc.y){
				Food tmp = Food();
				s.grow();
				s.grow();
				g = tmp;
			}
			razer_update(chroma);
			razer_frame_limiter(chroma,13);
		}
开发者ID:jamesshawver1,项目名称:razer_blackwidow_chroma_driver,代码行数:32,代码来源:snake.cpp

示例2: hitFoodTest

void InGameLayer::hitFoodTest()
{
	Food* getFood = nullptr;
	Point foodWorldPoint(0,0);
	float dist = 0;
	float dx = 0;
	float dy = 0;
	for (int i = foodList.size() - 1; i >= 0 ; i--)
	{
		getFood = foodList.at(i);
		foodWorldPoint = getFood->getParent()->convertToWorldSpace(getFood->getPosition());
		dx = mPanda->getPositionX() - foodWorldPoint.x;
		dy = mPanda->getPositionY() - foodWorldPoint.y;
		dist = sqrt(dx * dx + dy * dy );
		if (dist <= 50 + 30)
		{
			if (getFood->getType() == FOOD_TYPE_JIU)
			{
				jiuPower += 150;
				score	+= 50;
				mPanda->playEffect(PANDA_EFFECT::PANDA_EFFECT_SPEED);
			}else if (getFood->getType()	== FOOD_TYPE_FOOD)
			{
				zhu++;
				score	+= 20;
				updateTextFiled(zhu,txtBambooCount);
			}else if (getFood->getType()	== FOOD_TYPE_ZHONG)
			{
				zhong++;
				score	+= 10;
				updateTextFiled(zhong,txtZhongCount);
			}else if (getFood->getType()	== FOOD_TYPE_BAO)
			{
				score	+= 60;
			}
			mFoodPool.takeIn(getFood);
			elementLayer->removeChild(getFood);
			foodList.eraseObject(getFood);
		}
	}
}
开发者ID:picassoporker,项目名称:runnning-panda,代码行数:41,代码来源:InGameLayer.cpp

示例3: update

/// ------------------------------------------------------------------------------------------------
void World::update()
{
	if (tick_cnt++ <= Param::n_ticks)
	{
		Food* pfood;
		for (auto fi : fishes_)
		{
			fi->update(foods_);

			pfood = foods_.at(fi->getClosestFood());

			if (Vec2DLength(fi->getPosition() - pfood->getPosition())
					< (pfood->getRadius() + fi->getRadius()))
			{
				fi->incrementFood(Param::n_food - foods_.size());

				foods_.erase(foods_.begin() + fi->getClosestFood());
//				foods_.push_back(new Food());

				if (foods_.empty())
				{
					cerr << "No more foods" << endl;
					foods_.push_back(new Food());
				}
			}

		}

		/// Highlight best fish
		RGBA rgba =
		{ 0, 0, 0, 255 };

		fish_best_->setRGBA(rgba);

		for (uint16_t i = 0; i < fishes_.size(); i++)
		{
			if (fishes_.at(i)->getFitness() > fish_best_->getFitness())
			{
				fish_best_ = fishes_.at(i);
			}
		}

		rgba =
		{	255,0,0,255};
		fish_best_->setRGBA(rgba);
	}
	else
	{
		/// Resupply food
		for (uint16_t i = foods_.size(); i < Param::n_food; i++)
		{
			foods_.push_back(new Food());
		}

		cout << "Next Generation: " << gen_algo_->getGenerationCount() << endl;

		tick_cnt = 0;

		/// Update chromosomes fitness
		vector<Chromosome> pop = gen_algo_->getPopulation();
		for (uint16_t i = 0; i < fishes_.size(); i++)
		{
			pop[i].setFitness(fishes_.at(i)->getFitness());
		}

		/// Run Genetic Algorithm
		pop = gen_algo_->NextGeneration(pop);

		/// Update Fishes' brain with new values
		for (uint16_t i = 0; i < fishes_.size(); i++)
		{
			fishes_[i]->putWeights(pop[i].getGenes());

			fishes_[i]->reset();
		}

		cout << "Average Fitness: " << gen_algo_->getAverageFitness() << endl;
		cout << "Best Fitness:    " << gen_algo_->getBestFitness() << endl << endl;

	}
}
开发者ID:boutboutnico,项目名称:ai_fish,代码行数:82,代码来源:world.cpp


注:本文中的Food::getPosition方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。