コード例 #1
0
ファイル: ball_entity.cpp プロジェクト: seedframework/games
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 MyController::onCollision(CollisionEvent &evt) 
{
  if (m_grasp == false){  
    typedef CollisionEvent::WithC C;  
  
    //触れたエンティティの名前を得ます  
    const std::vector<std::string> & with = evt.getWith();  
  
    // 衝突した自分のパーツを得ます  
    const std::vector<std::string> & mparts = evt.getMyParts();  
  
    // 衝突したエンティティでループします  
    for(int i = 0; i < with.size(); i++){  
  
      //右手に衝突した場合  
      if(mparts[i] == "RARM_LINK7"){  
  
				//自分を取得  
				SimObj *my = getObj(myname());  
				
				//自分の手のパーツを得ます  
				CParts * parts = my->getParts("RARM_LINK7");  
				parts->graspObj(with[i]);  
	
        m_grasp = true;  
      }  
    }  
  }  
}
コード例 #3
0
ファイル: main.cpp プロジェクト: PetriTolonen/TekoalyKurssi
	// Send, when game object receives an event.
	// Event name tells the event in question, each event type may have eventObject data associated with the event.
	//
	// Currently supported eventNames and eventObject data desctiption:
	// - Collision: 
	//		Called when game object collides to another object. 
	//		eventObject: CollisionEvent* = Information about collision.
	// - TakingDamage:
	//		Called when game object is taking damage.
	//		eventObject: yam2d::GameObject* = object which give damage to the object. Typically this is bullet, missile, mine or grenade etc.
	// - ZeroHealth: 
	//		Called when game object is going to die, because of zero health.
	//		eventObject: 0 always.
	virtual void onGameObjectEvent(GameEnvironmentInfoProvider* environmentInfo, yam2d::GameObject* gameObject, const std::string& eventName, yam2d::Object* eventObject)
	{
		if (eventName == "Collision")
		{
			CollisionEvent* collisionEvent = dynamic_cast<CollisionEvent*>(eventObject);
			assert(collisionEvent != 0);
			if (!collisionEvent->isValid()) return;
			yam2d::GameObject* otherGo = collisionEvent->getOtherGameObject();
			std::string otherType = otherGo->getType();
			yam2d::vec2 localNormal = collisionEvent->getLocalNormal();
		}
		else if (eventName == "TakingDamage")
		{
			int teamIndex = gameObject->getProperties()["teamIndex"].get<int>();

			TakingDamageEvent* damageEvent = dynamic_cast<TakingDamageEvent*>(eventObject);
			yam2d::GameObject* damageFromObject = damageEvent->getFromObject();
			float newHealth = damageEvent->getNewHealth();
			yam2d::esLogMessage("%s(team=%d) %s: fromObject=%s. New health: %3.1f", gameObject->getType().c_str(), teamIndex, eventName.c_str(), damageFromObject->getType().c_str(), newHealth);
		}
		else if (eventName == "ZeroHealth")
		{
			int teamIndex = gameObject->getProperties()["teamIndex"].get<int>();
			yam2d::esLogMessage("%s(team=%d) %s.", gameObject->getType().c_str(), teamIndex, eventName.c_str());
		}
		else
		{
			assert(0); // Should be impossible, because unknown message id.
		}
	}
