Spawning Enemies

I’m trying to create a side scrolling shoot 'em up type game and I’m having trouble spawning the enemies, this is my code right now.

if (r==1 && enemy==true)

  buggieY+=5;
buggieX=750;
buggieY=300;

if (buggieY>600 || buggieY<0)
{
  buggieY*=-1;
} 
enemyY=buggieY;
enemyX-=25;
if (enemyX<0)
{
  enemyX=750;
}
if (x>725 && x<775 && y>buggieY-50 && y<buggieY+50)
{
  enemy=false;
  enemykilled+=1;
  buggieY=-100;
  buggieX=-100;
} else
{
  buggieY=-100;
  buggieX=-100;
}

I’m newer to processing so any help would be nice,
Thank you

1 Like

You need functions triggered by some event like mousePressed() and of course the special Processing void draw() function. This function will be called by an internal timer and will run at a frame rate of about 60 times per second, looping your code. Without that it will run your code just once .

1 Like

I guess you have setup and draw and you posted only the relevant part of your code.

When you want to have multiple enemies shown at the same type, make an array or arraylist of them.

When only one enemy is visible at a time, you can respawn it by placing it to the very right. I think you do this with enemyX=750; already.

You can also use a random here: enemyX=int(random(width+22, width + 130));

So don’t say enemy=false; and instead just place the enemy on the far right.

Welcome to the forum!

Chrisir

1 Like

Thanks for the help and for the welcome, hope you gave a great day!

1 Like