please format code with </> button * homework policy * asking questions
When I shoot the enemy doesnt die when the bullet comes in the middle, I need to shoot a bit to the right so the enemey disapears but how do i fix.
<int playerX = 300;
int playerY = 400;
int lazerX = playerX, lazerY = playerY, lazerSPD = 0;
int ball1X = 150, ball1Y = 50, ball2X = 250, ball2Y = 50, ball3X = 350, ball3Y = 50;
int ball1S = 3, ball2S = 6, ball3S = 9;
boolean ball1=true,ball2=true,ball3=true;
boolean wkey,akey,skey,dkey;
boolean space;
void setup()
{
size(500,550);
background(255);
}
void draw()
{
background(255);
fill(255,0,0);
rect(playerX,playerY,25,50);
fill(0,255,0);
rect(lazerX,lazerY,2,25);
if(ball1 == true)
{
ellipse(ball1X,ball1Y,25,25);
}
if(ball2 == true)
{
ellipse(ball2X,ball2Y,25,25);
}
if(ball3 == true)
{
ellipse(ball3X,ball3Y,25,25);
}
fill(0,0,255);
ellipse(ball1X,ball1Y,25,25);
ellipse(ball2X,ball2Y,25,25);
ellipse(ball3X,ball3Y,25,25);
/ball1X +=ball1S;
ball2X += ball2S;
ball3X += ball3S;/
lazerX = playerX;
lazerY += lazerSPD;
if(lazerY < 0)
{
lazerX = playerX;
lazerY = playerY;
lazerSPD = 0;
}
if(wkey)
{
playerY -= 10;
}
if(akey)
{
playerX -= 10;
}
if(skey)
{
playerY += 10;
}
if(dkey)
{
playerX += 10;
}
if(space)
{
lazerSPD = -30;
}
if(ball1X > 485 || ball1X < 13)
{
ball1S = -ball1S;
}
else if(ball2X > 485 || ball2X < 13)
{
ball2S = -ball2S;
}
else if(ball3X > 485 || ball3X < 13)
{
ball3S = -ball2S;
}
if(lazerX > ball1X && lazerX < ball1X+25 && lazerY < ball1Y)
{
ball1 = false;
ball1S = 0;
ball1X = 1500;
}
if(lazerX > ball2X && lazerX < ball2X+25 && lazerY < ball2Y)
{
ball2 = false;
ball2S = 0;
ball2X = 1500;
}
if(lazerX > ball3X && lazerX < ball3X+25 && lazerY < ball3Y)
{
ball3 = false;
ball3S = 0;
ball3X = 1500;
}
if(ball1 == false)
{
ball1X = 1500;
}
if(ball2 == false)
{
ball2X = 1500;
}
if(ball3 == false)
{
ball3X = 1500;
}
}
void keyPressed()
{
if(key == āwā)
{
wkey = true;
}
if(key == āaā)
{
akey = true;
}
if(key == āsā)
{
skey = true;
}
if(key == ādā)
{
dkey = true;
}
if(key == ā ')
{
space = true;
}
}
void keyReleased()
{
if(key == āwā)
{
wkey = false;
}
if(key == āaā)
{
akey = false;
}
if(key == āsā)
{
skey = false;
}
if(key == ādā)
{
dkey = false;
}
if(key == ā ')
{
space = false;
}
}