I've been doing a lot of messing around with orientation and have found some nice tricks you may find useful, so here's a few things you can do to _O and _MyO.
Here's the values of _O based on facing.
_O
0 1 2
3 4 5
6 7 8
Facing
This also matches the values for script commands that can use _MyScript vars to change orientation, so you can use _O as a parameter. The central number, 4, is Central facing, and will be omitted from all future matrices because these functions are meant for things that have a direction.
N or S, E or W?
Let's split the orientation "
vector"
into its X and Y components.
Dividing your oriention by 3 gives a number according to vertical facing.
Modulating your orientation by 3 gives a number according to horizontal facing.
Subtracting 1 from these yields more useful values(-1,0,1 instead of 0,1,2).
(_O%3) - 1 (_O/3) - 1
-1 0 1 -1 -1 -1
-1 1 0 0
-1 0 1 1 1 1
X-Component Y-Component
You can use these to find the tile in front of you (your sword's location), for instance.
Click here to view the secret text
×
WeaponX = _X + (_O % 3) - 1
WeaponY = _Y + (_O / 3) - 1
The other way
Here's something simple to give the opposite direction (NW to SE): Subtract it from 8. Useful for if you're scripting a Slayer, or if you want a Game Effect to spew backwards.
8 - _O
8 7 6
5 3
2 1 0
Reverse
There are also ways just to mirror your facing vertically or horizontally; make NE become NW, for instance. Here's how: E and W values differ by 2. N and S values differ by 6. We can tell the game to add or subtract these numbers to find the related directions.
To tell the game whether to add, subtract, or ignore the 2 or 6, we multiply it by the X or Y component.
_O-(2*((_O%3)-1)) _O-(6*((_O/3)-1))
2 1 0 6 7 8
5 3 3 5
8 7 6 0 1 2
Flip X Flip Y
Such a function may see some use in a project similar to Sideo RPG:
Click here to view the secret text
×Let's say you script a platformer-shooter. The player is a custom player role that has a gun, but is technically unarmed (moving makes you face the direction you move).
In most real platformer-shooters, you can move while aiming at an angle. You can also turn around while aiming at an angle to aim at the same angle in the other way (that is, in shooters where diagonal aiming doesn't automatically turn on backstrafing).
Creating an NPC with the following Ctrl+B-friendly script will ensure that, for example, if you're facing NE, then moving E will continue to let you face NE, and moving W will make you face NW. Try it! You can give yourself a sword to make its effects more apparent.
Click here to view the secret text
×Label Loop
Set var "OldO" = _O
Set var "OldOX" = (_O % 3) - 1
Wait 0
If ...
Wait until var "OldOX" = 1
If ...
Wait for player to move East
Go to Maintain Facing
If End
If ...
Wait for player to move West
Go to Change Facing
If End
If End
If ...
Wait until var "OldOX" = -1
If ...
Wait for player to move West
Go to Maintain Facing
If End
If ...
Wait for player to move East
Go to Change Facing
If End
If End
If ...
Wait until var "OldOX" = 0
If ...
Wait for player to move West
Go to Change Facing
If End
If ...
Wait for player to move East
Go to Change Facing
If End
If End
Go to Loop
Label Maintain Facing
Set var "_O" = OldO
Go to Loop
Label Change Facing
Set var "_O" = OldO - (2 * OldOX)
Go to Loop
The formula this demonstrates is under "
Label Change Facing"
.
Two things to note: One, I shortened "
((OldO % 3) - 1)"
to "
OldOX"
.
And two, this code doesn't account for diagonal movement (jumping).
Diagonal or Orthogonal?
Here's something else you might find useful.
_O % 2
0 1 0
1 1
0 1 0
Orthogonal
That's all I have. I'm currently trying to see if I can find an algorithm for directions to the side (examples: N would have W and E, SW would have NW and SE, etc.). My current one has separate formulae for orthogonal and diagonal, and I want just one formula.
If I get any luck, I'll share it.
____________________________
Also known as ExpHP everywhere else.
[Last edited by Kwakstur at 12-31-2008 03:24 AM]