Added missing 'MoveTowards' function in Math.c and upgraded LaunchProjectile func

floating-point
Charles Spurrill 2012-08-09 17:37:53 -07:00
parent 032baa5dd6
commit e019cd5655
2 changed files with 22 additions and 8 deletions

View File

@ -141,4 +141,13 @@ global func RectangleEnsureWithin(proplist first, proplist second)
if (adjusted.y + adjusted.h > second.y + second.h) adjusted.h = second.h - (adjusted.y - second.y);
return adjusted;
}
//Moves param 'a' towards param 'b' by 'max' amount per frame
global func MoveTowards(int a, int b, int max)
{
if(b == nil) return false;
if(max == nil) max = 1;
if(a < b) return BoundBy(a + max,a,b);
if(a > b) return BoundBy(a - max,b,a);
}

View File

@ -17,11 +17,13 @@ global func SetSpeed(int x_dir, int y_dir, int prec)
// Can set either speed or angle of velocity, or both
global func SetVelocity(int angle, int speed, int precAng, int precSpd)
{
if(!precSpd) precSpd = 10;
if(!precAng) precAng = 1;
if(!speed)
speed = Distance(0,0, GetXDir(precSpd), GetYDir(precSpd));
if(!angle)
angle = Angle(0,0, GetXDir(precSpd), GetYDir(precSpd), precAng);
if(!precAng) precAng = 1;
var x_dir = Sin(angle, speed, precAng);
var y_dir = -Cos(angle, speed, precAng);
@ -75,15 +77,18 @@ global func GetPosition(int prec)
}
// Speed the calling object into the given direction (angle)
global func LaunchProjectile(int angle, int dist, int speed, int x, int y, bool rel_x)
global func LaunchProjectile(int angle, int dist, int speed, int x, int y, int precAng, int precSpd, bool rel_x)
{
// dist: Distance object travels on angle. Offset from calling object.
// x: X offset from container's center
// y: Y offset from container's center
// rel_x: if true, makes the X offset relative to container direction. (x=+30 will become x=-30 when Clonk turns left. This way offset always stays in front of a Clonk.)
var x_offset = Sin(angle, dist);
var y_offset = -Cos(angle, dist);
var x_offset = Sin(angle, dist, precAng);
var y_offset = -Cos(angle, dist, precAng);
if(!precAng) precAng = 1;
if(!precSpd) precSpd = 10;
if (Contained() != nil && rel_x == true)
if (Contained()->GetDir() == 0)
@ -91,16 +96,16 @@ global func LaunchProjectile(int angle, int dist, int speed, int x, int y, bool
if (Contained() != nil)
{
Exit(x_offset + x, y_offset + y, angle);
SetVelocity(angle, speed);
Exit(x_offset + x, y_offset + y, angle / precAng);
SetVelocity(angle, speed, precAng, precSpd);
return true;
}
if (Contained() == nil)
{
SetPosition(GetX() + x_offset + x, GetY() + y_offset + y);
SetR(angle);
SetVelocity(angle, speed);
SetR(angle/precAng);
SetVelocity(angle, speed, precAng, precSpd);
return true;
}
return false;