コード例 #4
0
ファイル: PhysicsWorld.cpp プロジェクト: maxbilbow/RMXcodeKit
bool PhysicsWorld::checkForCollision(CollisionBody * A, CollisionBody * B) {
    if (A == B)
        return false;
    if (A->getCollisionGroup() != B->getCollisionGroup())
        if (A->getCollisionGroup() != EXCLUSIVE_COLLISION_GROUP &&
                B->getCollisionGroup() != EXCLUSIVE_COLLISION_GROUP)
            return false;

    switch (A->getCollisionGroup()) {
    case NO_COLLISIONS:
    case EXCLUSIVE_COLLISION_GROUP:
        return false;
    }


    bool isHit = A->intersects(B);
    if (isHit) {
        CollisionEvent * e = new CollisionEvent(A->getNode(),B->getNode(),secureKey);
        if (collisionDelegate != nullptr)
            collisionDelegate->handleCollision(A->getNode(), B->getNode(), e);
        e->processCollision(secureKey);
        delete e;
    }
    return isHit;

}
コード例 #5
0
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;
		
	}
}
コード例 #6
0
ファイル: playerentity.cpp プロジェクト: ggj/optimalus
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());
		}
	}
}
コード例 #7
0
ファイル: SwingState.cpp プロジェクト: kgwong/ProjectSkystone
void SwingState::handleEvent(const CollisionEvent & e)
{
	if (e.getOtherObject().getType() == GameObject::Type::ENEMY)
	{
		enemyHit_ = true;
	}
}
コード例 #8
0
		virtual void onMessage(const std::string& msgName, yam2d::Object* eventObject)
		{
			CharacterController::onMessage(msgName, eventObject);
			if (msgName == "Collision")
			{
				CollisionEvent* collisionEvent = dynamic_cast<CollisionEvent*>(eventObject);
				assert(collisionEvent != 0);
				assert(collisionEvent->getMyGameObject() == getGameObject());
				yam2d::GameObject* otherGo = collisionEvent->getOtherGameObject();
				std::string otherType = otherGo->getType();
				if (otherType == "HomeBase")
				{
					if (hasItem())
					{
						dropItem1();
					}
				}
			}
		}
