Level Y limit

betterbold

Active member
Hello, everyone. ;D

I use "keyfly" script and fly up in the level.
I try it and find limit "Y 380".
If I want to make it "Y 200", what I should edit ?
 
You should include the function you are using in your post

I can only assume you're using this keyfly :
Code:
void keyfly(float V)
{// Move hero if direction button is pressed
      void self = getlocalvar("self");
      int iPIndex = getentityproperty(self,"playerindex"); //Get player index
      int a = getentityproperty(self,"a"); //Get player's altitude
	float xdir = 0;
	float ydir = 0;

      if (playerkeys(iPIndex, 0, "moveleft")){// Left is pressed?
	  xdir = -V;
	} else if(playerkeys(iPIndex, 0, "moveright")){// Right is pressed?
	  xdir = V;
      }

	if(playerkeys(iPIndex, 0, "moveup") && (a <= 360)){// Up is pressed?
	  ydir = V;
	} else if(playerkeys(iPIndex, 0, "movedown") && (a >= 0)){// Down is pressed?
	  ydir = -V;
      }

	changeentityproperty(self, "velocity", xdir, 0, ydir);
}

You can find a <= 360 in script above and that line defines top limit. You can modify the value to lower the y limit


That's old way BTW, I am using other method to limit y so I can have different levels with their own y limit
 
Thank you , Bloodbane !! Yes, that's exactly it. :D
I need the method to limit y in different levels with their own y limit.

If it’s not too much trouble, could you tell it for me?
 
Alright, first of all I'm using this onmoveascript :
jedot.c
Code:
void main()
{ // Limits y movement to certain y coords
    void self = getlocalvar("self");
    int y = getentityproperty(self,"y");
    int Limit = getglobalvar("Atap");

    if(Limit == NULL()){
      Limit = openborvariant("levelheight") - 50;
    }

    if(y >= Limit){ // Reached y limit
      changeentityproperty(self, "position", NULL(), NULL(), Limit);

      changeentityproperty(self, "velocity", NULL(), NULL(), -0.1);
    }
}

This script limits y movement to certain value defined by global variable called "Atap". If that variable isn't defined, it will limit to level height - 50.
I use this to limit jumping but it can also be used to limit flying

To declare this script, add this line in character's header:
Code:
onmoveascript	 data/scripts/jedot.c

About setting "Atap", you can declare it in level text with this script:
Code:
spawn	Empty
@script
void main()
{
    setglobalvar("Atap", 380);
}
@end_script
coords	320 460
at	0

The script is independent to empty entity IOW it can be declared on any entity spawn

To reset "Atap" value, you need endlevel.c containing at least this line:
Code:
    setglobalvar("Atap", NULL());

If you need example, you can play Robo Magi, a metroidvania I've made for game jam sometime ago. That game has multiple rooms which are comprised of big rooms and tunnels. Tunnels have short "Atap" setting while big rooms have big setting

HTH
 
Back
Top Bottom