繁体   English   中英

射击后如何将一颗子弹分裂成多颗子弹

[英]How to split a bullet to many bullets after shooting

我是一名编程初学者,我必须为一个游戏做一些我们正在编写霰弹枪射击但有问题并且不知道该怎么做的游戏

我想在游戏中添加一颗子弹,当你射击它时,它会朝不同的方向吐出几颗小子弹,所以基本上是霰弹枪射击。

我已经有了一个带有他的位置、向量和速度的普通子弹,你已经可以射击了。 但我的问题是或者我不明白的是我如何在我用多颗子弹射出一颗子弹后分割它,以及每颗子弹如何获得自己的位置和移动向量

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); 

}

我的问题的图片我的意思是

只需让一堆较小的子弹从相同的位置开始并以稍微不同的方向行进即可。 您可以稍微旋转每个子弹的速度矢量来实现这一点。 如果它们还没有,您可以制作子弹传感器,因此重叠不是问题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM