射击后如何将子弹分成许多子弹

时间:2019-07-03 11:53:23

标签: java libgdx game-development

我是一名编程初学者,我在做一场游戏时就这样做了,我们正在编写a弹枪射击,但是有问题,不知道该怎么做

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

我已经有了他的位置,向量和速度的普通子弹,您已经可以射击了。但是我的问题是或者我不明白的是,我将一颗子弹射击成许多子弹后如何将其拆分,以及每个子弹如何获得自己的位置和移动矢量

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

}

Picture of my problem i mean

1 个答案:

答案 0 :(得分:1)

只要使一堆较小的子弹从相同的位置开始并沿略有不同的方向行进即可。您可以稍微旋转每个子弹的速度矢量以实现此目的。如果还没有的话,您可以制造子弹传感器,这样重叠就不会成为问题

相关问题