PDA

View Full Version : Permanent Side Scrolling Jump



Joe123
04-24-2008, 12:39 PM
Right, so, side scrolling jump.
I know that there's a script to do this in Zodiac, but it's a bit more complicated to set up, and I was asked to write this for someone else previously.

Pretty much just stick it in as your global script, set up those 4 integers to how you want them, and you're good to go.
It's no use in top-down view though obviously.

It's set up so that 'L' is 'Jump', but if you want to replace it, just change every instance of 'InputL' to 'InputA' or 'InputB' or whatever.


//Inputs
const int jumpheight = 32; //Height, in pixels, of Link's Jump.
const int jumppeak = 8; //Time, in frames, Link will linger at the peak of his jump for.
const int jumpspeed = 2; //Speed, in pixels per frame, of Link's Jump.
const int nojumpflag = 98; //Flag that Link can't pass through

//Utility Integers
int jy;
bool jump; bool top;

global script slot2{
void run(){
int i; int jtmr; int ttmr;

if(jumpspeed != 0) int jmax = jumpheight/jumpspeed;
while(true){
if(Screen->ComboF[ComboAt(Link->X+8, Link->Y+16)] == nojumpflag || Screen->ComboI[ComboAt(Link->X+8, Link->Y+16)] == nojumpflag){
if(Link->Jump < 0) Link->Jump = 0;
if(Link->InputDown){Link->Dir = 1; Link->InputDown = false;}
}
if(Screen->ComboF[ComboAt(Link->X+16, Link->Y+8)] == nojumpflag || Screen->ComboI[ComboAt(Link->X+16, Link->Y+8)] == nojumpflag){
if(Link->InputRight){Link->Dir = 3; Link->InputRight = false;}
}
if(Screen->ComboF[ComboAt(Link->X, Link->Y+8)] == nojumpflag || Screen->ComboI[ComboAt(Link->X, Link->Y+8)] == nojumpflag){
if(Link->InputLeft){Link->Dir = 2; Link->InputLeft = false;}
}

if(Link->InputL && !jump && !top){
Link->InputL = false;
if(isSolid(Link->X+8, Link->Y+18) || Screen->ComboF[ComboAt(Link->X+8, Link->Y+18)] == nojumpflag || Screen->ComboI[ComboAt(Link->X+8, Link->Y+18)] == nojumpflag){jump = true; jy = Link->Y;}
}
if(jump){
jtmr++;
Link->Jump = jumpspeed;
Link->InputA = false; Link->InputB = false; Link->InputL = false;
if(jtmr >= jmax){
jtmr = 0;
jump = false;
top = true;
}
for(i=0; i<16; i++){
if(isSolid(Link->X+i, Link->Y-2) || Screen->ComboF[ComboAt(Link->X+i, Link->Y-2)] == nojumpflag || Screen->ComboI[ComboAt(Link->X+i, Link->Y-2)] == nojumpflag){jtmr = 0; jump = false; top = true;}
}
}
if(top){
ttmr++;
Link->InputA = false; Link->InputB = false; Link->InputL = false;
Link->Jump = 0;
if(ttmr == jumppeak){
ttmr = 0;
top = false;
}
}
Waitframe();
}
}

bool isSolid(int x, int y) {
if(x<0 || x>255 || y<0 || y>175)
return false;
int mask=1111b;
if(x%16<8)
mask&=0011b;
else
mask&=1100b;
if(y%16<8)
mask&=0101b;
else
mask&=1010b;
return (!(Screen->ComboS[ComboAt(x, y)]&mask)==0);
}
}

And this little one is for those moving blocks that you can stand on.
Stick it on an ffc, and make it move around via changers.
Link can then use it to stand on.
Bare in mind though, that if he's standing on it while it's moving, he'll have to walk along too, the block won't move him.
That is on the to-do list though.

Also, if you change it's Tile Width to '2' in the ffc's data, the script will take note of that and set itself up accordingly ;-)


