Question: I'm building a server-side(!) for online game and I need to check if bullet hit a target.

Client sends me position and angle of bullet fired, I know all the enemies coordinates and sizes. How can I calculate if bullet hit an enemy after a bullet fired? Enemies have different sizes, bullet is 1px size.

For example, I have player shooting angle of 45 degrees from 0, 0 coordinates, and an enemy on 200, 200 coordinates with 10 width, 15 height. How do I calculate that bullet hit the enemy?

**UPDATE:** The game is 2d dhooter from the top, like Crimsonland. Projectiles have start speed which decreases slowly.

Answer: 
When you are calling `new SteamBot();` you are creating a new instance of a `SteamBot`, it depends how you intend to use your SteamBot, do you need multiple steambots or just one ? If you only need one instance in your app,I would advise you to do something like that :

file /steambot.class.js

```
// this file contains your class
class SteamBot {

    ...
}

module.exports = SteamBot; 

```

file /steambot.js

```
const SteamBotClass = require('./steambot.class');
let SteamBot;

module.exports = function(...args) {
    SteamBot = SteamBot || new SteamBotClass(...args);
    return SteamBot;
};

```

/app.js

```
const SteamBot = require('./steambot')({
    'logOnOptions'
});

```

And if you want to use in a third file the same instance:

```
const SteamBot = require('./steambot')();

```

with this structure, in your app, you would be able to create a new class if you need it one day, with just the `.class.js` file, but if you need to keep one instance of `SteamBot` all along the app, just require `steambot.js`.

it gives you a singleton pattern based on file, a bit different from the answer from Grégory which I also like.

Hope this helps :)
What you are doing in `app.js` is instantiate a new `object` of the `class` `SteamBot`.

Then you are calling the method `getUserInventory` of that object.

---

> 
> Can you call the method of this object from another file?
> 
> 
> 

Yes if you pass to that file the object you just created. If not you gotta instantiate a new object, which can be a mistake due to the fact that i'll be totally different from the first object you did created (an other implementation of the class that's going to have it's own attributes).

---

To pass through the object instantiation you have two things you can do :

* Use static methods. A static method do not require an instantiation.

example: 

`SteamBot.getUserInventory(...)`

```
class SteamBot {

   static getUserInventory(...)  {
     ...
   }

}

```

* Use singleton pattern, that will allow the creation of only one instance of a class.

example:

```
let instance = null;

class SteamBot {

 constructor() {
   if (instance) return instance;

   instance = this;

   return instance;
 }

 static getInstance() {
   return instance || new SteamBot();
 }

}

```