gpt4 book ai didi

c++ - 基于一个点的角度射击子弹

转载 作者:行者123 更新时间:2023-11-30 04:16:31 25 4
gpt4 key购买 nike

我正在做的是用我来回旋转 20 度的直线 Sprite 扫描一个区域

当我点击我的 Action 按钮时,我想朝 Sprite 的旋转方向发射一颗子弹

我通过做一个得到角度

sprite->getRotation();

我有可用的单位点,假设它是 (0,0)

我猜我需要在线上找到一个点,但我不知道它背后的数学原理。

这有可能吗?

最佳答案

鉴于您知道子弹的速度(像素/秒),我假设您将其称为 v。横穿屏幕需要 s 秒。 x 表示子弹在 x 轴上的位置(与 y 变量相同),您可以使用这个简单的三角函数实现这两个变量:

x = 0; // initial position. You say that it start at (0,0)
y = 0;

for (int i = 0; i < s; i++) {
sleep(1); // look in unistd.h
x += v*cos(angle); // include math.h
y += v*sin(angle); // angle in radian, of course
// draw your sprite here, at (x, y)
}

关于c++ - 基于一个点的角度射击子弹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17710692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com