示例#1
0
void Utility::Kill(Entity& entity, Entity* source, meansOfDeath_t meansOfDeath) {
	HealthComponent *healthComponent = entity.Get<HealthComponent>();
	if (healthComponent) {
		entity.Damage(healthComponent->Health(), source ? source->oldEnt : nullptr, {}, {},
		              (DAMAGE_PURE | DAMAGE_NO_PROTECTION), meansOfDeath);
	}
}
示例#2
0
int G_BuildableDeconValue(gentity_t *ent)
{
	HealthComponent* healthComponent = ent->entity->Get<HealthComponent>();

	if (!healthComponent->Alive()) {
		return 0;
	}

	return (int)roundf((float)BG_Buildable(ent->s.modelindex)->buildPoints
	                   * healthComponent->HealthFraction());
}
示例#3
0
static AIValue_t percentHealth( gentity_t *self, const AIValue_t *params )
{
	AIEntity_t e = ( AIEntity_t ) AIUnBoxInt( params[ 0 ] );
	botEntityAndDistance_t et = AIEntityToGentity( self, e );
	float healthFraction;
	HealthComponent *healthComponent;

	if (et.ent && (healthComponent = et.ent->entity->Get<HealthComponent>())) {
		healthFraction = healthComponent->HealthFraction();
	} else {
		healthFraction = 0.0f;
	}

	return AIBoxFloat( healthFraction );
}
void EnemyComponent::draw(sf::RenderWindow& win)
{
	if (clock.getElapsedTime().asSeconds() - lastHit > hitFrequency)
	{
		for (b2ContactEdge* edge = getOwner()->body->GetContactList(); edge; edge = edge->next) {
			b2Body* bodya = edge->contact->GetFixtureA()->GetBody();
			b2Body* bodyb = edge->contact->GetFixtureB()->GetBody();

			GameObject* playa = getOwner()->getWorld()->getPlayer();

			if (bodyb == playa->body)
			{
				GameObject* g = (GameObject*)playa->body->GetUserData();
				HealthComponent* h = (HealthComponent*)g->getComponent<HealthComponent>();
				h->takeDamage(damage);
				soundManager::getSound().playPlayerGrunt();
				

				lastHit = clock.getElapsedTime().asSeconds();
			}
		}
	}
}
示例#5
0
void G_CheckCkitRepair( gentity_t *self )
{
	vec3_t    viewOrigin, forward, end;
	trace_t   tr;
	gentity_t *traceEnt;

	if ( self->client->ps.weaponTime > 0 ||
	     self->client->ps.stats[ STAT_MISC ] > 0 )
	{
		return;
	}

	BG_GetClientViewOrigin( &self->client->ps, viewOrigin );
	AngleVectors( self->client->ps.viewangles, forward, nullptr, nullptr );
	VectorMA( viewOrigin, 100, forward, end );

	trap_Trace( &tr, viewOrigin, nullptr, nullptr, end, self->s.number, MASK_PLAYERSOLID, 0 );
	traceEnt = &g_entities[ tr.entityNum ];

	if ( tr.fraction < 1.0f && traceEnt->spawned && traceEnt->s.eType == ET_BUILDABLE &&
	     traceEnt->buildableTeam == TEAM_HUMANS )
	{
		HealthComponent *healthComponent = traceEnt->entity->Get<HealthComponent>();

		if (healthComponent && healthComponent->Alive() && !healthComponent->FullHealth()) {
			traceEnt->entity->Heal(HBUILD_HEALRATE, nullptr);

			if (healthComponent->FullHealth()) {
				G_AddEvent(self, EV_BUILD_REPAIRED, 0);
			} else {
				G_AddEvent(self, EV_BUILD_REPAIR, 0);
			}

			self->client->ps.weaponTime += BG_Weapon( self->client->ps.weapon )->repeatRate1;
		}
	}
}
示例#6
0
void ApplyDamage( HasPhysicalContactsComponent *pHasPhysicalContacts, DamageOnContactComponent *pDamageOnContact )
{
	for (Set<EntityWPtr>::Iterator iter = pHasPhysicalContacts->m_EverTouchedThisFrame.Begin();
		iter != pHasPhysicalContacts->m_EverTouchedThisFrame.End(); ++iter)
	{
		Entity *pOtherEntity = *iter;

		if (!pOtherEntity)
		{
			continue;
		}

		HealthComponent *pOtherHealthComponent = pOtherEntity->GetComponents().GetFirst<HealthComponent>();
		if ( pOtherHealthComponent )
		{
			pOtherHealthComponent->ApplyDamage( pDamageOnContact->m_DamageAmount );
		}

		if ( pDamageOnContact->m_DestroySelfOnContact )
		{
			pDamageOnContact->GetEntity()->DeferredDestroy();
		}
	}
}
void MouseMovementComponent::update(sf::Time& tpf) {
	b2Vec2 charPosition = Convert::box2dToWorld(getOwner()->body->GetPosition());
	swordRect.setPosition(charPosition.x+20, charPosition.y+40);
	if (!sf::Mouse::isButtonPressed(sf::Mouse::Left)) return;
	sword = true;
	sf::Vector2i position = sf::Mouse::getPosition(window);
	b2Vec2 mousePosition = b2Vec2(
		camera->getPosition().x + position.x,
		camera->getPosition().y + position.y);
	
	
	b2Vec2 toTarget =   mousePosition - charPosition;
	
	if (mousePosition.x < charPosition.x)
	{
		direction = true;
	}
	else
		direction = false;

	float angle = atan2f(-toTarget.x, toTarget.y);
	//getOwner()->body->SetTransform(getOwner()->body->GetPosition(), angle);
	
	// miltä alueelta etsitään
	b2Vec2 lower = Convert::worldToBox2d(charPosition - b2Vec2(32.f, 32.f));
	b2Vec2 upper = Convert::worldToBox2d(charPosition + b2Vec2(32.f, 32.f));
	b2AABB area;
	area.lowerBound = lower;
	area.upperBound = upper;
	ClosestGameObjectsCallback query;

	world.getBoxWorld()->QueryAABB(&query, area);
	// TODO tee kolmio ja eti 
	GameObject *owner = getOwner();
	std::for_each(query.bodies.begin(), query.bodies.end(), [owner,angle](b2Body* body) {
		if (body != owner->body && body->GetUserData() != NULL) {
			GameObject* other = (GameObject*)body->GetUserData();
			HealthComponent* component = (HealthComponent*)other->getComponent<HealthComponent>();
			if (component != NULL) {
				component->takeDamage(20);

				/*
				b2PolygonShape triangle;
				float f = 8.f;
				b2Vec2 verts[3] = {
				Convert::worldToBox2d(0, -f),
				Convert::worldToBox2d(f, f),
				Convert::worldToBox2d(-f, f)
				};
				b2Rot rotation;
				rotation.Set(angle);
				for (int i = 0; i < 3; i++) {
				verts[i] = b2Mul(rotation, verts[i]);
				}
				triangle.Set(verts, 3);

				if (b2TestOverlap(&triangle, 0, other->body->GetFixtureList()->GetShape(), 0, body->GetTransform(), other->body->GetTransform())) {
				component->takeDamage(2);
				}*/
			}
		}
	});
	
	

}
示例#8
0
void EnemyComponent::Update() {
	if (playerId.id == 0xFFFFFFFF) {
		playerId = GlobalScene->gameplay.players.vals[0].entity;
	}

	if (!hasCalculatedPatrolPoints) {
		patrolPoints.EnsureCapacity(GlobalScene->gameplay.patrolPoints.currentCount);
		for (int i = 0; i < GlobalScene->gameplay.patrolPoints.currentCount; i++) {
			patrolPoints.PushBack(GlobalScene->gameplay.patrolPoints.vals[i].entity);
		}

		ASSERT_MSG(patrolPoints.count > 0, "Must have patrol points if have an enemy in scene %d", GlobalScene->currentLevel)

		hasCalculatedPatrolPoints = true;
	}

	Transform* trans = GlobalScene->transforms.GetById(GlobalScene->entities.GetById(entity)->transform);

	HealthComponent* health = FIND_COMPONENT_BY_ENTITY(HealthComponent, entity);
	if (health->IsDead()) {
		GlobalScene->DestroyEntity(entity);
	}

	const float enemyHeight = 1.5f;

	float floorHeight = -10.0f;

	// TODO: Copied from player code, pull out to common function?
	if (enemydoDownCast) {
		RaycastHit downCast = GlobalScene->phys.Raycast(trans->GetGlobalPosition() + Vector3(0, 0.5f, 0), Y_AXIS * -1);

		if (downCast.wasHit) {
			floorHeight = downCast.globalPos.y;
		}
	}

	switch (currentState) {
		case ES_Patrol: {
			Entity* goalEnt = GlobalScene->entities.GetById(patrolPoints.data[patrolIndex]);
			Vector3 goal = GlobalScene->transforms.GetById(goalEnt->transform)->GetGlobalPosition();
			Vector3 toGoal = goal - trans->GetGlobalPosition();
			if (Vector2(toGoal.x, toGoal.z).Magnitude() < 0.2f){
				patrolIndex = (patrolIndex + 1) % patrolPoints.count;
				currentState = ES_Paused;
				timer = 0;
			}
			else {
				Vector3 moveVec = toGoal.Normalized() * GlobalScene->GetDeltaTime() * speed;
				trans->position = trans->position + moveVec;
				if (enemydoDownCast) {
					trans->position.y = floorHeight;
				}
			}
		} break;

		case ES_Paused: {
			timer += GlobalScene->GetDeltaTime();

			if (timer > pauseTime) {
				currentState = ES_Patrol;
				timer = 0;
			}
		} break;

		case ES_Chase: {

		} break;

		case ES_AttackWait: {

		} break;

		case ES_Attack: {

		} break;
	}
}
示例#9
0
bool Utility::Dead(Entity &entity) {
	HealthComponent* healthComponent = entity.Get<HealthComponent>();
	return (healthComponent && !healthComponent->Alive());
}