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


C++ Damage::getTotalDamage方法代码示例

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


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

示例1: hit

	void CSubStructure::hit(const b2Transform& trafo, Damage damage, vector2d position, vector2d direction)
	{
		// check that position is not inside the ship, otherwise move!


		// first, raytrace against armour to find hit segment
		b2RayCastInput rcin{position, position + direction, 1000};
		b2RayCastOutput rcout;
		ArmourSegment* armour_hit{};
		for(auto& seg : mArmour)
		{
			b2EdgeShape temp;
			temp.Set(seg.p1, seg.p2);
			if(temp.RayCast(&rcout, rcin, trafo, 0))
			{
				rcin.maxFraction = rcout.fraction;
				armour_hit = seg.armour.get();
			}
		}

		// if there was an armour segment that was hit.
		if(armour_hit)
		{
			damage = armour_hit->hit(damage);
		}

		// now, for the internal segments
		struct HitCell
		{
			float frac;
			IStructureCell* cell;
		};
		rcin.maxFraction = 10000;
		std::vector<HitCell> hit_cells;
		for(auto& cell : mCells)
		{
			if(physics::raycast(rcout, cell->shape(), rcin, trafo))
			{
				rcin.maxFraction = rcout.fraction;
				hit_cells.push_back(HitCell{rcout.fraction, cell.get()});
			}
		}

		// sort hits
		std::sort( hit_cells.begin(), hit_cells.end(), [](HitCell a, HitCell b) { return a.frac < b.frac; } );

		// now go through all cells and hit the components
		/// \todo make damage processing more interesting here!
		float internal_damage = 0.5 * damage.getTotalDamage();
		mStructurePoints -= internal_damage;
		for(auto& hc : hit_cells)
		{
			IStructureCell* cell = hc.cell;
			std::size_t comp_count = cell->component_count();
			float cmp_dmg = internal_damage / comp_count;
			for(auto& c : cell->components())
			{
				internal_damage -= c.damage(cmp_dmg);
			}
		}

		/// \todo hit event listener, including ship destruction
	}
开发者ID:ngc92,项目名称:stargame,代码行数:63,代码来源:CSubStructure.cpp


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