Jump to content

Photo

Sail Boat Script


  • Please log in to reply
84 replies to this topic

#31 Zephlon

Zephlon

    Experienced Forumer

  • Members

Posted 30 January 2008 - 10:02 AM

I tried adding it, but it doesn't work.
CODE
ffc script barrel{
void run(int blank){
    ffc link2 = Screen->LoadFFC(2);
    bool go; int ran; int orig = this->Data;

    this->Data = blank;
    ran = Rand(120); //space out the barrels
    Waitframes(ran);
    this->Data = orig;
    while(true){
        ran = Rand(104) + 32; //put the barrel at a random Y coordinate
        this->Y = ran;
        this->X = 256;
            
        ran = (Rand(5)/10) + 0.25; // random speeds
        this->Vx = -ran;
        go = true;

        while(go){
            if(this->X < -16) go = false;
            if(this->X < link2->X -16 && this->Y == link2->Y) {
                go = false;
                Link->HP -= 16;
                }
            Waitframe();
            }
        Waitframes(10);
        }
    }
}


#32 Joe123

Joe123

    Retired

  • Members

Posted 30 January 2008 - 10:32 AM

CODE
ffc script barrel{
    void run(int blank){
    ffc link2 = Screen->LoadFFC(2);
    bool go; int ran; int orig = this->Data;

        this->Data = blank;
        ran = Rand(120); //space out the barrels
        Waitframes(ran);
        this->Data = orig;
        while(true){
            ran = Rand(104) + 32; //put the barrel at a random Y coordinate
            this->Y = ran;
            this->X = 256;
            
            ran = (Rand(5)/10) + 0.25; // random speeds
            this->Vx = -ran;
            go = true;

            while(go){
                if(this->X < -16) go = false;
                if(Abs(this->X - link2->X + 8) < 16 && Abs(this->Y - link2->Y + 8) < 16){
                    Link->HP -= 16;
                    Waitframes(5);
                }
            Waitframe();
            }
        Waitframes(10);
        }
    }
}


That's for a 1x1 tile FFC.
If your boat is larger, you might want to edit it, or tell me how big it is and I will.

Edited by Joe123, 30 January 2008 - 10:33 AM.


#33 Zephlon

Zephlon

    Experienced Forumer

  • Members

Posted 30 January 2008 - 03:36 PM

