傍:如何桨知道球会打? [英] Pong: How does the paddle know where the ball will hit?

查看:139
本文介绍了傍:如何桨知道球会打?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

执行吃豆子和蛇,我实现下一个非常非常经典的比赛结束后:傍

After implementing Pacman and Snake I'm implementing the next very very classic game: Pong.

的实施是非常简单的,但我有一个小问题,剩下的。当桨(我不知道,如果它被称为桨)的一个由电脑控制的,我有麻烦,在正确的位置来定位它。

The implementation is really simple, but I just have one little problem remaining. When one of the paddle (I'm not sure if it is called paddle) is controlled by the computer, I have trouble to position it at the correct position.

球具有的当前位置,速度(其现在是常数)和方向角。所以,我可以计算位置在那里将击中计算机控制桨的一侧。因此Icould定位桨就在那里。但是,无论在实际游戏中,有计算机的桨将错过皮球的概率。我怎样才能实现这个概率有多大?

The ball has a current position, a speed (which for now is constant) and a direction angle. So I could calculate the position where it will hit the side of the computer controlled paddle. And so Icould position the paddle right there. But however in the real game, there is a probability that the computer's paddle will miss the ball. How can I implement this probability?

如果我只用一个概率可以说0.5计算机的桨将命中三分球,问题就解决了​​,但我认为这并不是那么简单。

If I only use a probability of lets say 0.5 that the computer's paddle will hit the ball, the problem is solved, but I think it isn't that simple.

从原始的比赛,我认为概率取决于当前桨位置和位置的球会击中边境之间的距离。

From the original game I think the probability depends on the distance between the current paddle position and the position the ball will hit the border.

没有任何人有任何提示,这是如何精确计算?

Does anybody have any hints how exactly this is calculated?

推荐答案

我们做了(伪)3D乒乓游戏,我们的高中CS类。我们所做的是,我们做电脑始终将挡板向球,但有一个最大速度 - 这样,就可能错过了球,如果太远了,但它仍然是聪明的。这是否帮助?

We made a (pseudo-)3D ping-pong game for our high school CS class. What we did was, we made the computer always move the paddle toward the ball, but with a maximum speed -- that way, it could miss the ball if it's too far, but it's still smart. Does this help?

这篇关于傍:如何桨知道球会打?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