首页 > 解决方案 > 射击后如何将一颗子弹分成多颗子弹

问题描述

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

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

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

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

}

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

标签: javalibgdxgame-development

解决方案


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


推荐阅读