## Shooting projectiles at the player from predefined angles

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

tepples
Posts: 22052
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

### Re: Shooting projectiles at the player from predefined angles

DRW wrote:
Fri Jun 26, 2020 5:40 pm
I could simply create a little C++ program in Windows that does this:

Code: Select all

``````for (int i = 1; i <= 7; i += 2)
{
cout << "#define TURN_" << i << " " << (int)(256 * tan((double)i / 64 * M_PI * 2)) << "\n";
}
``````
I wouldn't even need to write this output into a source code file. Since I only have four numbers anyway, I could just calculate them once and use them directly in my program, couldn't I?
You could do this. But then you'd have to redo it whenever you decide to change your angle resolution from 24 steps per turn to 32 or 64 or whatever. I guess it depends on how strictly you want to interpret "don't repeat yourself".

DRW
Posts: 1982
Joined: Sat Sep 07, 2013 2:59 pm

### Re: Shooting projectiles at the player from predefined angles

If I ever decide to do more angles, I need to define movement arrays for these angles anyway, and I have to do more ifs manually. So, this should be alright.

By the way, I tried it out and it works great. I'll take this method now. Thanks a lot.

Oh, by the way: Your calculation of the slope could create a division by zero if hero and weapon have the same y position.
My game "City Trouble": www.denny-r-walter.de/city.htm