c中的线轨迹

时间:2019-07-02 10:34:52

标签: c

我正在创建引擎。 几乎一切正常。 我什至可以玩游戏。

我正在做一个rpg游戏,决定让 互相射击的点。 我已经具有移动圆点的功能。 但是这个函数不是线性的。

所以,那是我不能继续的地方。 我需要更改该功能以使 那些悲剧是线性的。所以我可以开枪 点上的子弹或箭头,这将 直接去找他们。

这是我现在拥有的功能:

PLACE_CALL STATUS PLACE_TYPE place_user_route(CHAINED * user, BP32 x, BP32 y) {
    if (user && USER_C(user->it)->object && bit_is_on(USER_C(user->it)->object->status, OBJECT_VISIBLE)) {
        OBJECT_SET * U = USER_C(user->it)->object;
        if (U->x_route == x && U->y_route == y) {
            obj_where_stop_all(U);
            return (On);
        }
        //printf("xs %f ys %f\n",object->x_speed,object->y_speed);
        if (U->x_route == x) {
            if (U->y_route > y) {
                U->y_route += -U->y_speed;
                U->where_stop_but(U, NORTH);
                if (U->y_route < y) {
                    U->y_route = y;
                    U->where_stop(U);
                    return (On);
                }
            }
            if (U->y_route < y) {
                U->y_route += U->y_speed;
                U->where_stop_but(U, SOUTH);
                if (U->y_route > y) {
                    U->where_stop(U);
                    U->y_route = y;
                    return (On);
                }
            }
            return (Off);
        }
        if (U->y_route == y) {
            if (U->x_route > x) {
                U->x_route += -U->x_speed;
                U->where_stop_but(U, WEST);
                if (U->x_route < x) {
                    U->where_stop(U);
                    U->x_route = x;
                    return (On);
                }
            }
            if (U->x_route < x) {
                U->x_route += U->x_speed;
                U->where_stop_but(U, EAST);
                if (U->x_route > x) {
                    U->where_stop(U);
                    U->x_route = x;
                    return (On);
                }
            }

            return (Off);
        }
        if (U->x_route > x) {
            U->x_route += -U->x_speed;
            if (U->x_route < x)U->x_route = x;
            if (U->y_route > y) {
                U->y_route += -U->y_speed;
                U->where_stop_but_and(U, NORTH, WEST);
                if (U->y_route < y)U->y_route = y;
            }
            if (U->y_route < y) {
                U->where_stop_but_and(U, SOUTH, WEST);
                U->y_route += U->y_speed;
            }
        }
        if (U->x_route < x) {
            U->x_route += U->x_speed;
            if (U->x_route > x)U->x_route = x;
            if (U->y_route < y) {
                U->y_route += U->y_speed;
                U->where_stop_but_and(U, SOUTH, EAST);
                if (U->y_route > y)U->y_route = y;
            }
            if (U->y_route > y) {
                U->y_route += -U->y_speed;
                U->where_stop_but_and(U, NORTH, EAST);
                if (U->y_route < y)U->y_route = y;
            }
        }
    }
    return (Off);
}

对于该代码,我可以做些什么改变呢?

这是游戏工作的一部分:

https://www.youtube.com/watch?v=nuLi_lB6c4Y&feature=youtu.be

这是我做的一个函数,但并不完全直接;

PLACE_CALL void straight_line(CHAINED * user, BP32 x, BP32 y) {
    if (user) {
        OBJECT_SET * U = USER_C(user->it)->object;
        BP32 x_distancy = (x > U->x_route) ? round(x - U->x_route) : round(U->x_route - x);
        BP32 y_distancy = (y > U->y_route) ? round(y - U->y_route) : round(U->y_route - y);
        if (x_distancy && y_distancy) {
            if (x_distancy != y_distancy) {
                //if (U->x_speed_old != U->x_speed)U->x_speed_old = U->x_speed;
                //if (U->y_speed_old != U->y_speed)U->y_speed_old = U->y_speed;
                U->x_speed = (x_distancy / y_distancy) * U->resistance;
                U->y_speed = (y_distancy / x_distancy) * U->resistance;
            } else {
                if (U->x_speed != U->y_speed) {
                    //if (U->x_speed_old != U->x_speed)U->x_speed_old = U->x_speed;
                    //if (U->y_speed_old != U->y_speed)U->y_speed_old = U->y_speed;
                    U->x_speed = (U->x_speed > U->y_speed) ? U->x_speed : U->y_speed;
                    U->y_speed = (U->y_speed > U->x_speed) ? U->y_speed : U->x_speed;
                }
            }
        } else {
            if (!x_distancy && !y_distancy) {
                //U->x_speed = U->x_speed_old;
                //U->y_speed = U->y_speed_old;
                U->x_route = x;
                U->y_route = y;
            }
            if (x_distancy && !y_distancy) {
                U->x_speed = (x_distancy / (x_distancy * U->resistance));
                //U->y_speed = U->y_speed_old;
                U->y_route = y;
            }
            if (y_distancy && !x_distancy) {
                U->y_speed = (y_distancy / (y_distancy * U->resistance));
                //U->x_speed = U->x_speed_old;
                U->x_route = x;
            }
            if (U->x_speed < 1 && U->y_speed < 1) {
                //U->x_speed = U->x_speed_old;
                //U->y_speed = U->y_speed_old;
                U->x_route = x;
                U->y_route = y;
            }
        }
    }
}

0 个答案:

没有答案