示例#1
0
void BallEntity::OnCollision(const CollisionEvent &event)
{
    if (event.GetType() == CollisionEventType::OnEnter)
    {
        Entity *other = event.GetOtherEntity();

        // Confirm ball position
//		pBody->SetTransform(pRSClient->sPacketData.vBall, pBody->GetAngle());

        // Normalize
        vDirection *= vDirection.Normalize();

        if(other == NULL)
        {
            // Invert diection
            vDirection.y *=-1;
        }
        if(other != NULL && other->GetName() == "PlayerRight")
        {
            // Invert diection
            vDirection.x *=-1;
        }

        if(other != NULL && other->GetName() == "PlayerLeft")
        {
            // Invert diection
            vDirection.x *=-1;
        }

        // Confirm ball position
//		pRSClient->sPacketData.vBall = pBody->GetPosition();
//		pRSClient->cSocket.Send(pRSClient->cAddress, &pRSClient->sPacketData, sizeof(pRSClient->sPacketData));
    }
}
示例#2
0
void PlayerEntity::OnCollision(const CollisionEvent &event)
{
	if (event.GetType() == CollisionEventType::OnEnter)
	{
		Entity *other = event.GetOtherEntity();
		if (other != nullptr && other->GetClassName() == "Trigger")
		{
			gGameScene->UseKey(this->GiveKey());
		}
	}
}
示例#3
0
void TriggerEntity::OnCollision(const CollisionEvent &event)
{
	Entity *other = event.GetOtherEntity();

	if(event.GetType() == CollisionEventType::OnEnter)
	{
		if(other != NULL && other->GetClassName().compare("Ball") == 0)
		{
			if(this->GetTarget() == "PlayerLeft")
				gGui->SetRightPlayerPoints(gGui->GetRightPlayerPoints() + 1);
			else
				gGui->SetLeftPlayerPoints(gGui->GetLeftPlayerPoints() + 1);
		}
	}

	if(event.GetType() == CollisionEventType::OnLeave)
	{
		if(other != NULL && other->GetClassName().compare("Ball") == 0)
		{
			BallEntity *ball = static_cast<BallEntity*>(other);
			ball->Restart();
		}
	}
}
示例#4
0
void StaminaPotionEntity::OnCollision(const CollisionEvent &event)
{
	if (event.GetType() == CollisionEventType::OnEnter)
	{
		Log("On collided with health potion");

		Entity *other = event.GetOtherEntity();
		if ((other != nullptr && other->GetClassName() == "OptimistPlayer") ||
			(other != nullptr && other->GetClassName() == "RealistPlayer") ||
			(other != nullptr && other->GetClassName() == "PessimistPlayer"))
		{
			PlayerEntity *player = static_cast<PlayerEntity *>(other);

			// Disable item
			this->pSprite->SetVisible(false);
			this->clSensor.Disable();

			//Collect Item
			player->OnCollect(ItemTypes::StaminaPotion, this->iAmount);

		}
	}
}
示例#5
0
void EnemyEntity::OnCollision(const CollisionEvent &event)
{
	if (event.GetType() == CollisionEventType::OnEnter && !bIsDead)
	{
		Log("ENEMY colidiu");

		Entity *other = event.GetOtherEntity();
		if ((other != nullptr && other->GetClassName() == "OptimistPlayer") ||
			(other != nullptr && other->GetClassName() == "RealistPlayer") ||
			(other != nullptr && other->GetClassName() == "PessimistPlayer"))
		{
			PlayerEntity *player = static_cast<PlayerEntity *>(other);

			// Stop player movement
			player->StopPlayerMovement();
			player->SetIsInputEnabled(false);

			// Define a vector to push the player
			b2Vec2 vecToPush = b2Vec2(0, 0);

			// Find where the player comes
			if (gPhysics->RayCast(pBody, b2Vec2(0, -0.32f)) ||
				gPhysics->RayCast(pBody, b2Vec2(0.16f, -0.32f)) ||
				gPhysics->RayCast(pBody, b2Vec2(-0.16f, -0.32f)))
			{
				Log("Push player up");
				vecToPush = b2Vec2(0.0f, -1.0f);
			}
			else if (gPhysics->RayCast(pBody, b2Vec2(0, 0.32f)) ||
					 gPhysics->RayCast(pBody, b2Vec2(0.16f, 0.32f)) ||
					 gPhysics->RayCast(pBody, b2Vec2(-0.16f, 0.32f)))
			{
				Log("Push player down");
				vecToPush = b2Vec2(0.0f, 1.0f);
			}
			else if (gPhysics->RayCast(pBody, b2Vec2(-0.32f, 0.0f)) ||
					 gPhysics->RayCast(pBody, b2Vec2(-0.32f, 0.16f)) ||
					 gPhysics->RayCast(pBody, b2Vec2(-0.32f, -0.16f)))
			{
				Log("Push player left");
				vecToPush = b2Vec2(-1.0f, 0.0f);
			}
			else if (gPhysics->RayCast(pBody, b2Vec2(0.32f, 0.0f)) ||
					 gPhysics->RayCast(pBody, b2Vec2(0.32f, 0.16f)) ||
					 gPhysics->RayCast(pBody, b2Vec2(0.32f, -0.16f)))
			{
				Log("Push player right");
				vecToPush = b2Vec2(1.0f, 0.0f);
			}

			s32 damageToPlayer = (player->GetDefensePower() - sEnemy.iAttackPower) + (rand() % 3 + 1);
			if (damageToPlayer < 0)
				damageToPlayer = 0;

			//Do damage to the player
			player->OnDamage(vecToPush, u32(damageToPlayer));

			s32 damageEnemyBase = player->GetAttackPower() - sEnemy.iDefensePower + (rand() % 3 + 1);
			if (damageEnemyBase < 0)
				damageEnemyBase = 0;

			//Receive damage
			this->OnDamage(u32(damageEnemyBase));
		}
	}
}