void StickOnCollision::handleEvent(const CollisionEvent& e)
 {

	GameObject obj = e.getOtherObject();
	if (obj.getType() == GameObject::Type::TILE)
	{
		hookPoint = obj.getPos();
		PhysicsComponent * hookPhysics = owner_.getComponent<PhysicsComponent>();
		hookPhysics->setVelX(0);
		hookPhysics->setVelY(0);
		
		auto tileCollider = e.getOtherCollider();
		auto hookCollider = owner_.getComponent<ColliderComponent>();

		float hookBot = hookCollider->getBottom();
		float tileBot = tileCollider.getBottom();
		float tileTop = tileCollider.getTop();

		if (hookBot == tileTop)
		{
			isConnected = false;
		}
		else
		{
			isConnected = true;
		}
		//LOG("INFO") << "Hook is connected at " << hookPoint;
		
	}
}
示例#2
0
void SwingState::handleEvent(const CollisionEvent & e)
{
	if (e.getOtherObject().getType() == GameObject::Type::ENEMY)
	{
		enemyHit_ = true;
	}
}
void PlayerComponent::handleEvent(const CollisionEvent& e)
{
	DamageComponent* pDamage = e.getOtherObject().getComponent<DamageComponent>();

	switch (e.getOtherObject().getType())
	{
	case GameObject::Type::DROP:
		health_->heal(10);
		LOG("GAME") << "Picked up a thing to heal 10hp!";
		break;
	case GameObject::Type::ENEMY_PROJECTILE:
		health_->takeDamage(pDamage->getDamage());
		break;
	case GameObject::Type::ENEMY:
		DamageComponent* damage = e.getOtherObject().getComponent<DamageComponent>();
		if (health_->takeDamage(damage->getDamage()))
		{
			owner_.broadcastEvent(DamageTakenEvent(e.getScene()));
		}
		break;
	}
}
void LiftTileComponent::handleEvent(const CollisionEvent & other)
{
	tileRight_ = collider_->getRight() + 25;
	tileLeft_ = collider_->getLeft() - 25;


	if (other.getOtherObject().getType() == GameObject::Type::PLAYER && collider_->getTop() == playerCollider_->getBottom() && 
		playerCollider_->getRight() < tileRight_ && playerCollider_->getLeft() > tileLeft_)
	{
		
		playerPhysics_->enableGravity(false);
		playerPhysics_->setVelY(-DEFAULT_LIFT * 360);
	}

}
void FallingAIComponent::handleEvent(const CollisionEvent & e)
{

	if (e.getOtherObject().getType() == GameObject::Type::TILE)
	{
		//colliders
		auto blockCollider = owner_.getComponent<ColliderComponent>();
		ColliderComponent& tileCollider = e.getOtherCollider();

		if (blockCollider->getBottom() == tileCollider.getTop())
		{
			state_ = STATE::RISING;
			LOG("HARVEY") << "RISING";
		}
		else if(state_ != STATE::NEUTRAL)
		{
			state_ = STATE::DELAY;
			LOG("HARVEY") << "DELAY";
		}


	}
}
void BurnTileComponent::handleEvent(const CollisionEvent & other)
{
	if (other.getOtherObject().getType() == GameObject::Type::PLAYER)
	{
		float currentSpeed = playerPhysics_->getVelX();
		int direction = 1;
		if (playerPhysics_->isMovingRight()) //determine which direction to slow you
		{
			direction = -1;
		}
		
		//slow/push them if they're moving and aren't being slowed already
		if (playerPhysics_->getVelX() != 0 && playerPhysics_->getAccelX() == 0)
		{

			playerPhysics_->setAccelX(slow_ * direction * 3600.0f);


			time_++;
		}
		//don't push them if they're just standing on it
		else
		{
			playerPhysics_->setAccelX(0);
		}
	}
	if (time_++ > delay_)
	{
		health_->takeDamage(damage_->getDamage());
		cout << "Took " << damage_->getDamage() << " damage!" << endl;
		cout << "Current hp: " << health_->getHealth() << endl;

		time_ = 0;

	}
}
示例#7
0
void AirborneState::handleEvent(const CollisionEvent & e)
{
	if (e.getOtherObject().getType() == GameObject::Type::TILE)
	{
	}
}