Shooting projectiles at the player from predefined angles

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

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

Re: Shooting projectiles at the player from predefined angles

Post by tepples »

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".
User avatar
DRW
Posts: 2225
Joined: Sat Sep 07, 2013 2:59 pm

Re: Shooting projectiles at the player from predefined angles

Post by DRW »

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":
Gameplay video: https://youtu.be/Eee0yurkIW4
Download (ROM, manual, artworks): http://www.denny-r-walter.de/city.html
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: Shooting projectiles at the player from predefined angles

Post by tepples »

DRW wrote: Fri Jun 26, 2020 8:14 pmOh, by the way: Your calculation of the slope could create a division by zero if hero and weapon have the same y position.
My NES-side angle calculation routine reflects the (X, Y) coordinates into the first octant before calculating the angle. That way, the slope is always in the [0 ... 1] interval.
Post Reply