Announcement: Be excellent to each other.


Caravel Forum : DROD RPG Boards : RPG Architecture : A small orientation reference
New Topic New Poll Post Reply
Poster Message
Kwakstur
Level: Smiter
Avatar
Rank Points: 384
Registered: 05-05-2006
IP: Logged
icon A small orientation reference (+5)  
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


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


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]
12-31-2008 at 02:37 AM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
Kwakstur
Level: Smiter
Avatar
Rank Points: 384
Registered: 05-05-2006
IP: Logged
icon Re: A small orientation reference (+2)  
Oh, looking at the Architechopedia shows that Build/Wait for item Force Arrow and Tunnel don't follow this pattern. Force arrows follow the order that graphic tiles do (starting at N and going CW). Tunnels are just wierd.
 Arrows    Tunnels       _O
19 12 13      47       1  2  3
18    14   64    63    3     5
17 16 15      48       6  7  8
I can't give a simple single-line formula for either of them, but here's the shortest algorithms I can come up with, as well as some complicated 1-line iterations of them. I'll update them when I come up with better ones.

Until I come up with really good ones, you may find it easier to just simply code for each direction. But I myself prefer algorithms like this (especially the 1-line formulae) because I always think it's deceiving when I have a 32-line code block to accomplish a small task.

This code is Ctrl+B-friendly.

Convert _O to ArrowO
Click here to view the secret text


Convert _O to TunnelO:
Click here to view the secret text

Set _MyScriptF to ArrowO or TunnelO when you Build or Wait for Item.

In case anyone wants to know, DROD does follow order of operations. So some of my formulae in this and the previous post can have a few parentheses taken away, but I don't really feel like doing that now (because then I have to make a new hold to test it out to make sure I can still paste it with Ctrl+Shift+B).

____________________________
Also known as ExpHP everywhere else.

[Last edited by Kwakstur at 12-31-2008 08:52 PM]
12-31-2008 at 08:46 PM
View Profile Send Private Message to User Send Email to User Visit Homepage Show all user's posts Quote Reply
New Topic New Poll Post Reply
Caravel Forum : DROD RPG Boards : RPG Architecture : A small orientation reference
Surf To:


Forum Rules:
Can I post a new topic? No
Can I reply? No
Can I read? Yes
HTML Enabled? No
UBBC Enabled? Yes
Words Filter Enable? No

Contact Us | CaravelGames.com

Powered by: tForum tForumHacks Edition b0.98.8
Originally created by Toan Huynh (Copyright © 2000)
Enhanced by the tForumHacks team and the Caravel team.