コード例 #1
0
ファイル: Entity.cpp プロジェクト: Zylann/SnowfeetEngine
//------------------------------------------------------------------------------
Entity::~Entity()
{
    if (r_parent)
        r_parent->removeChild(this);
    destroyChildren();

    removeAllTags();

	// Unregister update callback
    if (getFlag(SN_EF_UPDATABLE))
    	setUpdatable(false);
    if (getFlag(SN_EF_SYSTEM_EVENT_LISTENER))
        listenToSystemEvents(false);

    //SN_LOG("Entity " << getName() << " destroyed");
}
コード例 #2
0
void Projectile::move(int facingPosition) {
	b2Vec2 vel = myBody->GetLinearVelocity();

	float desiredVelx = 0;
	float desiredVely = 0;

	switch (facingPosition) {
	case OR_LEFT:
		desiredVelx = -STEP_LENGTH*2;
		break;	//let speed change gradually
	case OR_RIGHT:
		desiredVelx = STEP_LENGTH*2;
		break;	//let speed change gradually
	case OR_TOP:
		desiredVely = BODIES_SIZE * 8;
		break;	//let speed change gradually
	case OR_BOTTOM:
		desiredVely = -5;
		break;
	}
	float velChangex = desiredVelx - vel.x;
	float impulsex = myBody->GetMass() * velChangex;
	float velChangey = desiredVely - vel.y;
	float impulsey = myBody->GetMass() * velChangey;

	bool moving = facingPosition == OR_LEFT || facingPosition == OR_RIGHT
			|| facingPosition == OR_TOP || facingPosition == OR_BOTTOM
			|| desiredVely != 0;
	setUpdatable(moving);

	myBody->ApplyLinearImpulse(b2Vec2(impulsex, impulsey),
			myBody->GetWorldCenter(), true);

	MovementSerializer* serializer = new MovementSerializer(getId(),
			getPositionX(), getPositionY());
	Engine::getInstance().getContext()->dispatchEvent(serializer);
}