The boat (FFC#1) is 2x3
Link (FFC#2) is 1x1
The water/shadow (FFC#3) is 2x1
IPB Image
Normal

IPB Image
Jumping

Bugs:
The point at which the barrel hurts Link is in the back of the boat.
1 hit kills Link.

I forgot to make it compatible with jumping.
CODE
ffc script barrel{
void run(int blank, int speed){
    ffc link2 = Screen->LoadFFC(2);
    bool go; int ran; int orig = this->Data;

    this->Data = blank;
    ran = Rand(120); //space out the barrels
    Waitframes(ran);
    this->Data = orig;
    Link->HP = 64;
    while(true){
        ran = Rand(104) + 32; //put the barrel at a random Y coordinate
        this->Y = ran;
        this->X = 256;
            
        this->Vx = -speed;
        go = true;

        while(go){
            if(this->X < -16) go = false;
            if(Abs(this->X - link2->X + 8) < 16 && Abs(this->Y - link2->Y + 8) < 16 && !boatjump){
                Link->HP -= 16;
                Waitframes(5);
                }
            Waitframe();
            }
        Waitframes(10);
        }
    }
}


int boatjump is a global variable. Now it lets the user decide the speed, and it won't hurt Link if the boat is jumping.

#34 Joe123

Joe123

    Retired

  • Members

Posted 30 January 2008 - 03:42 PM

CODE
ffc script barrel{
void run(int blank, int speed){
    ffc link2 = Screen->LoadFFC(2);
    bool go; int ran; int orig = this->Data;

    this->Data = blank;
    ran = Rand(120); //space out the barrels
    Waitframes(ran);
    this->Data = orig;
    //Link->HP = 64; <- I've noted this line cause you'd be better off doing it in the boat script.

    while(true){
        ran = Rand(104) + 32; //put the barrel at a random Y coordinate
        this->Y = ran;
        this->X = 256;
            
        this->Vx = -speed;
        go = true;

        while(go){
            if(this->X < -16) go = false;
            if((this->X > 48 && this->X < 70) && Abs(this->Y - link2->Y + 8) < 16 && !boatjump){
                Link->HP -= 16;
                Waitframes(20);
                }
            Waitframe();
            }
        Waitframes(10);
        }
    }
}


How's the jumping code work?


#35 Zephlon

Zephlon

    Experienced Forumer

  • Members

Posted 30 January 2008 - 04:13 PM

I'm still planning it, but what I got so far is:

Arguments:
D0 = Boat data# while jumping
D1 = Boat shadow data#

When A is pressed, boatjump is set to true.
this->Data is set to D0.
The boat and "Link" are moved up 16 pixels.
water->Data is set to D1.
The boat's shadow is moved 24 pixels to the right.

5 sec. delay?

boatjump is set to false, and everything returns to the way it was.

How should I do a 5 sec. delay?
CODE
ffc script boat{
void run(int jumptil, int shadowtil){
    ffc link2 = Screen->LoadFFC(2);
    ffc water = Screen->LoadFFC(3);
    bool upcheck;
    Link->HP = 64;
    int normtil = this->Data
    int watertil = water->Data
    while(true){
        //Link->Action = LA_FROZEN;
        upcheck = false;

        if(Link->InputUp){
            this->Vy = -1;
            link2->Vy = -1;
            water->Vy = -1;
            upcheck = true;
        }else{
            this->Vy = 0;
            link2->Vy = 0;
            water->Vy = 0;
            }
        if(Link->InputDown){
            this->Vy = 1;
            link2->Vy = 1;
            water->Vy = 1;
        }else{
            if(!upcheck){
                this->Vy = 0;
                link2->Vy = 0;
                water->Vy = 0;
                }
            }
        if(Link->InputA){
            boatjump = true;
            this->Data = jumptil;
            this->Y -=16;
            link2->Y -=16;
            water->Data = shadowtil;
            water->X += 24;

            //Waitframes(300);

            boatjump = false;
            this->Data = normtil;
            this->Y +=16;
            link2->Y +=16;
            water->Data = watertil;
            water->X -= 24;
            }

        if(link2->Y > 136 && this->Vy > 0){this->Vy = 0; link2->Vy = 0; water->Vy = 0;}
        if(link2->Y < 32 && this->Vy < 0){this->Vy = 0; link2->Vy = 0; water->Vy = 0;}
        Waitframe();
        }
    }
}


#36 Joe123

Joe123

    Retired

  • Members

Posted 30 January 2008 - 04:24 PM

CODE
ffc script boat{
void run(int jumptil, int shadowtil){
    ffc link2 = Screen->LoadFFC(2);
    ffc water = Screen->LoadFFC(3);
    bool upcheck;
    Link->HP = 64;
    int normtil = this->Data
    int watertil = water->Data
    int jumpmax = 60*5;
    int jumptimer;
    while(true){
        //Link->Action = LA_FROZEN;
        upcheck = false;

        if(Link->InputUp){
            this->Vy = -1;
            link2->Vy = -1;
            water->Vy = -1;
            upcheck = true;
        }else{
            this->Vy = 0;
            link2->Vy = 0;
            water->Vy = 0;
            }
        if(Link->InputDown){
            this->Vy = 1;
            link2->Vy = 1;
            water->Vy = 1;
        }else{
            if(!upcheck){
                this->Vy = 0;
                link2->Vy = 0;
                water->Vy = 0;
            }
        }
        if(Link->InputA){
            boatjump = true;
            this->Data = jumptil;
            this->Y -=16;
            link2->Y -=16;
            water->Data = shadowtil;
            water->X += 24;
        }

        if(boatjump){
            if(jumptimer == jumpmax){
                boatjump = false;
                this->Data = normtil;
                this->Y +=16;
                link2->Y +=16;
                water->Data = watertil;
                water->X -= 24;
                jumptimer = 0;
            }
            jumptimer++;
        }

        if(link2->Y > 136 && this->Vy > 0){this->Vy = 0; link2->Vy = 0; water->Vy = 0;}
        if(link2->Y < 32 && this->Vy < 0){this->Vy = 0; link2->Vy = 0; water->Vy = 0;}
        Waitframe();
        }
    }
}


Certainly not with Waitframes(300); icon_wink.gif

You'd do it a bit like what I've posted there, where you up a timer, allowing the rest of the script to continue, then apply changes when it reaches 300.

#37 Zephlon

Zephlon

    Experienced Forumer

  • Members

Posted 30 January 2008 - 04:35 PM

Bugs:
The point at which the barrel hurts Link is in the back of the boat.
1 hit kills Link.
When A is pressed, the ship goes higher, higher, higher, higher, higher, higher, and higher!

#38 Joe123

Joe123

    Retired

  • Members

Posted 30 January 2008 - 04:37 PM

You'll have to look at the collision detection and work that bit out for yourself, I haven't tested it and I'm not about to right now I'm afraid.

And you wrote that jump bit, not me!

I don't know how it works, I just put in the 300 frame delay!

EDIT: I'll explain how the collision detection works if you want?
All you should have to do is change a few numbers.

Edited by Joe123, 30 January 2008 - 04:38 PM.


#39 Zephlon

Zephlon

    Experienced Forumer

  • Members

Posted 30 January 2008 - 04:51 PM

QUOTE(Joe123)
You'll have to look at the collision detection and work that bit out for yourself, I haven't tested it and I'm not about to right now I'm afraid.

But you agreed:
QUOTE(Joe123)
And if you try and do it yourself, I'll fix it when it doesn't work.


Can you tel me why it does that?

#40 Joe123

Joe123

    Retired

  • Members

Posted 30 January 2008 - 05:06 PM

Well, I have done the collision detection, and I don't really know what it doesn't work that well.

I'll explain to you what my code is doing, and why it might possibly not be working:
CODE
if((this->X > 48 && this->X < 70) && Abs(this->Y - link2->Y + 8) < 16 && !boatjump){
    Link->HP -= 16;
    Waitframes(20);
}


This function, within the loop that runs while the barrel goes across the screen, is what checks for whether it hits Link's ffc.
How it works is:
It checks whether the barrel is within the x-coordinates 48 and 70 (so this might well be the bit that's causing the problem)
CODE
(this->X > 48 && this->X < 70)

So, if this X coordinate is greater than 48, AND less than 70 (so it creates an invisible region from top to bottom of the screen between 48 and 70, and checks whether the boat is in it)

Then it checks whether the barrel is within 16 pixels of the middle of Link's ffc:
CODE
Abs(this->Y - link2->Y + 8) < 16

Abs takes a negative value and makes it positive, so what this says is:
'Subtract Link's ffc's Y coordinate from this Y coordinate (so, find the distance between the two), add 8 (which puts it in the middle of the ffc), make sure it's positive (incase Link was below the barrel), then check if that value is less than 16.
So this creates a 16 pixel field below and above Link's boat.

If the barrel is within that space, and the boat is not jumping, it then proceeds to the next two parts:
CODE
Link->HP -= 16;

That just takes 16 off Link's current HP, which is one heart's worth, and I don't see how it could go wrong really.

Then, it waits for 20 frames.
This is to make sure (well, that's what it's supposed to do) that the barrel doesn't trigger damaging Link more than once.
If that's what happening, you might want to either increase the number of frames waited, or reduce the size of the x-coordinate gap that the script checks in.
I don't know the specific conditions, so I can't really do it.

#41 Zephlon

Zephlon

    Experienced Forumer

  • Members

Posted 30 January 2008 - 05:43 PM

Here are the specific conditions:
FFC #1 (boat) (40,48)
FFC #2 (link2) (48,76)
FFC #3 (water) (16,80)

Wow. Making it jump is harder than I thought.

Here the .qst file:

IPB Image lakelon.qst (2.9 MB)

#42 Joe123

Joe123

    Retired

  • Members

Posted 31 January 2008 - 03:19 AM

Do bear in mind that I have other things to do aswell, I don't know if I have the time to check how it works in that file.

Knowing those coordinates should allow me to fix the solidity detection though, just not right now cause I'm off to school.

Edited by Joe123, 31 January 2008 - 03:19 AM.


#43 Zephlon

Zephlon

    Experienced Forumer

  • Members

Posted 01 February 2008 - 08:07 PM

I just can't get the jumping code to work right!

Here is the script:
CODE
ffc script boat{
void run(int jumptil, int shadowtil, int jumpht){
    ffc link2 = Screen->LoadFFC(2);
    ffc water = Screen->LoadFFC(3);
    bool upcheck;
    Link->HP = 64;
    int normtil = this->Data;
    int watertil = water->Data;
    int jumpmax = 60*5;
    int jumptimer;
    if (jumpht == 0) {jumpht = 16;}
    else {jumpht = jumpht*8;}

    while(true){
        //Link->Action = LA_FROZEN;
        upcheck = false;

        if(Link->InputUp){
            this->Vy = -1;
            link2->Vy = -1;
            water->Vy = -1;
            upcheck = true;
        }else{
            this->Vy = 0;
            link2->Vy = 0;
            water->Vy = 0;
            }
        if(Link->InputDown){
            this->Vy = 1;
            link2->Vy = 1;
            water->Vy = 1;
        }else{
            if(!upcheck){
                this->Vy = 0;
                link2->Vy = 0;
                water->Vy = 0;
                }
            }
        if(Link->InputA){
            boatjump = true;
            this->Data = jumptil;
            //int GetBoatY = this->Y
            //int GetLinkY = link2->Y
            this->Y = this->Y-16;
            link2->Y = link2->Y-16;
            water->Data = shadowtil;
            water->X = water->X+24;
            }

        if(boatjump){
            if(jumptimer == jumpmax){
                boatjump = false;
                this->Data = normtil;
                this->Y = this->Y+16;
                link2->Y = this->Y+16;
                water->Data = watertil;
                water->X = water->X-24;
                }
            jumptimer++;
            }

        if(link2->Y > 136 && this->Vy > 0){this->Vy = 0; link2->Vy = 0; water->Vy = 0;}
        if(link2->Y < 32 && this->Vy < 0){this->Vy = 0; link2->Vy = 0; water->Vy = 0;}
        Waitframe();
        }
    }
}


Can anyone tell me whats wrong?

Anyone at all!

#44 Joe123

Joe123

    Retired

  • Members

Posted 02 February 2008 - 06:00 PM

CODE
ffc script barrel{
void run(int blank, int speed){
    ffc link2 = Screen->LoadFFC(2);
    bool go; int ran; int orig = this->Data;

    this->Data = blank;
    ran = Rand(120); //space out the barrels
    Waitframes(ran);
    this->Data = orig;

    while(true){
        ran = Rand(104) + 32; //put the barrel at a random Y coordinate
        this->Y = ran;
        this->X = 256;
            
        this->Vx = -speed;
        go = true;

        while(go){
            if(this->X < -16) go = false;
            if((this->X > 44 && this->X < 52) && Abs(this->Y - Link->Y+8) < 16 && !boatjump){
                Link->HP -= 16;
                Waitframes(20);
                }
            Waitframe();
            }
        Waitframes(10);
        }
    }
}


Try that for your barrels.
I think the collision detection should work now.

EDIT:
Right, lesson on scope.

CODE
        }else{
            if(!upcheck){
                this->Vy = 0;
                link2->Vy = 0;
                water->Vy = 0;
                }
            }

In this code, the scope is wrong.

CODE
        }else{
            if(!upcheck){
                this->Vy = 0;
                link2->Vy = 0;
                water->Vy = 0;
            }
        }

In this code, the scope is correct.

You can see the difference, yes?

What you have is two scopes.
The first is the 'else' requirement, and the second is the 'if' requirement.

The else is declared at two indentations.
All functions within the else are then placed at three indentations, so this includes only the if.
The if is declared at three indentations, so the functions within it are placed at four indentations.
This means that the if is closed at three indentations, not four, and the else is closed at two indentations, not three.

It is essential that you get your scope correct, otherwise reading your scripts will be a nightmare.

EDIT2:
CODE

ffc script boat{
    void run(int jumptil, int shadowtil, int jumpht){
    ffc link2 = Screen->LoadFFC(2);
    ffc water = Screen->LoadFFC(3);
    bool upcheck;
    Link->HP = 64;
    int orig = this->Data;
    int worig = water->Data;
    int jumpmax = 60*5;
    int yorig;
    int jumptimer;
    if(jumpht == 0) jumpht = 16;
    else jumpht = jumpht*8;

    while(true){
        upcheck = false;

        if(Link->InputUp){
            this->Vy = -1;
            link2->Vy = -1;
            water->Vy = -1;
            upcheck = true;
        }else{
            this->Vy = 0;
            link2->Vy = 0;
            water->Vy = 0;
        }
        if(Link->InputDown){
            this->Vy = 1;
            link2->Vy = 1;
            water->Vy = 1;
        }else{
            if(!upcheck){
                this->Vy = 0;
                link2->Vy = 0;
                water->Vy = 0;
            }
        }

        if(Link->InputA){
            boatjump = true;
            this->Data = jumptil;
            water->Data = shadowtil;
            yorig = this->Y;
            this->Vy = -2;
            Waitframe();
        }

        if(boatjump){
            if(this->Y >= yorig+jumpht){
                this->Vy = 2;
            }
            if(this->Y <= yorig){
                this->Vy = 0;
                this->Data = orig;
                water->data = worig;
                boatjump = false;
            }
        }

        if(link2->Y > 136 && this->Vy > 0){this->Vy = 0; link2->Vy = 0; water->Vy = 0;}
        if(link2->Y < 32 && this->Vy < 0 && !boatjump){this->Vy = 0; link2->Vy = 0; water->Vy = 0;}
        Waitframe();
        }
    }
}


Give that a try for your jumping.

Edited by Joe123, 03 February 2008 - 05:17 AM.


#45 Zephlon

Zephlon

    Experienced Forumer

  • Members

Posted 02 February 2008 - 09:45 PM

That's weird.

When I press A... nothing happens.
The barrels don't hurt Link either.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users