Search code examples
javamultithreadingcollision-detection

Check for intersection between many missles and enemy?


I want to create a class lets say called enemy 1, enemy 2, and enemy 3.

Enemy 1: Very easy to kill, but many. Enemy 2: Harder to kill, but less of them. Enemy 3: Boss, super hard to kill, only one.

Lets say that many is going to be 1,000. Less of them will be 100. Boss is of course one.

So it would be stupid to make 1,101 different instances for a game of just enemy. It would require to much code.

Now my fighter, which is sick, can fire a lot of missiles. Lets say 2,000 a minute for the sake of fun.

I need to check for collisions between the enemy and all the missiles. I plan only using 4 different instances. Which would be enemy1, enemy2, enemy3, and a missile.

Any ideas on how to go about this? Obviously I would need threads, but I am not sure how to check for collisions in this instance.


Solution

  • So it would be stupid to make 1,101 different instances for a game of just enemy. It would require to much code.

    Not at all. You may be confusing class with instance because you will in fact have to create 1,101 instances of these objects, but will only need code for 3 Enemy classes (or 1 class perhaps if you can make how hard it is to kill a property of the class). Likely you will have a collection, such as an ArrayList of Enemy.

    The other answer handles collisions, but likely you will do this part in your model, not in your view code.