We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi. I am relatively new to programming, and I thought it would be fun to make a "shooter" kind of game. I am stuck on trying to make the enemy shape die... It would be awesome if I could get the current enemy circle to disappear and have another one spawn... Here is my code!
.....
ellipse(enemyX, enemyY, 50, 50); // enemy circle
....
if(mousePressed) {
line(playerA, playerB, mouseX, mouseY); // bullet animation
if(mouseX == enemyX && mouseY == enemyY) { // checking accuracy
*unknown code*
}
}
.......
Answers
Thanks @TfGuy44, I never thought about just changing his position to make him "die" and "respawn", do you know a way where i could make it so if the player kills one enemy, two spawn instead of just the one?
This is one of my older examples - the concept is the same. In short, define your enemy object as it's own class, and have an ArrayList of them. When one gets removed from the ArrayList, two more get added.
Oh, and press mouse for RAVE PARTY MODE.
Hey cole,
Definitely check out TfGuy44's code and take a look at the Object Oriented Programming tutorial to learn about classes and objects. If you want to make a shooter-type program you'll probably want to have different enemy types, which would require classes and objects.
If you want to draw multiple enemies, the best way that I know of is to run a for loop in your draw() function. This way each of your enemy objects will be drawn every frame.
You can use a similar for loop in the draw() function to move each enemy, and you can use a for loop in the mouseClicked() function to check each enemy to see if it's been clicked. I would also suggest using some coordinates-checking system that lets you hit the enemy without clicking exactly on its origin, like something below:
Cheers!