本文整理汇总了C#中Actor.setPos方法的典型用法代码示例。如果您正苦于以下问题:C# Actor.setPos方法的具体用法?C# Actor.setPos怎么用?C# Actor.setPos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Actor
的用法示例。
在下文中一共展示了Actor.setPos方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: handleMapCollision
public void handleMapCollision(Actor actor)
{
actorX = actor.hitBox.X;
actorY = actor.hitBox.Y;
actorW = actor.hitBox.Width;
actorH = actor.hitBox.Height;
predictedMove.X = actorX + (int)Math.Round(actor.velocity.X);
predictedMove.Y = actorY + (int)Math.Round(actor.velocity.Y);
predictedMove.Width = actorW;
predictedMove.Height = actorH;
Point remainingMovement = new Point(0, 0);
if (worldManager.curWorld.isInBounds(predictedMove))
{
actor.setPos(predictedMove.X, predictedMove.Y);
}
else
{
if (actor.velocity.X < 0)
{
if (worldManager.curWorld.isInBounds(predictedMove.X, actorY) && worldManager.curWorld.isInBounds(predictedMove.X, actorY + actorH - 1))
remainingMovement.X = (int)actor.velocity.X;
else if (actorX % worldManager.curWorld.tileSize != 0)
{
remainingMovement.X = -(actorX % worldManager.curWorld.tileSize);
}
}
else if (actor.velocity.X > 0)
{
if (worldManager.curWorld.isInBounds(predictedMove.X + actorW, actorY) && worldManager.curWorld.isInBounds(predictedMove.X + actorW, actorY + actorH - 1))
remainingMovement.X = (int)actor.velocity.X;
else if ((actorX + actorW) % worldManager.curWorld.tileSize != 0)
remainingMovement.X = worldManager.curWorld.tileSize - ((actorX + actorW) % worldManager.curWorld.tileSize);
}
if (actor.velocity.Y < 0)
{
if (worldManager.curWorld.isInBounds(actorX, predictedMove.Y) && worldManager.curWorld.isInBounds(actorX + actorW - 1, predictedMove.Y))
remainingMovement.Y = (int)actor.velocity.Y;
else if (actorY % worldManager.curWorld.tileSize != 0)
remainingMovement.Y = -(actorY % worldManager.curWorld.tileSize);
}
else if (actor.velocity.Y > 0)
{
if (worldManager.curWorld.isInBounds(actorX, predictedMove.Y + actorH) && worldManager.curWorld.isInBounds(actorX + actorW - 1, predictedMove.Y + actorH - 1))
remainingMovement.Y = (int)actor.velocity.Y;
else if ((actorY + actorH) % worldManager.curWorld.tileSize != 0)
remainingMovement.Y = worldManager.curWorld.tileSize - ((actorY + actorH) % worldManager.curWorld.tileSize);
}
predictedMove.X = actor.hitBox.X + remainingMovement.X;
predictedMove.Y = actor.hitBox.Y + remainingMovement.Y;
predictedMove.Width--;
predictedMove.Height--;
if (worldManager.curWorld.isInBounds(predictedMove))
actor.setPos(actor.hitBox.X + remainingMovement.X, actor.hitBox.Y + remainingMovement.Y);
}
}
示例2: spawnActor
public void spawnActor(Actor actor, Point point, int spawnType){
actor.setPos(point);
actor.onSpawn(spawnType);
//actor.world = worldManager.curWorld;
actor.sightVector = new Vector2(random.Next(-1, 1), random.Next(-1, 1));
actors.Add(actor);
if (actor.isPlayer)
protagonist = actor;
}
示例3: handlePropCollision
public void handlePropCollision(Actor actor)
{
Rectangle intersectedRect = new Rectangle();
Point newPos = new Point();
foreach (Prop prop in props)
{
if (collidesWithProp(prop, actor.hitBox))
{
Rectangle.Intersect(ref actor.hitBox,ref prop.hitBox,out intersectedRect);
if (actor.velocity.X < 0)
{
newPos.X = actor.hitBox.X + intersectedRect.Width + 1;
}
else if (actor.velocity.X > 0)
{
newPos.X = actor.hitBox.X - intersectedRect.Width - 1;
}
else
{
newPos.X = actor.hitBox.X;
}
if (actor.velocity.Y < 0)
{
newPos.Y = actor.hitBox.Y + intersectedRect.Height + 1;
}
else if (actor.velocity.Y > 0)
{
newPos.Y = actor.hitBox.Y - intersectedRect.Height - 1;
}else{
newPos.Y = actor.hitBox.Y;
}
if(!collidesWithProp(prop, new Point(newPos.X, actor.hitBox.Y))){
actor.setPos(new Point(newPos.X, actor.hitBox.Y));
}
else if (!collidesWithProp(prop, new Point(actor.hitBox.X, newPos.Y)))
{
actor.setPos(new Point(actor.hitBox.X, newPos.Y));
}
else{
actor.setPos(newPos);
}
}
}
}