herdem_dog.c
/**
 * Calculates the acceleration of the dog, based on keys have
 * been pressed
 */
Calculates the acceleration of the dog, based on keys have
been pressed
Calculates the acceleration of the dog based on keys have been pressed
void herdem_dog_calculate_acceleration(herdem_dog *dog)
{
    double s2r = 0.7071067811865475;
    dog->parent.ax = 0;
    dog->parent.ay = 0;
    if (dog->player_actions & HERDEM_MOVE_N) {
        if (dog->player_actions & HERDEM_MOVE_S) {
            dog->parent.ay = 0;
        }
        dog->parent.ay = -dog->acceleration;
    } else if (dog->player_actions & HERDEM_MOVE_S) {
        dog->parent.ay = dog->acceleration;
    }
    if (dog->player_actions & HERDEM_MOVE_E) {
        if (dog->player_actions & HERDEM_MOVE_W) {
            dog->parent.ax = 0;
        }
        if (dog->parent.ay != 0) {
            dog->parent.ax = s2r * dog->acceleration;
            dog->parent.ay *= s2r;
        } else {
            dog->parent.ax = dog->acceleration;
        }
    } else if (dog->player_actions & HERDEM_MOVE_W) {
        if (dog->parent.ay != 0) {
            dog->parent.ax = -s2r * dog->acceleration;
            dog->parent.ay *= s2r;
        } else {
            dog->parent.ax = -dog->acceleration;
        }
    }
    jty_vector v = {.x = dog->parent.vx, .y = dog->parent.vy};
    double dog_speed = sqrt(jty_vector_mag_sq(v));
    if (dog_speed < 0.1 && dog->parent.ax == 0 && dog->parent.ay == 0) {
        dog->parent.vx = 0;
        dog->parent.vy = 0;
        eight_way_direction_change((jty_actor *)dog);
        return;
    }
    dog->parent.ax += -1 * dog->drag * v.x;
    dog->parent.ay += -1 * dog->drag * v.y;
    eight_way_direction_change((jty_actor *)dog);
}
void herdem_dog_calculate_acceleration ( herdem_dog * dog ) { double s2r = 0.7071067811865475 ; dog -> parent . ax = 0 ; dog -> parent . ay = 0 ; if ( dog -> player_actions & HERDEM_MOVE_N ) { if ( dog -> player_actions & HERDEM_MOVE_S ) { dog -> parent . ay = 0 ; } dog -> parent . ay = - dog -> acceleration ; } else if ( dog -> player_actions & HERDEM_MOVE_S ) { dog -> parent . ay = dog -> acceleration ; } if ( dog -> player_actions & HERDEM_MOVE_E ) { if ( dog -> player_actions & HERDEM_MOVE_W ) { dog -> parent . ax = 0 ; } if ( dog -> parent . ay != 0 ) { dog -> parent . ax = s2r * dog -> acceleration ; dog -> parent . ay *= s2r ; } else { dog -> parent . ax = dog -> acceleration ; } } else if ( dog -> player_actions & HERDEM_MOVE_W ) { if ( dog -> parent . ay != 0 ) { dog -> parent . ax = - s2r * dog -> acceleration ; dog -> parent . ay *= s2r ; } else { dog -> parent . ax = - dog -> acceleration ; } } jty_vector v = { . x = dog -> parent . vx , . y = dog -> parent . vy } ; double dog_speed = sqrt ( jty_vector_mag_sq ( v ) ) ; if ( dog_speed < 0.1 && dog -> parent . ax == 0 && dog -> parent . ay == 0 ) { dog -> parent . vx = 0 ; dog -> parent . vy = 0 ; eight_way_direction_change ( ( jty_actor * ) dog ) ; return ; } dog -> parent . ax += -1 * dog -> drag * v . x ; dog -> parent . ay += -1 * dog -> drag * v . y ; eight_way_direction_change ( ( jty_actor * ) dog ) ; }
Calculates the acceleration of the dog, based on keys have
 been pressed
Calculates the acceleration of the dog based on keys have been pressed
/* 1/sqrt(2) */