當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。