Flylib.com

Books Software

 
 
 

MoveDownMoveUp


MoveDown/MoveUp

This command moves an object down or up while maintaining its orientation known as strafing ).

object.MoveDown(distance, time, animation, animation speed)
object.MoveUp(distance, time, animation, animation speed)

Parameters

distance

The distance object is to move

time

The number of seconds that the move will take (if omitted, the movement is immediate)

animation

The animation name to play (only for 3D objects)

animation speed

The speed of the animation from 0 (slowest) to 100 ( fastest ).

Sample Code

oworld = New World();
ocamera = New Camera(oworld);
sphere = oworld.CreateSphere(50,50,50,25,25);
ocamera.MoveBack(1200);
//Move the sphere.
sphere.MoveDown(400,5);

//Loop
While(TRUE);



MoveLeft/MoveRight

This command moves an object to its left or right without changing its orientation (strafing), relative to the direction that it is facing .

object.MoveLeft(distance, time, animation, animation speed)

Parameters

distance

The distance object is to move

time

The number of seconds that the move will take (if omitted, the movement is immediate)

animation

The animation name to play (only for 3D objects)

animation speed

The speed of the animation from 0 (slowest) to 100 ( fastest )

Sample Code

The following code has commands commented out for moving to the right. You must use one or the other ( MoveLeft or MoveRight ).

oworld = New World();
ocamera = New Camera(oworld);
sphere = oworld.CreateSphere(50,50,50,25,25);
ocamera.MoveBack(1200);
//Move the sphere.
sphere.MoveLeft(200,5);
//sphere.MoveRight(200,5);

//Loop
While(TRUE);



OnStopMovement

This command specifies the function to be called when certain commands are finished.

object.OnStopMovement = function

Notes

The function is called when movement of an object stops. The movement must have been caused by a command with a time parameter, such as the SetPosition , SetAngle , AddAngle , and Move commands.

Sample Code

The following code hides the sphere when motion stops.

oworld = New World();
ocamera = New Camera(oworld);
sphere = oworld.CreateSphere(50,50,50,25,25);
ocamera.MoveBack(1200);
//Move the sphere.
sphere.MoveLeft(200,5);
Sphere.OnStopMovement = hideit;

//Loop
While(TRUE);

function hideit //Hides the sphere when motion stops.
  {
    sphere.hide();
  }



Pause

This command pauses the current movement.

object.Pause();

Notes

The object stops immediately and does not resume motion until the resume command is issued.

Sample Code

The following code pauses motion of the sphere when the left arrow key is pressed and resumes motion with the resume command when the right arrow key is pressed.

oworld = New World();
ocamera = New Camera(oworld);
sphere = oworld.CreateSphere(50,50,50,25,25);
ocamera.MoveBack(1200);
//Move the sphere.
sphere.MoveDown(500,30);

//Loop
While(TRUE)
 {
  //Pause the motion when the left arrow key is pressed.
  If(IsKeyDown(Keyboard.LEFT))
   {
    Sphere.Pause();
   }
  // Resume motion when the right arrow key is pressed.
   If(IsKeyDown(Keyboard.RIGHT))
   {
    Sphere.Resume();
   }
  }



Random

This command generates a random number.

randomnumber = random(value)

Parameters

randomnumber

A random number between 0 and value

value

Specifies what the maximum possible value is of the random number

Notes

The random command is useful for making a game behave in a different way every time. For example, the position of an object at game start-up could be determined by a random number so that the location of the object will be different each time the game is played . The following code shows this happening.

The random number will generate the same random number each time unless you give it a different seed value. The SetRandom(System.GetElapsedTime()) command gives a seed value to the random number generator that is linked to the time. In this way, you will get a different set of random numbers each time.

Sample Code

Please run the following code several times so that you can see the difference in how the sphere is placed.

oworld = New World();
ocamera = New Camera(oworld);
sphere = oworld.CreateSphere(50,50,50,25,25);
ocamera.MoveBack(1200);
sphere.Walk();
SetRandom(System.GetElapsedTime());
X = random(200);
Sphere.SetPosition(x,0,0);
SetText("random no " + x);

//Loop
While(TRUE)
 {
  }