java - 射击后如何将一颗子弹分成多颗子弹
问题描述
我是一名编程初学者,我必须做一个游戏,我们正在编写霰弹枪射击,但有一个问题,不知道该怎么做
我想在游戏中添加一颗子弹,当你射击它时,它会将自己吐出几个不同方向的小子弹,所以基本上是霰弹枪射击。
我已经有了一个具有他的位置、矢量和速度的普通子弹,你已经可以射击了。但我的问题是或者我不明白的事情是我如何在我用许多子弹射出一颗子弹后分裂它,以及它如何获得自己的位置和移动矢量
Bullet class{
Vector2 moveVector;
float speed =15;
public void setMoveVector(float x, float y) {
moveVector = new Vector2(x,y);}
// in that area here its for the bullet how it moving/acting including if the path is free or blocked by walls or something
if(map.pathFree(getX(), getY(), getX()+ moveVector.x * speed, getY() + moveVector.y * speed, this)) {
setPosition(getX() + moveVector.x * speed, getY() + moveVector.y * speed);
//somewhere here sould come the code splitting the bullet
//removing the bullet after a distance
DistanceIndex += speed;
if(DistanceIndex >= 1000) {
remove();
}
}
else
HitWall();
if(outsideMap()) this.remove();
}
....
}
Obj Class
//class/object/gamefigure using/creating the bullet
.....
public void shootingMethod(){
......
double direction_x = Math.cos(Math.toRadians(rotation));
double direction_y = Math.sin(Math.toRadians(rotation));
Bullet bullet = new Bullet();
....
bullet.setMoveVector((float)direction_x, (float)directoin_y);
}
解决方案
只需让一堆较小的子弹从同一位置开始,然后朝稍微不同的方向行进。您可以稍微旋转每个子弹的速度矢量来实现这一点。如果它们还没有,您可以使子弹传感器重叠不成问题
推荐阅读
- python - pyspark 数据框为每一行获得第二低的值
- visual-c++ - 对导入的方法强制 stdcall
- laravel - Laravel:将此服务提供者添加到 app.php 会给出“找不到类日志”
- c# - 健康文本离开对象引用未设置为每帧对象的实例
- excel - 通过变量字符串引用范围导致 1004 错误
- firebase - 我保存在 Firebase 存储中的音频文件没有声音
- javascript - 如何删除外部脚本添加的内联样式?
- python - PySpark - 删除 n-gram 中的空格
- c++ - 两个数组查找代码如何具有不同的速度
- r - 在 r 的一个季度内不购买后放置一个 0