# Randomizing shot

I’m trying to design an enemy that shoots multiple shots in random directions, I have an Idea of what I want to do, but I don’t know where to put it. What I want to do is make the xSpeed of the shot randomize between 0 and 12, and then take that amount and subtract it from 12 to get the ySpeed. All of the code related to it is here:

``````abstract class Projectile extends GameObject
{
Projectile(float x, float y, float w, float h, float xSpeed, float ySpeed)
{
super(x, y, w, h);
this.xSpeed = xSpeed;
this.ySpeed = ySpeed;
}
}

abstract class EnemyProjectile extends Projectile
{
EnemyProjectile(float x, float y, float w, float h, float xSpeed, float ySpeed)
{
super(x, y, w, h, xSpeed, ySpeed);
}

void reactions()
{
for (int x = 0; x < collisions.size (); x++)
{
GameObject o = collisions.get(x);
if (o instanceof Player)
{
die();
}
if (x<0 || x > width || y < 0 || y > height)
{
die();
}
}
}
void act()
{
super.act();
if (x<0 || x > width || y < 0 || y > height)
{
die();
}
}
}

class RandomShot extends EnemyProjectile
{
RandomShot(float x, float y)
{
super(x, y, redShot.width, redShot.height, 0, RED_SHOT_SPEED);
image = redShot;
damage = RED_SHOT_DAMAGE;
}
}

if (timer > EVIL_SQUARE_COOLDOWN)
{
objects.add(new RandomShot(x + (image.width/2), y + image.height));
timer = 0;
}
``````

When the shooting happens by adding x2 and y2 to the bullet position :

``````x2=random(-6,6);
y2=random(-6,6);
``````