当前位置: 首页>>代码示例>>C#>>正文


C# Actor.setPos方法代码示例

本文整理汇总了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);

            }

        }
开发者ID:csalmon3,项目名称:DreamStateMachine,代码行数:63,代码来源:ActorManager.cs

示例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;
 }
开发者ID:csalmon3,项目名称:DreamStateMachine,代码行数:10,代码来源:ActorManager.cs

示例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);
                    }
                    
                }
                
            }
        }
开发者ID:mitjmcc,项目名称:DreamStateMachine,代码行数:48,代码来源:PhysicsController.cs


注:本文中的Actor.setPos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。