示例#1
0
static void
playerUpdateVelocity(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt)
{
	int jumpState = (ChipmunkDemoKeyboard.y > 0.0f);
	
	// Grab the grounding normal from last frame
	cpVect groundNormal = cpvzero;
	cpBodyEachArbiter(playerBody, (cpBodyArbiterIteratorFunc)SelectPlayerGroundNormal, &groundNormal);
	
	grounded = (groundNormal.y > 0.0);
	if(groundNormal.y < 0.0f) remainingBoost = 0.0f;
	
	// Do a normal-ish update
	cpBool boost = (jumpState && remainingBoost > 0.0f);
	cpVect g = (boost ? cpvzero : gravity);
	cpBodyUpdateVelocity(body, g, damping, dt);
	
	// Target horizontal speed for air/ground control
	cpFloat target_vx = PLAYER_VELOCITY*ChipmunkDemoKeyboard.x;
	
	// Update the surface velocity and friction
	// Note that the "feet" move in the opposite direction of the player.
	cpVect surface_v = cpv(-target_vx, 0.0);
	playerShape->surfaceV = surface_v;
	playerShape->u = (grounded ? PLAYER_GROUND_ACCEL/GRAVITY : 0.0);
	
	// Apply air control if not grounded
	if(!grounded){
		// Smoothly accelerate the velocity
		playerBody->v.x = cpflerpconst(playerBody->v.x, target_vx, PLAYER_AIR_ACCEL*dt);
	}
	
	body->v.y = cpfclamp(body->v.y, -FALL_VELOCITY, INFINITY);
}
示例#2
0
文件: physics.c 项目: andi2/cgame
static void _update_collisions(PhysicsInfo *info)
{
    if (info->collisions)
        return;

    /* gather collisions */
    info->collisions = array_new(Collision);
    cpBodyEachArbiter(info->body, _add_collision, info->collisions);
}
示例#3
0
文件: cbody.cpp 项目: dogtwelve/eepp
void cBody::EachArbiter( ArbiterIteratorFunc Func, void * data ) {
	cArbiterIterator it( this, data, Func );
	cpBodyEachArbiter( mBody, &BodyArbiterIteratorFunc, (void*)&it );
}
示例#4
0
bool DynamicObject::isGrounded()
{
	m_grounded = false;
	cpBodyEachArbiter(m_pBody, (cpBodyArbiterIteratorFunc)updateGrounded, &m_grounded);
	return m_grounded;
}
示例#5
0
void Body::eachArbiter(BodyArbiterIteratorFunc func)
{
		cpBodyEachArbiter(body,*BodyEachArbiter,&func);
}
示例#6
0
void Body::eachArbiter(cpBodyArbiterIteratorFunc func,void *data)
{
		cpBodyEachArbiter(body,func,data);
}