where's the humanoid?
In order for the Robots to move or shoot, they need to know where the Humanoid is in relation to themselves. If we're only looking at 4 directions it fairly straightforward - horizontal vs vertical is determined by seeing if the difference between Robot X and Humanoid X bigger or smaller than the difference between Robot Y and Humanoid Y. Once horizontal/vertical is decided then if the difference is negative the direction is left or up, while if it's positive it's right or down.
For Frantic it's a tad more complex as we want to use 8 directions. I pulled out some graph paper and sketched this out - nowhere near as purty as Nathan would do, I'm sure
The robot is at the origin, with an onscreen location of (10,10). The letters A-L are different test positions the Humanoid could be at (their coordinates are listed down the right). The blue lines, labeled L1-L4, define the boundaries for determining which of the 8 directions the Humanoid is in. The numbers 0-7 are direction identifiers used by the program.
I then did some calculations using Open Office and came up with these formulas with these results:
L1 = (rX - hX) * 2 - (rY - hY) L2 = (rX - hX) - (rY - hY) * 2 L3 = (rX - hX) * 2 + (rY - hY) L4 = (rX - hX) + (rY - hY) * 2
In reviewing the spreadsheet results I could see that I could figure out which of the 8 directions the humanoid was located by checking the sign of L1, L4 and then either L2 or L3. See function DirectionToHumanoid() in the source file main.c if you're interested in how that works.
To test the routines I set it up so that 3 of the robots would "point" to the Humanoid using the 3 robot shots. (the robots are sprites 3, 9 and 15 - that's what the numbers on the left of the graph paper are!)
Next thing to do is revise the DirectionToHumanoid() function to also return "Target Lock" - i.e.: if the humanoid is stationary, he'd get hit if the robot fired a shot. Looking at the robots with direction indicators in the screen capture, the top one does not have target lock, the middle one does, and the bottom one may or may not as it's too close to eyeball. Once that's done I'll be able to add the routines to make the robots shoot and move!
ROM
Source
4 Comments
Recommended Comments