Ejemplo n.º 1
0
bool DynamicBody::OnCollision(Object *o, Uint32 flags, double relVel)
{
    // don't bother doing collision damage from a missile that will now explode, or may have already
    // also avoids an occasional race condition where destruction event of this could be queued twice
    // returning true to ensure that the missile can react to the collision
    if (o->IsType(Object::MISSILE)) return true;

    double kineticEnergy = 0;
    if (o->IsType(Object::DYNAMICBODY)) {
        kineticEnergy = KINETIC_ENERGY_MULT * static_cast<DynamicBody*>(o)->GetMass() * relVel * relVel;
    } else {
        kineticEnergy = KINETIC_ENERGY_MULT * m_mass * relVel * relVel;
    }

    // damage (kineticEnergy is being passed as a damage value) is measured in kilograms
    // ignore damage less than a gram except for cargo, which is very fragile.
    CollisionContact dummy;
    if (this->IsType(Object::CARGOBODY)) {
        OnDamage(o, float(kineticEnergy), dummy);
    }
    else if (kineticEnergy > 1e-3) {
        OnDamage(o, float(kineticEnergy), dummy);
    }

    return true;
}
Ejemplo n.º 2
0
void Missile::ECMAttack(int power_val)
{
	if (power_val > m_power) {
		CollisionContact dummy;
		OnDamage(0, 1.0f, dummy);
	}
}
void Creature::OnCollide(App &app, Game *game, World *world, GameUtility *gameUtility, float speedX, float speedY, CollisionType collisionType)
{
    if((collisionType == CollisionType::YAxis && speedY > 3) || (collisionType == CollisionType::XYAxis && speedY > 3))
    {
#ifdef SERVER
        std::cout << "Damaged " << speedY*5 << " ! Health left: " << getHealth() << std::endl;
        OnDamage(speedY*5);
        sf::Packet packet;
        packet << (sf::Uint16)MessageType::CreatureDamage << (sf::Uint16)getId() << (float)speedY*5;
        gameUtility->SendPacket(packet);
#endif
    }
}
Ejemplo n.º 4
0
void iGameEntity::Damage(float afDamage, int alStrength)
{
	if(mfHealth > 0)
	{
		if(mType == eGameEntityType_Enemy)
		{
			//if(mpInit->mDifficulty== eGameDifficulty_Easy) afDamage *= 2.0f;
			if(mpInit->mDifficulty== eGameDifficulty_Hard) afDamage /= 2.0f;
			if(mpInit->mbHasHaptics) afDamage *= 2.0f;
		}
		
		int lDiff = mlToughness - alStrength;
        
		if(alStrength>=0)
		{
			float fDamageMul = 1 - (0.25f * (float)lDiff);
			if(fDamageMul<0) fDamageMul =0;
			
			//Could be 2 here, depends on what you wanna do. This way the damage is never increased.
			if(fDamageMul>1) fDamageMul =1;

			afDamage *= fDamageMul;
		}


		mfHealth -= std::abs(afDamage);

		if(mfHealth <=0)
		{
			OnDeath(afDamage);
		}
		else
		{
			OnDamage(afDamage);
		}
	}
}
Ejemplo n.º 5
0
void Missile::ECMAttack(int power_val)
{
	if (power_val > m_power) {
		OnDamage(0, 1.0f);
	}
}
void Creature::OnProjectileHit(App &app, GameUtility *gameUtility, Projectile *projectile, float damage)
{
    OnDamage(damage);
}