tutorial_BouncingBall/bball__versions/bball_subVersionsSprites/bball__v06/source/ball.c
//-----------------------------------------------------------------
// update ball object (call once per frame)
//-----------------------------------------------------------------
update ball object (call once per frame)
update ball object ( call once per frame )
void ballUpdate( ball* b ) 
{
 b->x += (b->xvel>>4);
 b->xvel = (b->xvel * (256-c_air_friction)) >> 8;
 b->xvel = clampint( b->xvel, -max_xvel, max_xvel );
 b->yvel += c_gravity;
 b->y += (b->yvel);
 if( b->y + c_radius >= c_platform_level )
 {
    b->xvel = (b->xvel * (256-c_ground_friction)) >> 8;
    if( b->y > c_platform_level - min_height )    {
     b->y = c_platform_level - min_height;
     b->yvel = -(b->yvel * (256-c_bounce_damper)) >> 8;
     if( b->yvel > -min_yvel ) b->yvel = -min_yvel;
    }
    b->height = (c_platform_level - b->y) * 2;
 }
 else {
    b->height = c_diam << 8;
 }
}
void ballUpdate ( ball * b ) { b -> x += ( b -> xvel >> 4 ) ; b -> xvel = ( b -> xvel * ( 256 - c_air_friction ) ) >> 8 ; b -> xvel = clampint ( b -> xvel , - max_xvel , max_xvel ) ; b -> yvel += c_gravity ; b -> y += ( b -> yvel ) ; if ( b -> y + c_radius >= c_platform_level ) { b -> xvel = ( b -> xvel * ( 256 - c_ground_friction ) ) >> 8 ; if ( b -> y > c_platform_level - min_height ) { b -> y = c_platform_level - min_height ; b -> yvel = - ( b -> yvel * ( 256 - c_bounce_damper ) ) >> 8 ; if ( b -> yvel > - min_yvel ) b -> yvel = - min_yvel ; } b -> height = ( c_platform_level - b -> y ) * 2 ; } else { b -> height = c_diam << 8 ; } }
update ball object (call once per frame)
update ball object ( call once per frame )
// Físicas // add X velocity to X position xvel is 20.12 while x is 24.8 //Gravetat:  // apply air friction to X velocity // clamp X velocity to the limits // add gravity to Y velocity // add Y velocity to Y position // Bounce on the platform // apply ground friction to X velocity // check if the ball has been squished to minimum height // mount Y on platform // negate Y velocity, also apply the bounce damper // clamp Y to mininum velocity (minimum after bouncing, so the ball does not settle) // calculate the height