User Tag List

Results 1 to 7 of 7

Thread: Anti Fairy

  1. #1
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.56%

    Anti Fairy



    WARNING: This script uses a script command that is not present in Build 1296! You must have a newer build than that in order to use this script!

    Code:
    ffc script AntiFairy {
        void run(int type, int dmg, int sfx) {
            int dir = 4 + Rand(4);
            int hurttimeout = 0;
            
            while(true) {
                dir = MoveBounce(this, dir);
                
                if(hurttimeout == 0) {
                    if(LinkCollision(this) && Link->Action != LA_GOTHURTLAND && Link->Action != LA_GOTHURTWATER) {
                        Link->Action = LA_GOTHURTLAND;
                        Link->HitDir = RelativeDir(this);
                        
                        if(sfx != 0) Game->PlaySound(sfx);
                        
                        if(type == 0) {
                            Link->HP -= dmg;
                        } else if(type == 1) {
                            Link->MP -= dmg;
                        }
                        
                        hurttimeout = 10;
                    }
                } else {
                    hurttimeout -= 1;
                }
                
                for(int i = 1; i <= Screen->NumLWeapons(); i++) {
                    lweapon lw = Screen->LoadLWeapon(i);
                    
                    if(lw->ID == LW_BRANG && Collision(this, lw)) {
                        //buh bye
                        lw->DeadState = WDS_BOUNCE;
                        Game->PlaySound(25);
                        item itm = Screen->CreateItem(I_FAIRY);
                        itm->X = this->X;
                        itm->Y = this->Y;
                        itm->Pickup = IP_TIMEOUT;
                        this->X = -100;
                        this->Y = -100;
                        return;
                    }
                }
                
                Waitframe();
            }
        }
        
        int FlipH(int dir) {
            if(dir == DIR_LEFTUP) {
                return DIR_RIGHTUP;
            } else if(dir == DIR_RIGHTUP) {
                return DIR_LEFTUP;
            } else if(dir == DIR_LEFTDOWN) {
                return DIR_RIGHTDOWN;
            } else if(dir == DIR_RIGHTDOWN) {
                return DIR_LEFTDOWN;
            }
        }
        
        int FlipV(int dir) {
            if(dir == DIR_LEFTUP) {
                return DIR_LEFTDOWN;
            } else if(dir == DIR_RIGHTUP) {
                return DIR_RIGHTDOWN;
            } else if(dir == DIR_LEFTDOWN) {
                return DIR_LEFTUP;
            } else if(dir == DIR_RIGHTDOWN) {
                return DIR_RIGHTUP;
            }
        }
        
        int MoveBounce(ffc this, int dir) {
            int newx = this->X;
            int newy = this->Y;
            if(dir == DIR_LEFTUP) {
                newx -= 1;
                newy -= 1;
            } else if(dir == DIR_RIGHTUP) {
                newx += 1;
                newy -= 1;
            } else if(dir == DIR_LEFTDOWN) {
                newx -= 1;
                newy += 1;
            } else if(dir == DIR_RIGHTDOWN) {
                newx += 1;
                newy += 1;
            }
            
            //this doesn't check the extreme top or bottom!
            if(newx <= 0 || newx + 15 >= 255) {
                dir = FlipH(dir);
            } else {
                for(int y = newy+2; y < newy + 14; y++) {
                    if(Screen->isSolid(newx+1, y) || Screen->isSolid(newx + 14, y)) {
                        dir = FlipH(dir);
                        break;
                    }
                }
            }
            
            //this doesn't check the extreme right or left!
            if(newy <= 0 || newy + 15 >= 175) {
                dir = FlipV(dir);
            } else {
                for(int x = newx+2; x < newx + 14; x++) {
                    if(Screen->isSolid(x, newy+1) || Screen->isSolid(x, newy + 14)) {
                        dir = FlipV(dir);
                        break;
                    }
                }
            }
            
            newx = this->X;
            newy = this->Y;
            if(dir == DIR_LEFTUP) {
                newx -= 1;
                newy -= 1;
            } else if(dir == DIR_RIGHTUP) {
                newx += 1;
                newy -= 1;
            } else if(dir == DIR_LEFTDOWN) {
                newx -= 1;
                newy += 1;
            } else if(dir == DIR_RIGHTDOWN) {
                newx += 1;
                newy += 1;
            }
            
            this->X = newx;
            this->Y = newy;
            
            return dir;
        }
    }
    This script creates one of those enemies from the Zelda 3/the gameboy zeldas that bounces diagonally around the screen. In Zelda 3, they take magic instead of health, while on the game boy, they do damage. In addition, they turn into fairies when struck with the boomerang.

    Fortunately for you, these ones do all of the above.

    Usage:
    No special set up is required. Just place the FFC and set the arguments.

    Arguments:
    D0 - The type of damage to do: 0 = HP, 1 = MP
    D1 - The amount of damage.
    D2 - The sound effect to play on contact. (0 = none)
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  2. #2
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,303
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.74%
    That's pretty cool!
    FlipV would work as dir ^= 10b and FlipH as dir ^= 1b, although it would only work for diagonals and not for the cardinal directions I think.

  3. #3
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.56%
    The first rule of Programming club: Don't optimize prematurely.
    The second rule of Programming club: Don't optimize prematurely.

    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  4. #4
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,303
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.74%
    If it's inside a function that describes what it's doing what's wrong with it?

  5. #5
    Lynel
    ZC Developer
    pkmnfrk's Avatar
    Join Date
    Jan 2004
    Location
    Toronto
    Age
    37
    Posts
    1,248
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    3,142
    Level
    18
    vBActivity - Bars
    Lv. Percent
    10.56%
    Nothing is particularly wrong with it, it just looks like noise. I prefer to write code that doesn't require comments, since those can quickly go out of date. A chained if statement is clear, some bit twiddling isn't.

    If it gets moved into std.zh (which is fine), then I understand that there are other, more pressing concerns (like, reducing compilation time and code size as much as possible).

    (on a side note, I don't suppose you're working on a switch statement, are you?)
    Tale of the Cave - a web comic - Updates Monday, Wednesday, Friday
    ZC Tutorials - Tutorials and Script Library - Updated July 30, 2008
    ZeldaGuard - Corruption in my save files? It's more likely than you think!
    I do script requests!

  6. #6
    &&
    ZC Developer
    Joe123's Avatar
    Join Date
    Sep 2006
    Age
    32
    Posts
    3,061
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    7,303
    Level
    26
    vBActivity - Bars
    Lv. Percent
    8.74%
    Eh, my thoughts are that if it's inside a function with a descriptive name it doesn't require any comments anyway.

    Well I had thought about switch statements very fleetingly, my understanding of bison isn't anyway near good enough to implement them though. After co-incedentally having looked at the relative merits of speeds for different implementations of them compared with if/else if/else and arrays of function pointers and things a few hours ago I'm definitely not working on one.

  7. #7
    Gel violetwasp's Avatar
    Join Date
    Jan 2011
    Location
    Omnipresent
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    517
    Level
    8
    vBActivity - Bars
    Lv. Percent
    16.11%

    Error compiling

    when I try to compile this script it gives me this message:
    tmp, line 13: error s10: function relativedir is undeclared.

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