Enabling gravity on characters (SOLVED)

Started by Creator, Thu 20/08/2009 18:55:55

Previous topic - Next topic

Creator

I've made a function which enables gravity depending on a boolean (which is a global variable). This is the code:

Code: ags

//Boolean is called gravOn

function Gravity(int ground, int pixelFall) //ground is where the floor meets the wall. pixelFall is how many pixels the character will drop
{  
  if (gravOn == true) {
    if (player.y < ground) {
      player.y += pixelFall;
    }
  }
}


What I want to know is how to set it for just the one character and setting which character in the function parameters.

EG.
Code: ags

Gravity(player, 313, 3);


How would I set it up so I can choose a character based on their script-o name?

Matti

Code: ags

function Gravity(int ground, int pixelFall, Character*char)
{  
  if (gravOn == true) {
    if (char.y < ground) {
      char.y += pixelFall;
    }
  }
}

Mazoliin

Or use extender functions.
Code: ags

function Gravity(this Character*, int ground, int pixelFall)
{  
  if (gravOn == true) {
    if (this.y < ground) {
      this.y += pixelFall;
    }
  }
}


Then you can write
Code: ags

player.Gravity(313, 3);

cEgo.Gravity(313, 3);

Creator

Thank you both for that.
Using Mazoliin's method. Seems more logical to make it a character function.

SMF spam blocked by CleanTalk