PDA

View Full Version : Independent and Dependent Movement



C-Dawg
01-09-2007, 01:26 PM
Here's an idea that will help people code complicated movement patterns more easily. Now that the "this_ffc->" pointer can be used to overcome problems with the "this->" pointer, we can use some ffcs independently, and some as dependent on the position of other ffcs.

For instance, I'll be coding today a simple movement script that will make an enemy "bounce" around in little arcs. This will consist of two movement FFCs.

The first FFC will be independent. It will be invisible, and move back and forth along the X coordinate. In this case, it will pursue the player, but it could move however you like.

The second FFC will be dependent on the first. It will also be invisible, and will move in an arc up and down along the Y axis. It will remain fixed to the X coordinate of the first FFC, however. The custom boss will be made up of additional FFCs linked to the second FFC.

While you could put both movement instructions in the same script, using dependent and independent scripts has the following advantages:

(1) Easier to figure out movement patterns because it gives the designer concrete objects (FFCs) to manipulate instead of storing X,Y coordinates in a variable.

(2) Portability. You can re-use your old movement scripts by making a new dependent FFC script. For instance, in the case of the hopping enemy I'm planning, I've already got a pursue_player script that I can immediately apply to the independent FFC.

(3) Creative aid. Each movement script you design can, potentially, be combined with other movement scripts you design. You can experiment by combining different movement patterns in different ways.

NOTE: Again, though, be wary about letting your FFCs wander off the screen. Make sure they don't go off by more than 32 pixels of they will be gone forever!