[A83] Re: Angles


[Prev][Next][Index][Thread]

[A83] Re: Angles




If you want to move objects in any direction, then you'll need to use 16-bit
fixed point numbers.  Here's how it works: the high byte is the actual pixel
position, and the low byte is the fractional position that you discard.  You
keep a 16-bit velocity for both the x and y axis, say vel_x and vel_y.  Say
you want to move something only along the x axis at half a pixel per frame.
You'd set vel_y to 0, and vel_x to 128.  The positions also must be 16-bit
values.  Each frame, you'd add vel_x to object_x, and vel_y to object_y.
Starting the object's coordinates at 0, what would the values look like?  0,
128, 256, 384, 512, etc.  When you actually draw it, you use the high byte.
What would they look like?  0, 0, 1, 1, 2, etc.  Make sense?  This is the
same idea behind Bresenham's line algorithm.

> How would I determine the angle needed for an enemy bullet fired from
> (enemy_x), (enemy_y) so it would hit the player (player_x), (player_y) at
a
> constant speed of 3 pixels per frame?  I saw the routine in Pheonix that
> did this but I can't understand it.  help?..






References: