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)
|
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
|
|
animation speed |
The speed of the animation from 0 (slowest) to 100 (
|
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);
This command moves an object to its left or right without changing its orientation (strafing), relative to the direction that it is
object.MoveLeft(distance, time, animation, animation speed)
|
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
|
|
animation speed |
The speed of the animation from 0 (slowest) to 100 (
|
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);
This command specifies the function to be called when certain commands are finished.
object.OnStopMovement = function
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.
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();
}
This command pauses the current movement.
object.Pause();
The object stops immediately and does not resume motion until the resume command is issued.
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();
}
}
This command generates a random number.
randomnumber = random(value)
|
randomnumber |
A random number between 0 and value |
|
value |
Specifies what the maximum possible value is of the random number |
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
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
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)
{
}