Game Development Community

World Limits Code

by rennie moffat · in Torque Game Builder · 06/17/2009 (10:35 am) · 2 replies

function MeanBat :: onWorldLimit(%this, %mode, %limit)
{
switch$(%limit)
{
case"left"
%this.setFlipX(true);



%this.setLinearVelocityX(%this.getRandom(%this.getRandom(%this.minSpeed, %this.maxSpeed));
%this.setPositionY(getRandom(-35, 35));


case "right"
%this.setFlipX(false);
%this.setLinearVelocityX(-%this.getRandom(%this.minSpeed, %this.maxSpeed));
%this.setPositionY(getRandom(-35, 35));
}
}








this code is bothering me as I cant figure out why the programmer made it as such. My question being, why would the "setFlip" function be inside the "onWorldLimits" function and why is there velocity and positioning in the world limits as well?

About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
06/17/2009 (10:56 am)
When it hits the world limits it flips the graphic, give it a random velocity in the opposite direction, and gives it a random Y position on the screen.
As for the setFlip being inside the onWorldLimits, that makes sure as soon as the meanBat hits the world limits it flips and starts moving in the opposite direction.
The onWorldLimits call is for the meanBat, not the actual world limits in the game.
#2
06/17/2009 (11:16 am)
oh i see thanks,

I was expecting it to come back into the scene in the same direction, but opposite end of the camera view, ah lah pac man.


thanks.