本文整理汇总了C#中PhysicsObject.MoveTo方法的典型用法代码示例。如果您正苦于以下问题:C# PhysicsObject.MoveTo方法的具体用法?C# PhysicsObject.MoveTo怎么用?C# PhysicsObject.MoveTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PhysicsObject
的用法示例。
在下文中一共展示了PhysicsObject.MoveTo方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnUnitFlee
void OnUnitFlee(PhysicsObject unit)
{
foreach (var team in teams.Keys)
{
if (teams[team].DeployQueue.Contains(unit))
{
teams[team].DeployQueue.Remove(unit);
ProgressDeployQueue(team);
}
}
unit.StopMoveTo();
unit.IgnoresCollisionResponse = true;
unit.MoveTo(new Vector(unit.X > 0 ? Screen.Right + 100 : Screen.Left - 100, unit.Y), unitMoveSpeed, ()=>unit.Destroy());
moveOrStayTarget[unit] = null;
}
示例2: RedoMoveTo
private void RedoMoveTo(PhysicsObject unit)
{
if (unit.IgnoresCollisionResponse == true)
OnUnitFlee(unit);
if (moveOrStayTarget.Keys.Contains(unit) && moveOrStayTarget[unit] != null)
{
Vector movePos = moveOrStayTarget[unit].Item1;
Action afterMove = moveOrStayTarget[unit].Item2;
if (afterMove != null)
{
unit.MoveTo(movePos, unitMoveSpeed, afterMove);
}
else
{
unit.MoveTo(movePos, unitMoveSpeed);
}
}
}
示例3: OnMoveUnit
void OnMoveUnit(PhysicsObject unit, int index, RoadMap path)
{
// Already fleeing
if (unit.IgnoresCollisionResponse)
return;
// determine in which turn to traverse the path
int increment = +1;
if (unit.Tag == "m")
increment = -1;
if (unit.Image == hPreparer)
{
if (MoveToClosestTree(unit, treeImage)) return;
}
if (unit.Image == mGatherer)
{
if (MoveToClosestTree(unit, saplingImage)) return;
}
if (unit.Image == hGatherer)
{
if (MoveToClosestTree(unit, logImage)) return;
}
if (unit.Image == mPreparer)
{
if (MoveToClosestTree(unit, stumpImage)) return;
}
Vector moveToPos = path.Segments[index].Position;
if (index + increment >= 0 && index + increment < path.Segments.Length)
{
Action afterMove = () => OnMoveUnit(unit, index + increment, path);
unit.MoveTo(moveToPos, unitMoveSpeed, afterMove);
moveOrStayTarget[unit] = new Tuple<Vector,Action>(moveToPos, afterMove);
}
else
{
// Stop at the end of the path
unit.MoveTo(moveToPos, unitMoveSpeed);
moveOrStayTarget[unit] = new Tuple<Vector, Action>(moveToPos, null);
}
}
示例4: OnEnemiesCollide
void OnEnemiesCollide(PhysicsObject thisCollides, PhysicsObject toThat)
{
if (thisCollides.Tag == "h" && toThat.Tag == "m")
{
OnEnemiesCollide(toThat, thisCollides);
return;
}
// Already fleeing
if (thisCollides.IgnoresCollisionResponse || toThat.IgnoresCollisionResponse)
return;
// Push them apart and then togehter.
Vector delta = thisCollides.Position - toThat.Position;
toThat.Hit(toThat.Position + delta * 6.0);
thisCollides.Hit(thisCollides.Position - delta * 6.0);
Timer.SingleShot(0.1, () =>
{
toThat.MoveTo(thisCollides.Position, unitMoveSpeed);
thisCollides.MoveTo(toThat.Position, unitMoveSpeed);
});
double thisHitMultiplier = 1.0;
double thatHitMultiplier = 1.0;
//* Kauhea mörkö pelottaa metsureita ja mönkijöitä kaksinkertaisella voimalla
if ( (thisCollides.Image == mRepeller && toThat.Image == hPreparer) ||
(thisCollides.Image == mRepeller && toThat.Image == hGatherer) )
{
thisHitMultiplier = 2.0;
thatHitMultiplier = 0.5;
}
//* Eläimet karkoittavat toimittajia kaksinkertaisella teholla (mörköhavainnot osoittautuivat vain metsässä jolkottelevaksi hirveksi)
if (thisCollides.Image == mGatherer && toThat.Image == hRepeller)
{
thisHitMultiplier = 2.0;
thatHitMultiplier = 0.5;
}
//* Mönkijä karkoittaa pärinällään eläimiä kaksinkertaisella teholla
if (toThat.Image == hGatherer && thisCollides.Image == mGatherer)
{
thisHitMultiplier = 0.5;
thatHitMultiplier = 2.0;
}
//* Toimittaja karkoittaa haamumörköjä ja kauheita mörköjä kaksinkertaisella teholla
if ((toThat.Image == hRepeller && thisCollides.Image == mRepeller ) ||
(toThat.Image == hRepeller && thisCollides.Image == mPreparer ))
{
thisHitMultiplier = 0.5;
thatHitMultiplier = 2.0;
}
// First subobject is assumed to be health bar
DoubleMeter hpThis = (DoubleMeter)(thisCollides.Objects.First() as ProgressBar).Meter;
DoubleMeter hpThat = (DoubleMeter)(toThat.Objects.First() as ProgressBar).Meter;
hpThis.AddValue(hitPerHit * thatHitMultiplier);
hpThat.AddValue(hitPerHit * thisHitMultiplier);
// Make sure we are locked into deadly? combat.
// This requires us to make sure we try to move to the end of the line.
// TODO: Find out why sometimes the unit shoots away. This quickfix tries to fix it)
Timer.SingleShot(0.25, () => RedoMoveTo(thisCollides));
// TODO: Find out why sometimes the unit shoots away. This quickfix tries to fix it)
Timer.SingleShot(0.25, () => RedoMoveTo(toThat));
}
示例5: MoveToDeployQueue
void MoveToDeployQueue(PlayerTeam team, PhysicsObject unit, double addResources)
{
Vector moveToPos = GatherPoints[team] + new Vector(
40 * teams[team].DeployQueue.Count,
Math.Min(1, 40 * teams[team].DeployQueue.Count)*( team==PlayerTeam.Humans?40:-40) );
Action afterMove = () => ProgressDeployQueue(team);
if (addResources > 0)
afterMove = () => {
OnResourceAdded(team, addResources, false);
ProgressDeployQueue(team);
};
unit.MoveTo(moveToPos, unitMoveSpeed, afterMove);
moveOrStayTarget[unit] = new Tuple<Vector, Action>(moveToPos, afterMove);
teams[team].DeployQueue.AddLast(unit);
}
示例6: MoveToClosestTree
bool MoveToClosestTree(PhysicsObject unit, Image treeState)
{
if (trees.Where(t => t.Image == treeState).Count() == 0) return false;
// TODO. Very very ugly LINQ stuff. (OTOH it is a very short list)
double closestTreeDistance = (trees.Where(t => t.Image == treeState)).Min(t => Vector.Distance(unit.Position, t.Position));
PhysicsObject closestTree = (trees.Where(t => t.Image == treeState && Vector.Distance(unit.Position, t.Position) == closestTreeDistance)).First();
// Closest full grown tree
if (Vector.Distance(unit.Position, closestTree.Position) < maxTreeRange)
{
unit.MoveTo(closestTree.Position, unitMoveSpeed);
moveOrStayTarget[unit] = new Tuple<Vector, Action>(closestTree.Position, null);
return true;
}
return false;
}
示例7: LuoPutki
void LuoPutki(double x, double y)
{
double ht = Screen.Height;
PhysicsObject putki = new PhysicsObject(50, ht);
putki.Tag = "putki";
putki.Image = putkenkuva;
PhysicsObject putkenpaaAla = new PhysicsObject(70, 30);
putkenpaaAla.IgnoresCollisionResponse = true;
putkenpaaAla.IgnoresGravity = true;
putkenpaaAla.Image = putkenpaakuva;
putkenpaaAla.Y = putki.Height / 2;
putkenpaaAla.Tag = "putki";
putki.Add(putkenpaaAla);
PhysicsObject putkenpaaYla = new PhysicsObject(70, 30);
putkenpaaYla.IgnoresCollisionResponse = true;
putkenpaaYla.IgnoresGravity = true;
putkenpaaYla.Image = putkenpaakuva;
putkenpaaYla.Y = -putki.Height / 2;
putkenpaaYla.Tag = "putki";
putki.Add(putkenpaaYla);
PhysicsObject pisteseina = new PhysicsObject(10, 200);
pisteseina.IgnoresGravity = true;
pisteseina.IgnoresCollisionResponse = true;
pisteseina.Position = new Vector(x, y + putki.Height / 2 + pisteseina.Height / 2);
pisteseina.IsVisible = false;
pisteseina.CollisionIgnoreGroup = 1;
Add(pisteseina);
// Painovoima ei vaikuta
putki.IgnoresPhysicsLogics = true;
putki.CanRotate = false;
// Ei törmäile maahan
putki.CollisionIgnoreGroup = 1;
putkenpaaAla.CollisionIgnoreGroup = 1;
putkenpaaYla.CollisionIgnoreGroup = 1;
putki.Position = new Vector(x, y);
Add(putki);
AddCollisionHandler(Lintu, pisteseina, Pelaajallepiste);
// Pistä putket tulemaan lintua kohti
Vector movePos = new Vector(-ht, y);
putki.MoveTo(movePos, 100);
Vector movePosPiste = new Vector(-ht, pisteseina.Y);
pisteseina.MoveTo(movePosPiste, 100);
}