I have made a game named '

you can found the github repository here -

**Space Jam'**with Phaser. Play the game Here**Play**Here is some snap shot of the game,you can found the github repository here -

**https://github.com/shohan4556/Space-Jam**I have made a game named '**Space Jam' **with Phaser. Play the game Here **Play**
Here is some snap shot of the game,

you can found the github repository here -** https://github.com/shohan4556/Space-Jam**

you can found the github repository here -

Phaser game development template - boost up your dev !!

Download from gihub -- Phaser-Game-Dev-Template

Hello devs today I going to explain some very basic math for game developers. So lets get started at first we view a very basic game scenario .

So what we have we the coordinates of **e1**(x,y) and **e2**(x,y), we draw triangle with these coordinates respect to the player like this.

We have to find out the **hypotenuse **(? marked) assume that the hypotenuse for **e2 **is **H1 **and for **e2** is **H2**. Now according to the Pythagorean formula,

Lest have some simple calculation assume that x1=4, y1=5 and x2=3, y2=4.

So **H1 **= sqrt(41) = 6 (absolute value) and **H2 **= sqrt(25) = 5.

So now we know that **H2<H1** that means **e2**(enemy2) is closer to the player.

But there is a performance issue if you noticed the calculation above, we have sqrt() twice the values. The sqrt() is very expensive operation just think a game scenario we have players and enemies, they are moving and in our update() function calculating sqrt continuously and as a result our game will be slowing down.

But you can easily efficient the calculation ,

Forget about the sqrt we just do the following way,

at this moment 25<41,now we have our desired enemy and that’s it.

Thanks for reading.

Subscribe to:
Posts (Atom)