ffc script solidblock{
void run(){
int dx;
int dchk; int offset;
if(this->TileWidth == 1) dchk = 12;
else if(this->TileWidth == 2){dchk = 22; offset = 8;}
else dchk = 8;
while(true){
if((Link->Y+16 == this->Y || Link->Y+17 == this->Y) && Abs(Link->X - this->X-offset) < dchk){
if(Link->InputL && !jump && !top){
Link->InputL = false;
jump = true; jy = Link->Y;
}
if(Link->Jump < 0) Link->Jump = 0;
if(Link->InputDown){Link->Dir = 1; Link->InputDown = false;}
}
Waitframe();
}
}
}


So hopefully we can see some more true side scrollers around ^_^

C-Dawg
04-24-2008, 04:17 PM
Zodiac's side scrolling jumping is MAD complicated, yea. It's sort of a hodge-podge I kept tinkering with until the jump arc finally felt "right..." but I couldn't explain exactly why it works. More art than science.

As for the moving platforms, I've done those too. But you're doing it better, I think. I might just replace my code with yours. The way my moving platforms work is that they replace the Combo underneath them with a solid combo, then remove it when they move on. Which works for walking back and forth, but is sort of clumsy on the edges. Your script looks like it just manipulates the player directly.

Shouldn't be too hard to modify it so it pulls the player along, either.

Joe123
04-24-2008, 06:13 PM
If you could make those modifications that'd be great, I had a go at it but I just got a lot of crazy movement jumping around all over the place.
I'm sure it's not too hard, just wasn't working for me at the time.

You have to be careful with the platform script though (or at least I had to); the only way I could stop Link from jumping again in mid-air was to check whether he was on a solid combo, so obviously that meant Link couldn't jump while on the platform, so I had to put a little bit of code into the platform script to initiate Link jumping whilst on the platform.

Getting the jumping arc right is horrendous, I agree =P
Mine doesn't really feel perfect, but it was a pretty simple few lines of code really, and you can edit the time he remains at the top if it's not quite how you want it.

C-Dawg
04-25-2008, 11:26 AM
The thing that finally made my jumping script feel right was taking into account how gravity works in ZC. I believe (correct me if I'm wrong, _L_) that the player's downward velocity increases to terminal velocity as long as the player is in the air and the Jump variable (z?) is zero. In my script, I don't manipulate the Jump variable, I just move the player directly. So what was happening was that the downward velocity was increasing behind the scenes while the player jumped up, then the player was slammed with terminal velocity when she fell down. I had to compensate for this by steadily increasing the upward velocity, which somehow worked out to make a more gentle rise and fall. Go figure.

Oh man, and stopping the player from bunny hopping by holding down the button was also a pain in the ass.

Joe123
04-25-2008, 12:31 PM
Yah, so there's an acceleration due to gravity, rather than an 'upwards accelartion, stop, downwards acceleration', which is what mine does.
I really can't be bothered to script downwards acceleration, it's far too much effort.
I'm not even using it myself so meh.

Howcomes you're directly moving the player though?
It's so much easier to use Link->Jump.


What I did (well, tried) orginally to stop that was to register Link->Y before he jumped, then not allow the activation code to run until after Link->Y was <= to that value.
Didn't work though for some reason, so I just gave in and used Beefster's boolean.
Works fine I think.

C-Dawg
04-28-2008, 08:41 AM
I didnt use Link->Jump because it didn't exist when I was coding the jump algorithm.

And I'm going to stick with what I did because I don't want the jumping animation.

Joe123
04-28-2008, 11:12 AM
Oh well, pretty good reason then =P

marcusarow
06-27-2011, 12:17 PM
I have 2 problems with this script:

1) It works on Non-Sideview Screens when Link is at the very bottom of the screen. He not only jumps, but will levitate off the screen if you hold the button down.

2) I can't seem to change the jumping tiles for this. It seems to make up its own when jumping instead of using the ones I set up in Quest>Graphics>Sprites>Link