Jump to content

Photo

Slope climber--Help!


  • Please log in to reply
6 replies to this topic

#1 Beefster

Beefster

    Human Being

  • Members
  • Real Name:Justin
  • Location:Colorado

Posted 19 November 2007 - 10:34 AM

This was taken right from my AGN topic:

I managed to make Link climb half a combo, but then he stops. I have a few questions regarding this:

Is there anything wrong with my isSolid Function?
How might I optimize my isSolid Function?
Is there anything wrong with my logic?

CODE
import "std.zh"

bool isSolid(int x, int y) {

    int mask = Screen->ComboS[ComboAt(x,y)];
    int xc; int yc;

    xc = x % 16;
    yc = y % 16;

    if((xc >= 0) && (xc < 8)) {

        if((yc >= 0) && (yc < 8)) {

            return mask & 0001b;

        } else {

            return mask & 0010b;

        }

    } else {

        if((yc >= 0) && (yc < 8)) {

            return mask & 0100b;

        } else {

            return mask & 1000b;

        }

    }

}

global script InherentControls {

    void run() {

        while(true) {

            //Inherent Jumping
            if((Link->InputUp || Link->InputL) && (isSolid(Link->X,Link->Y+16) || isSolid(Link->X+8,Link->Y+16))) {

                Link->Jump = 40;
                Game->PlaySound(45);

            }

            //"Slope" Control
            if(Link->InputRight && !isSolid(Link->X+16, Link->Y) && isSolid(Link->X+16, Link->Y+15)) {

                Link->X ++;
                Link->Y --;

            }

            if(Link->InputLeft && !isSolid(Link->X-1, Link->Y) && isSolid(Link->X-1, Link->Y+15)) {

                Link->X --;
                Link->Y --;

            }

            Link->InputUp = false;
            Link->InputL = false;
            Link->InputDown = false;

            Waitframe();

        }
    }
}


EDIT: NOTE: I bolded the areas of concern in the code Crud! You can't bold code here. icon_frown.gif

EDIT 2: I noticed that (I think) it only doesn't work on tiles with a single unwalkable fourth in a bottom corner of the combo's mask which for some reason, Link is not allowed to jump on. It has to do with my collision detector, doesn't it?

#2 Beefster

Beefster

    Human Being

  • Members
  • Real Name:Justin
  • Location:Colorado

Posted 26 November 2007 - 12:03 AM

It has been a week. I better bump this and ask what everyone doesn't like about this?

This is for use with sideview gravity so slopes can be faked since there are no diagonal combo solidities.

#3 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

  • Members
  • Real Name:Pillsbury
  • Location:Magical Land of Dough

Posted 27 November 2007 - 04:35 AM

Hmm, I really don't know enough about masking functions to be of much help. I use the tried and true is_walkable: by saffith I think, and C-'s canMove works pretty good too. Have you tried those?

CODE

    bool canMove(int x, int y){

        // x=23, y=130
        // Obviously in range...
        if(x<0 || x>255 || y<0 || y>175)
            return false;
        int mask=1111b;
        
        // x % 16 = 7, so
        // mask = 1111 & 0011 = 0011
        if(x%16<8)
            mask&=0011b;
        else
            mask&=1100b;
        
        // y % 16 = 2, so
        // mask = 0011 & 0101 = 0001
        if(y%16<8)
            mask&=0101b;
        else
            mask&=1010b;
    
        // All but the top-right quarter of the combo is solid, so ComboS = 1011
        // mask & ComboS = 0001 & 1011 = 0001
        // The result wasn't 0, so return false
        return ((Screen->ComboS[ComboAt(x, y)]&mask)==0);
     }// end of canMove

    bool canMove(int x, int y)
    {
        if(x<0 || x>240 || y<0 || y>160)
            return false;
        
        return Screen->ComboS[y+(x>>4)]==0;
    }
}


    bool is_walkable(int x, int y)
    {
        return Screen->ComboS[x+y*16]==0;
    }


Oh wait, the is_walkable is by DD, and canMove2 is saffith...i think.

#4 Beefster

Beefster

    Human Being

  • Members
  • Real Name:Justin
  • Location:Colorado

Posted 27 November 2007 - 10:19 PM

Even after redoing the isSolid function in the image of canMove, it still works in the exact same way as the old function. Okay. This is what's going on:

IPB Image
The pink stuff is solid quarters. The green line is the path I want Link to walk on. The red square is where Link won't walk through. The black grid lines show quarter combos and the white grid lines show whole tiles.

I probably should have specified all of this in the first place. icon_heh.gif

BTW: Like my custom Link sprite and the surrounding tiles?

#5 C-Dawg

C-Dawg

    Magus

  • Members

Posted 27 November 2007 - 11:03 PM

FYI, I believe Saffith originally created the canMove function I use, too. I renamed it for my own convenience, but he's the author.

#6 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

  • Members
  • Real Name:Pillsbury
  • Location:Magical Land of Dough

Posted 28 November 2007 - 01:21 AM

Oh, I see now. I think what you may want is two seperate functions. Something like isSolid, plus canSlope, or whatever you call it. You'd return the canSlope 4, ...oops, and also 3. I think thats the same as 0001 and 0010. You could then check for one || the other. Havn't tried any of this, but it seems feasible.

And while your here, how do you get an ffc at say 2Vx, to move in a circle along it's set trajectory? You said you had a script for this at agn.

..and yeah, Saffith's the man.

#7 Beefster

Beefster

    Human Being

  • Members
  • Real Name:Justin
  • Location:Colorado

Posted 20 February 2008 - 10:38 PM

I have a reason for digging this up.

I Finally figured out how I should have done this:

When right/left is pressed into a "slope" Link is ONLY pushed into the solidity. At any time when Link is overlapped on a solid combo in at least 2 pixels or so, he is pushed up. This should get rid of the spasms and climb halts.


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users