コード例 #9
0
void MyController::onCollision(CollisionEvent &evt) { 

    const vector<string> & wname  = evt.getWith();       // Get a name of the other  
    const vector<string> & wparts = evt.getWithParts();  // Get a parts name of the other's collision point  
    const vector<string> & mparts = evt.getMyParts();    // Get a parts of collision point of myself  
  
    // for(int i = 0; i < wname.size(); i++)  
    //   {  
    //   // Print the name of the other  
    //   LOG_MSG(("\"%s\"", wname[i].c_str()));  
    //   LOG_MSG(("\"%s\"", wparts[i].c_str()));  
    //   LOG_MSG(("\"%s\"", mparts[i].c_str())); 

    // } 

      // LOG_MSG(("\"%s\"", myParts)); 



}
コード例 #10
0
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;
	}
}
コード例 #11
0
void DemoRobotController::onCollision(CollisionEvent &evt)
{
	if (m_grasp == false) {
		typedef CollisionEvent::WithC C;
		// Get name of entity which is touched by the robot
		const std::vector<std::string> & with = evt.getWith();
		// Get parts of the robot which is touched by the entity
		const std::vector<std::string> & mparts = evt.getMyParts();

		// loop for every collided entities
		for(int i = 0; i < with.size(); i++) {
			if(m_graspObjectName == with[i]) {
				// If the right hand touches the entity
				if(mparts[i] == "RARM_LINK7") {
					SimObj *my = getObj(myname());
					CParts * parts = my->getParts("RARM_LINK7");
					if(parts->graspObj(with[i])) m_grasp = true;
				}
			}
		}
	}
}
コード例 #12
0
ファイル: staminapotionentity.cpp プロジェクト: ggj/optimalus
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);

		}
	}
}
コード例 #13
0
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";
		}


	}
}
コード例 #14
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();
		}
	}
}
コード例 #15
0
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);
	}

}
コード例 #16
0
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;

	}
}
コード例 #17
0
void AirborneState::handleEvent(const CollisionEvent & e)
{
	if (e.getOtherObject().getType() == GameObject::Type::TILE)
	{
	}
}
コード例 #18
0
void Jumpman::onCollision(CollisionEvent event)
{
    Collider* collider = event.myCollider();

    double rollbackTime = event.getCollisionTime() * mDeltaTime;

    float bounce = 1.3f;
    float bounceMin = 0.2f;

    unsigned int reference = collider->getRefNumber();



    if(reference == mFeetNumber)
    {
        //std::cout << " FEET " << std::endl;
        mIsGrounded = true;

         std::vector<glm::vec3> contactPoints = event.getContactPoints();
         float yOverlap = contactPoints[0].y;

         float upVelocity = glm::dot(mOrientation.getUp(), mVelocity);

        if(mVelocity.y < 0)
        {
            mVelocity.y = 0;
        }

        glm::vec3 pos = mOrientation.getPos();
        if(yOverlap - pos.y < 0.3f)
        {
            pos.y = yOverlap+mFeetHeight;
        }

        mOrientation.setPos(pos);

        std::cout << yOverlap << std::endl;

        //glm::vec3 rollback = float(rollbackTime) * (-mVelocity * mOrientation.getUp());
        //mOrientation.translate(rollback.x, rollback.y, rollback.z);
    }
    else if(reference == mRayNumber)
    {
        std::vector<glm::vec3> contactPoints = event.getContactPoints();

        //Should only be one point, but just make sure.
        for(int i = 0; i < contactPoints.size(); i++)
        {
            BlockNode* blockNode = (BlockNode*) event.collidedWith()->getMaster();
            mClimable = blockNode->isClimable(contactPoints[i]);
            mClimableCoord = contactPoints[i];
            std::cout << " RAYHIT: "; if(mClimable) std::cout << "brick" << std::endl; else std::cout << "metal" << std::endl;
            std::cout << "     X: " << contactPoints[i].x << " Y: " << contactPoints[i].y <<" Z:" << contactPoints[i].z << std::endl;
        }
    }
    else
    {
        if(reference == mFrontNumber)
        {
            mCanMoveForward = false;
            glm::vec3 inverseForward = -mOrientation.getForward();
            float forwardVelocity = glm::dot(inverseForward, mVelocity);

            if(forwardVelocity > 0.0f)
            {
                //glm::vec3 rollback = float(rollbackTime) * (-mVelocity * mOrientation.getForward());
                //mOrientation.translate(rollback.x, rollback.y, rollback.z);
                mBounceVelocity -= ( ((bounce * forwardVelocity)+bounceMin) * inverseForward) ;
                std::cout << "FRONT: " << mVelocity.x << ", " << mVelocity.y << ", " << mVelocity.z << std::endl;
            }
        }
        else if(reference == mBackNumber)
        {
            mCanMoveBackward = false;
            glm::vec3 inverseForward = -mOrientation.getForward();
            float forwardVelocity = glm::dot(inverseForward, mVelocity);

            if(forwardVelocity < -0.0f)
            {
                //glm::vec3 rollback = float(rollbackTime) * (-mVelocity * mOrientation.getForward());
                //mOrientation.translate(rollback.x, rollback.y, rollback.z);
                mBounceVelocity -= (((bounce * forwardVelocity)-bounceMin) * inverseForward);
                std::cout << "BACK: " << mVelocity.x << ", " << mVelocity.y << ", " << mVelocity.z << std::endl;
            }
        }
        else if(reference == mLeftNumber)
        {
            mCanMoveLeft = false;
            float rightVelocity = glm::dot(mOrientation.getRight(), mVelocity);

            if(rightVelocity < -0.0f)
            {
                //glm::vec3 rollback = float(rollbackTime) * (-mVelocity * mOrientation.getRight());
                //mOrientation.translate(rollback.x, rollback.y, rollback.z);
                mBounceVelocity -= (((bounce * rightVelocity)-bounceMin) * mOrientation.getRight());
                std::cout << "LEFT: " << mVelocity.x << ", " << mVelocity.y << ", " << mVelocity.z << std::endl;
            }
        }
        else if(reference == mRightNumber)
        {
            mCanMoveRight = false;
            float rightVelocity = glm::dot(mOrientation.getRight(), mVelocity);

            if(rightVelocity > 0.0f)
            {
                //glm::vec3 rollback = float(rollbackTime) * (-mVelocity * mOrientation.getRight());
                //mOrientation.translate(rollback.x, rollback.y, rollback.z);
                mBounceVelocity -= (((bounce * rightVelocity)+bounceMin) * mOrientation.getRight());
                std::cout << "RIGHT: " << mVelocity.x << ", " << mVelocity.y << ", " << mVelocity.z << std::endl;
            }
        }
        else if(reference == mTopNumber)
        {
            mCanJump = false;
            float upVelocity = glm::dot(mOrientation.getUp(), mVelocity);

            if(upVelocity > 0.0f)
            {
                mBounceVelocity -= (((bounce * upVelocity)-bounceMin) * mOrientation.getUp());
            }
            //std::cout << " TOP " << std::endl;
        }
    }


}
コード例 #19
0
ファイル: enemyentity.cpp プロジェクト: ggj/optimalus
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));
		}
	}
}