herdem.c
/**
 * Sets the current sprite of actor `a` so that
 * it corresponds to its velocity (assuming there
 * are 8 different direction spirtes
 */
Sets the current sprite of actor `a` so that
it corresponds to its velocity (assuming there
are 8 different direction spirtes
Sets the current sprite of actor ` a ` so that it corresponds to its velocity ( assuming there are 8 different direction spirtes
void eight_way_direction_change(jty_actor *a)
{
    double b = 0.8535533905932737;
    double x, y;
    x = 1 / (1 + a->vy * a->vy / (a->vx * a->vx));
    if (a->vx == 0 && a->vy == 0) {
        if (a->current_sprite < 8) {
            a->current_sprite += 8;
        }
        return;
    }
    if (x > b) {
        if (a->vx > 0) {
            a->current_sprite = DIRECTION_E;
            return;
        } else {
            a->current_sprite = DIRECTION_W;
            return;
        }
    }
    y = 1 / (1 + a->vx * a->vx / (a->vy * a->vy));
    if (y > b) {
        if (a->vy < 0) {
            a->current_sprite = DIRECTION_N;
            return;
        } else {
            a->current_sprite = DIRECTION_S;
            return;
        }
    }
    if (a->vx > 0 && a->vy < 0) {
        a->current_sprite = DIRECTION_NE;
        return;
    }
    if (a->vx < 0 && a->vy < 0) {
        a->current_sprite = DIRECTION_NW;
        return;
    }
    if (a->vx < 0 && a->vy > 0) {
        a->current_sprite = DIRECTION_SW;
        return;
    }
    a->current_sprite = DIRECTION_SE;
}
void eight_way_direction_change ( jty_actor * a ) { double b = 0.8535533905932737 ; double x , y ; x = 1 / ( 1 + a -> vy * a -> vy / ( a -> vx * a -> vx ) ) ; if ( a -> vx == 0 && a -> vy == 0 ) { if ( a -> current_sprite < 8 ) { a -> current_sprite += 8 ; } return ; } if ( x > b ) { if ( a -> vx > 0 ) { a -> current_sprite = DIRECTION_E ; return ; } else { a -> current_sprite = DIRECTION_W ; return ; } } y = 1 / ( 1 + a -> vx * a -> vx / ( a -> vy * a -> vy ) ) ; if ( y > b ) { if ( a -> vy < 0 ) { a -> current_sprite = DIRECTION_N ; return ; } else { a -> current_sprite = DIRECTION_S ; return ; } } if ( a -> vx > 0 && a -> vy < 0 ) { a -> current_sprite = DIRECTION_NE ; return ; } if ( a -> vx < 0 && a -> vy < 0 ) { a -> current_sprite = DIRECTION_NW ; return ; } if ( a -> vx < 0 && a -> vy > 0 ) { a -> current_sprite = DIRECTION_SW ; return ; } a -> current_sprite = DIRECTION_SE ; }
Sets the current sprite of actor `a` so that
 it corresponds to its velocity (assuming there
 are 8 different direction spirtes
Sets the current sprite of actor ` a ` so that it corresponds to its velocity ( assuming there are 8 different direction spirtes
/* b = (cos(22.5))**2 */ /* Travelling E */ /* Travelling W */ /* Travelling N */ /* Travelling S */ /* Travelling NE */ /* Travelling NW */ /* Travelling SW */