The Problem of Movement


Remember the game Mouse Chaser from Chapter 3, "Vecor Interactivity: Mouse Chaser" ? The bat moved after the mouse pointer, but it did it by moving only horizontally, vertically, and diagonally. What if we wanted the bat to move toward the mouse directly (in a straight line)? How could we do that?

Essentially, we need to look at where we are, where we want to go, and how fast we're going. From that, we can determine how much we need to change our _x and _y properties to give us the correct step forward.

For determining those changes _x and _y , we have two choices: We can use trigonometric functions (arctangent in particular), or we can use vectors. Vectors are a way of representing lines of force. By using vector transformations, you can do some interesting things while not using computationally expensive math functions. Although vectors will end up saving us some math calls, they can be conceptually difficult to grasp. As such, we're going wait to talk about vectors specifically in Chapter 11, "Physics: Pachinko ." In this chapter, we are going to look at a purely algebraic solution. We'll be focused mainly of the trigonometric solutions to movement and rotation in this chapter.




Macromedia Flash MX 2004 Game Programming
Macromedia Flash MX 2004 Game Programming (Premier Press Game Development)
ISBN: 1592000363
EAN: 2147483647
Year: 2004
Pages: 161

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net