如何制作图纸以移至面板的中心?

发布于 2025-01-23 11:37:02 字数 757 浏览 0 评论 0原文

有一个食物按钮,可让您用蠕虫喂鱼和水母,然后动物游泳到面板的中心吃蠕虫。我能够做到这一点,但问题是有时(这取决于面板中图纸的特定位置)我有一个问题,即鱼或水母从一边到另一侧都被卡住直到到达中心,而不是看起来不错,问题是如何解决?

我制作了我的程序运行的视频,您可以看到上述问题。您可以在带有黄色鱼的视频的0:16上看到问题。 链接: https://vimeo.com/702495703

我附上了我的代码,使它们连接到了我的代码面板:

    public void EatTheWorm() {
        // changing the drection of the fish to the center of the panel
        if(x_front > panel.getWidth()/2)
           x_dir = -1;
        else
           x_dir=1;
        if(y_front > panel.getHeight()/2)
           y_dir = -1;
        else
           y_dir=1;
        this.x_front+=horSpeed*x_dir;
        this.y_front+=verSpeed*y_dir;
    }       

谢谢。

There is a food button that allows you to feed the fish and jellyfish with a worm and then the animals swim to the center of the panel to eat the worm. I was able to do this but the problem is that sometimes (it depends on the specific place of the drawing in the panel) I have a problem that the fish or jellyfish get stuck from side to side until they reach the center and it does not look good, the question is how can this be fixed?

I made a video of my program running where you can see the above problem.you can see the problem at the 0:16 of the video with the yellow fish.
link : https://vimeo.com/702495703

I attached my code that makes them move to the center of the panel:

    public void EatTheWorm() {
        // changing the drection of the fish to the center of the panel
        if(x_front > panel.getWidth()/2)
           x_dir = -1;
        else
           x_dir=1;
        if(y_front > panel.getHeight()/2)
           y_dir = -1;
        else
           y_dir=1;
        this.x_front+=horSpeed*x_dir;
        this.y_front+=verSpeed*y_dir;
    }       

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

謌踐踏愛綪 2025-01-30 11:37:02

您只提供很少的代码。从我的观察中,我认为这就是这种情况。

鱼运动在每个壁虱上取决于两个因素。垂直方向和水平方向。似乎鱼不能移动纯净的垂直或水平。它必须对角线移动。

考虑一种情况,当一条鱼坐在蠕虫上方的屏幕中心时。在下一个壁虱上,鱼向前和向下移动。当它向前移动时,它穿过中心,因此要转弯,因为如果它保持方向,它将远离蠕虫。在下一个刻度上,它再次转向中心。这种迭代一直持续到蠕虫被食用为止。这引起了鱼类来回弹跳的幻想。

我认为这不仅是技术挑战,而且是设计挑战。在这种情况发生时,您将如何设计鱼?也许您会允许鱼直接下降到蠕虫?但是它看起来可能不自然。或者,您会命令鱼向前游泳,然后回头跟随一条路?这取决于你。

You only give a very little of your code. From my observation, I think this is that happening.

The fish movement is determined by two factors at every tick. The vertical direction and horizontal direction. Seems the fish cannot move pure vertical or horizontal. It has to move diagonally.

Consider a situation, when a fish sits at the center of the screen above the worm. At the next tick, the fish move forward and downward. When it moves forward, it across the center so it want to turn back because if it keeps it direction, it will swim further away from the worm. At the next tick, it turns back and across the center again. This iteration continue until the worm is eaten. This casts an illusion of the fish bouncing back and forth.
enter image description here

I think this is not only a technical challenge but also a design challenge. How would you design the fish to move when this situation happens? Maybe you would allow the fish to straight descend to the worm? But it might looks unnatural. Or you would order the fish to swim forward a little bit and turn back follow a path? That is up to you.

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文