Algorithms

<< < (4/4)

tcaudilllg:
Menu Algorithm: Manage the Dialogue Menu

Procedure:
In the actor cycle, disable player input.Set the Dialogue Cycle flag.
Code:


if (dialogueLayerIsCycling == true)
{
    fieldInputIsActive = false;
}
else
if (dialogueLayerIsCycling == false)
{
    fieldInputIsActive = true;
}

// cycle actors;

if (dialogueLayerIsCycling == true)
{
    // cycle the dialogue menu layer
}



Menu Algorithm: Cycle the Dialogue Menu Layer

Procedure:
If the menu is already open, cycle its actors.Else if the menu is not open, open it.
Code:

if (dialogueMenuIsOpen == true)
{
    // cycle actors
}
else
if (dialogueMenuIsOpen == false)
{
   // open the menu
   dialogueMenuIsOpen = true;
}


tcaudilllg:
I am adding algorithm applications to this list, because it is useful to categorize specific purposes for which an algorithm may be used.


Sprite Algorithm: Set a Cursor Over a Sprite

Procedure:
Hide the cursor.Set the coordinates of the cursor on the sprite by cloning its coordinates.Show the cursor.

Here's a tough one: gauge the movement range of a tactical actor.

It's solved by using the Bresenham line algorithm, with some minor variations. It's more difficult than it seems: sure, it's no big deal to count down steps from the origin point; but what if the actor backtracks? Uh oh....

Actor Algorithm: Move a range-limited actor.

Procedure:
Take the starting point of the actor, call it the "origin" for the line.Use Bresenham's algorithm to redraw the line between the actor and the origin once for every movement the actor makes. Commit every point on the line to an array as it is drawn.Trace the ray extending from the origin to the actor. Remember that a real diagonal line is impossible; only an approximated diagonal made up of zig-zag steps can be committed. For each diagonal point, increase the steps by two.Treat the line as a ghost -- do not permit the actor to move if the number of points in the zigzag exceeds their available steps.You can create a free-movement range by using pixels as the points instead of tiles.

Navigation

[0] Message Index

[*] Previous page