# When I shoot the enemy doesnt die when the bullet comes in the middle

**URL:** <https://discourse.processing.org/t/when-i-shoot-the-enemy-doesnt-die-when-the-bullet-comes-in-the-middle/38935>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [September 22, 2022, 4:45pm UTC](https://discourse.processing.org/t/when-i-shoot-the-enemy-doesnt-die-when-the-bullet-comes-in-the-middle/38935 "2022-09-22T16:45:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![EKEN](https://avatars.discourse-cdn.com/v4/letter/e/8dc957/32.png) [@EKEN](https://discourse.processing.org/u/EKEN)\
**Post date:** [September 22, 2022, 4:45pm UTC](https://discourse.processing.org/t/when-i-shoot-the-enemy-doesnt-die-when-the-bullet-comes-in-the-middle/38935/1 "2022-09-22T16:45:09Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

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

>

---

<div class="post-metadata">

**Author:** ![NumericPrime](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/numericprime/32/16318_2.png) [@NumericPrime](https://discourse.processing.org/u/NumericPrime)\
**Post date:** [September 22, 2022, 5:11pm UTC](https://discourse.processing.org/t/when-i-shoot-the-enemy-doesnt-die-when-the-bullet-comes-in-the-middle/38935/2 "2022-09-22T17:11:47Z")

</div>

The point given by eclipse is the middle point of the ellipse/circle.  
When you check if there is a hit it checks in the area  
ballX to ballX+25  
However the ball also goes 25 to the left so you need to check  
ballX-25 to ballX+25.

---

<div class="post-metadata">

**Author:** ![EKEN](https://avatars.discourse-cdn.com/v4/letter/e/8dc957/32.png) [@EKEN](https://discourse.processing.org/u/EKEN)\
**Post date:** [September 22, 2022, 8:09pm UTC](https://discourse.processing.org/t/when-i-shoot-the-enemy-doesnt-die-when-the-bullet-comes-in-the-middle/38935/3 "2022-09-22T20:09:37Z")

</div>

Thank you so much! Thats really heplful
