User Tag List

Results 1 to 8 of 8

Thread: AngleDir8() and weapons

  1. #1
    Octorok
    Join Date
    Jan 2011
    Location
    Canada
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    815
    Level
    10
    vBActivity - Bars
    Lv. Percent
    0.51%

    AngleDir8() and weapons

    The AngleDir8() function is commonly used to set weapon->Dir, but it is inconsistent with unscripted eweapons when it comes to which directions Link can be facing in order to block them when the weapon's angle is close to a multiple of 90 degrees. A more consistent function would be something like this (-180 <= angle <= 180):
    Code:
    int AngleDir8W(float angle) {
       if(angle == 0) return DIR_RIGHT;
       else if(angle == 90) return DIR_DOWN;
       else if(angle == -90) return DIR_UP;
       else if(angle == 180 || angle == -180) return DIR_LEFT;
       else if(angle < -90) return DIR_LEFTUP;
       else if(angle < 0) return DIR_RIGHTUP;
       else if(angle < 90) return DIR_RIGHTDOWN;
       else return DIR_LEFTDOWN;
    }
    
    int RadianAngleDir8W(float angle) {
       return AngleDir8W(angle*57.2958);
    }
    I think it would make a good addition to std.zh, though other functions that use AngleDir8() with weapon->Dir would need to be updated to fix the inconsistency.

    EDIT: Maybe this could be improved. I'll do some testing with radian values.

    EDIT 2: There are going to be roundoff errors when using radians, so I think there should be some tolerance for that with the non-diagonal directions. I'm not sure how much though.
    Last edited by Colossal; 09-02-2011 at 05:38 PM.

  2. #2
    Gibdo
    Join Date
    Mar 2004
    Age
    40
    Posts
    910
    Mentioned
    3 Post(s)
    Tagged
    1 Thread(s)
    vBActivity - Stats
    Points
    3,248
    Level
    18
    vBActivity - Bars
    Lv. Percent
    36.5%
    I think this thread belongs in the scripting section.

  3. #3
    Octorok
    Join Date
    Jan 2011
    Location
    Canada
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    815
    Level
    10
    vBActivity - Bars
    Lv. Percent
    0.51%
    Yeah, I guess you're right about that. I must have been tired when I posted that here.

    Anyway, another std.zh question: what's up with SpinDir()? It doesn't do what it claims at all, or anything seemingly useful right now, for that matter.
    Code:
    //Converts directions to go round in a circle rather than U, D, L, R
    int SpinDir(int dir) {
        if(dir == DIR_DOWN || dir == DIR_RIGHT)
            return dir;
        else if(dir == DIR_LEFT)
            return DIR_UP;
        else if(dir == DIR_UP)
            return DIR_LEFT;
        return -1;
    }

  4. #4
    The Time-Loop Continues ZC Developer
    Gleeok's Avatar
    Join Date
    Apr 2007
    Posts
    4,826
    Mentioned
    259 Post(s)
    Tagged
    10 Thread(s)
    vBActivity - Stats
    Points
    12,959
    Level
    33
    vBActivity - Bars
    Lv. Percent
    26.2%
    I don't know either. Why does it start from left = 0?
    This post contains the official Gleeok seal of approval. Look for these and other posts in an area near you.

  5. #5
    Floormaster Imzogelmo's Avatar
    Join Date
    Sep 2005
    Location
    Earth, currently
    Age
    45
    Posts
    387
    Mentioned
    7 Post(s)
    Tagged
    3 Thread(s)
    vBActivity - Stats
    Points
    1,461
    Level
    12
    vBActivity - Bars
    Lv. Percent
    94.29%
    I noticed this function when I was making my Spark script. I really needed a way to easily get the next direction clockwise or counterclockwise, and the functions using it should not have to care which direction it was, so I wrote my "Turn" function for that purpose. Of course, that was all just to help me learn, so I didn't intend it to be used by anyone else, but it does seem like such a function should be possible without converting into angles.

  6. #6
    Octorok
    Join Date
    Jan 2011
    Location
    Canada
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    815
    Level
    10
    vBActivity - Bars
    Lv. Percent
    0.51%
    This is what I came up with when I tackled that issue:
    Code:
    // Constants to use as arguments for spin
    const int SPIN_CCW = 10b;
    const int SPIN_CW = 11b;
    
    int SpinDir(int dir, int spin) {
       return dir ^ spin ^ (dir >> 1);
    }
    I've been having way too much fun with bitwise operators lately.

  7. #7
    Floormaster Imzogelmo's Avatar
    Join Date
    Sep 2005
    Location
    Earth, currently
    Age
    45
    Posts
    387
    Mentioned
    7 Post(s)
    Tagged
    3 Thread(s)
    vBActivity - Stats
    Points
    1,461
    Level
    12
    vBActivity - Bars
    Lv. Percent
    94.29%
    That's much more concise and perfect for my application. Do you mind if I use it?

  8. #8
    Octorok
    Join Date
    Jan 2011
    Location
    Canada
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    815
    Level
    10
    vBActivity - Bars
    Lv. Percent
    0.51%
    Go ahead. I don't mind at all.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social