SetPosition() public method

public SetPosition ( PointF pos ) : void
pos MegaMan.Common.Geometry.PointF
return void
コード例 #1
0
 private void Grab()
 {
     if (InReach)
     {
         position.SetPosition(new PointF(inReachTile.ScreenX + inReachTile.Tile.Width / 2, position.Position.Y));
     }
 }
コード例 #2
0
 protected void MovePlayer(PositionComponent playerPos)
 {
     if (direction == Direction.Right)
     {
         playerPos.SetPosition(new PointF(playerPos.Position.X + tickdist, playerPos.Position.Y));
     }
     else if (direction == Direction.Left)
     {
         playerPos.SetPosition(new PointF(playerPos.Position.X - tickdist, playerPos.Position.Y));
     }
     else if (direction == Direction.Down)
     {
         playerPos.SetPosition(new PointF(playerPos.Position.X, playerPos.Position.Y + tickdist));
     }
     else if (direction == Direction.Up)
     {
         playerPos.SetPosition(new PointF(playerPos.Position.X, playerPos.Position.Y - tickdist));
     }
 }
コード例 #3
0
        private void EnforcePlayerBounds()
        {
            // if the player is not colliding, they'll be allowed to pass through the walls (e.g. teleporting)
            if ((player.GetComponent <CollisionComponent>()).Enabled)
            {
                float leftBound  = (float)Const.PlayerScrollTrigger;
                float rightBound = Screen.PixelWidth - Const.PlayerScrollTrigger;

                if (isAutoscrolling)
                {
                    leftBound += OffsetX;
                    rightBound = OffsetX + Game.CurrentGame.PixelsAcross;
                }

                // now if we aren't scrolling, hold the player at the screen borders
                if (playerPos.Position.X >= rightBound)
                {
                    playerPos.SetPosition(new PointF(rightBound, playerPos.Position.Y));
                }
                else if (playerPos.Position.X <= leftBound)
                {
                    playerPos.SetPosition(new PointF(leftBound, playerPos.Position.Y));
                }

                if (playerPos.Position.Y > Screen.PixelHeight - Const.PlayerScrollTrigger)
                {
                    if (!container.IsGravityFlipped && playerPos.Position.Y > Game.CurrentGame.PixelsDown + 32)
                    {
                        // bottomless pit death!
                        playerPos.Parent.Die();
                    }
                }
                else if (playerPos.Position.Y < Const.PlayerScrollTrigger)
                {
                    if (container.IsGravityFlipped && playerPos.Position.Y < -32)
                    {
                        playerPos.Parent.Die();
                    }
                }
            }
        }
コード例 #4
0
        protected virtual void Finish(PositionComponent playerPos)
        {
            if (direction == Direction.Right)
            {
                playerPos.SetPosition(new PointF(OffsetDist(), playerPos.Position.Y + NextScreenY));
            }
            else if (direction == Direction.Left)
            {
                playerPos.SetPosition(new PointF(nextWidth - OffsetDist(), playerPos.Position.Y + NextScreenY));
            }
            else if (direction == Direction.Down)
            {
                playerPos.SetPosition(new PointF(playerPos.Position.X + NextScreenX, OffsetDist()));
            }
            else if (direction == Direction.Up)
            {
                playerPos.SetPosition(new PointF(playerPos.Position.X + NextScreenX, nextHeight - OffsetDist()));
            }

            if (ScrollDone != null)
            {
                ScrollDone(this);
            }
        }
コード例 #5
0
 private void Run()
 {
     running = true;
     frame   = 0;
     foreach (BlockInfo info in blocks)
     {
         info.entity.SendMessage(new StateMessage(null, "Start"));
         info.entity.Start(container);
         PositionComponent pos = info.entity.GetComponent <PositionComponent>();
         if (pos == null)
         {
             continue;
         }
         pos.SetPosition(info.pos);
         info.entity.SendMessage(new StateMessage(null, info.on > 0 ? "Hide" : "Show"));
     }
 }
コード例 #6
0
        protected override void Update()
        {
            if (!CanMove || Parent.Paused)
            {
                return;
            }

            float accelX = (pendingVx - vx) * dragX;

            vx += accelX;

            float accelY = (pendingVy - vy) * dragY;

            vy += accelY;

            if (!Floating)
            {
                float gmult = (overTile != null) ? overTile.Properties.GravityMult : 1;

                if (Parent.Container.IsGravityFlipped)
                {
                    vy -= Parent.Container.Gravity * gmult;
                    if (vy < -Const.TerminalVel)
                    {
                        vy = -Const.TerminalVel;
                    }
                }
                else
                {
                    vy += Parent.Container.Gravity * gmult;
                    if (vy > Const.TerminalVel)
                    {
                        vy = Const.TerminalVel;
                    }
                }
            }

            if (FlipSprite)
            {
                SpriteComponent sprite = Parent.GetComponent <SpriteComponent>();
                if (sprite != null)
                {
                    sprite.HorizontalFlip = (Direction == Direction.Left);
                }
            }

            Tile nextOverTile = null;

            if (position != null)
            {
                float deltaX = vx + pushX;
                float deltaY = vy + pushY;

                PointF pos = position.Position;
                if (collision == null)
                {
                    pos.X += deltaX;
                    pos.Y += deltaY;
                }
                else
                {
                    if ((!collision.BlockLeft && deltaX < 0) || (!collision.BlockRight && deltaX > 0))
                    {
                        pos.X += deltaX;
                    }
                    if ((!collision.BlockTop && deltaY < 0) || (!collision.BlockBottom && deltaY > 0))
                    {
                        pos.Y += deltaY;
                    }
                }
                position.SetPosition(pos);

                nextOverTile = Parent.Screen.TileAt(position.Position.X, position.Position.Y);
            }

            if (Parent.Name == "Player")
            {
                if (overTile != null && nextOverTile != null && nextOverTile.Properties.Name != overTile.Properties.Name)
                {
                    if (overTile.Properties.OnLeave != null)
                    {
                        EffectParser.GetLateBoundEffect(overTile.Properties.OnLeave)(Parent);
                    }
                    if (nextOverTile.Properties.OnEnter != null)
                    {
                        EffectParser.GetLateBoundEffect(nextOverTile.Properties.OnEnter)(Parent);
                    }
                }

                if (nextOverTile != null && nextOverTile.Properties.OnOver != null)
                {
                    EffectParser.GetLateBoundEffect(nextOverTile.Properties.OnOver)(Parent);
                }
            }

            vx     *= resistX;
            vy     *= resistY;
            resistX = resistY = 1;

            pendingVx = vx;
            pendingVy = vy;

            overTile = nextOverTile;
            pushX    = pushY = 0;
            dragX    = dragY = 1;
        }
コード例 #7
0
 protected void MovePlayer(PositionComponent playerPos)
 {
     if (direction == Direction.Right) playerPos.SetPosition(new PointF(playerPos.Position.X + tickdist, playerPos.Position.Y));
     else if (direction == Direction.Left) playerPos.SetPosition(new PointF(playerPos.Position.X - tickdist, playerPos.Position.Y));
     else if (direction == Direction.Down) playerPos.SetPosition(new PointF(playerPos.Position.X, playerPos.Position.Y + tickdist));
     else if (direction == Direction.Up) playerPos.SetPosition(new PointF(playerPos.Position.X, playerPos.Position.Y - tickdist));
 }
コード例 #8
0
        protected virtual void Finish(PositionComponent playerPos)
        {
            if (direction == Direction.Right) { playerPos.SetPosition(new PointF(OffsetDist(), playerPos.Position.Y + NextScreenY)); }
            else if (direction == Direction.Left) { playerPos.SetPosition(new PointF(nextWidth - OffsetDist(), playerPos.Position.Y + NextScreenY)); }
            else if (direction == Direction.Down) { playerPos.SetPosition(new PointF(playerPos.Position.X + NextScreenX, OffsetDist())); }
            else if (direction == Direction.Up) { playerPos.SetPosition(new PointF(playerPos.Position.X + NextScreenX, nextHeight - OffsetDist())); }

            if (ScrollDone != null) ScrollDone(this);
        }
コード例 #9
0
ファイル: StageHandler.cs プロジェクト: laazer/cs_megaman
        protected override void BeforeStart()
        {
            Player = Entities.CreateEntityWithId("Player", "Player");
            PlayerPos = Player.GetComponent<PositionComponent>();

            Player.Death += Player_Death;

            PlayerPos = Player.GetComponent<PositionComponent>();
            PlayerPos.SetPosition(new PointF(startX, 0));

            if (!info.Screens.ContainsKey(startScreen)) throw new GameRunException("The start screen for \""+info.Name+"\" is supposed to be \""+startScreen+"\", but it doesn't exist!");
            _currentScreen = screens[startScreen];
            StartScreen();

            Engine.Instance.SoundSystem.StopMusicNsf();

            if (music != null) music.Play();
            if (info.MusicNsfTrack != 0) Engine.Instance.SoundSystem.PlayMusicNSF((uint)info.MusicNsfTrack);

            // updateFunc isn't set until BeginPlay
            drawFunc = DrawScreen;

            BeginPlay();

            // make sure we can move
            (Player.GetComponent<InputComponent>()).Paused = false;
        }
コード例 #10
0
        public static Effect ParsePositionBehavior(XElement prop, Axis axis)
        {
            Effect action = e => { };

            XAttribute baseAttr = prop.Attribute("base");

            if (baseAttr != null)
            {
                string base_str = baseAttr.Value;
                if (base_str == "Inherit")
                {
                    action = entity =>
                    {
                        PositionComponent pos = entity.GetComponent <PositionComponent>();
                        if (pos != null && entity.Parent != null)
                        {
                            PositionComponent parentPos = entity.Parent.GetComponent <PositionComponent>();
                            if (parentPos != null)
                            {
                                pos.SetPosition(axis == Axis.X
                                    ? new PointF(parentPos.Position.X, pos.Position.Y)
                                    : new PointF(pos.Position.X, parentPos.Position.Y));
                            }
                        }
                    };
                }
                else
                {
                    float baseVal = prop.TryAttribute <float>("base");
                    if (axis == Axis.X)
                    {
                        action = entity =>
                        {
                            PositionComponent pos = entity.GetComponent <PositionComponent>();
                            if (pos != null)
                            {
                                pos.SetPosition(new PointF(baseVal, pos.Position.Y));
                            }
                        }
                    }
                    ;
                    else
                    {
                        action = entity =>
                        {
                            PositionComponent pos = entity.GetComponent <PositionComponent>();
                            if (pos != null)
                            {
                                pos.SetPosition(new PointF(pos.Position.X, baseVal));
                            }
                        }
                    };
                }
            }

            if (prop.Attribute("offset") != null)
            {
                float      offset     = prop.TryAttribute <float>("offset");
                XAttribute offdirattr = prop.RequireAttribute("direction");
                if (offdirattr.Value == "Inherit")
                {
                    action += entity =>
                    {
                        PositionComponent pos = entity.GetComponent <PositionComponent>();
                        if (pos != null && entity.Parent != null)
                        {
                            Direction offdir = entity.Parent.Direction;
                            switch (offdir)
                            {
                            case Direction.Down: pos.SetPosition(new PointF(pos.Position.X, pos.Position.Y + offset)); break;

                            case Direction.Up: pos.SetPosition(new PointF(pos.Position.X, pos.Position.Y - offset)); break;

                            case Direction.Left: pos.SetPosition(new PointF(pos.Position.X - offset, pos.Position.Y)); break;

                            case Direction.Right: pos.SetPosition(new PointF(pos.Position.X + offset, pos.Position.Y)); break;
                            }
                        }
                    };
                }
                else if (offdirattr.Value == "Input")
                {
                    action += entity =>
                    {
                        PositionComponent pos   = entity.GetComponent <PositionComponent>();
                        InputComponent    input = entity.GetComponent <InputComponent>();
                        if (input != null && pos != null)
                        {
                            if (axis == Axis.Y)
                            {
                                if (input.Down)
                                {
                                    pos.SetPosition(new PointF(pos.Position.X, pos.Position.Y + offset));
                                }
                                else if (input.Up)
                                {
                                    pos.SetPosition(new PointF(pos.Position.X, pos.Position.Y - offset));
                                }
                            }
                            else
                            {
                                if (input.Left)
                                {
                                    pos.SetPosition(new PointF(pos.Position.X - offset, pos.Position.Y));
                                }
                                else if (input.Right || (!input.Up && !input.Down))
                                {
                                    pos.SetPosition(new PointF(pos.Position.X + offset, pos.Position.Y));
                                }
                            }
                        }
                    };
                }
                else
                {
                    Direction offdir;
                    try
                    {
                        offdir = (Direction)Enum.Parse(typeof(Direction), offdirattr.Value, true);
                    }
                    catch
                    {
                        throw new GameXmlException(offdirattr, "Position offset direction was not valid!");
                    }
                    switch (offdir)
                    {
                    case Direction.Left: action += entity =>
                    {
                            PositionComponent pos = entity.GetComponent <PositionComponent>();
                            if (pos != null)
                            {
                                pos.SetPosition(new PointF(pos.Position.X - offset, pos.Position.Y));
                            }
                    };
                        break;

                    case Direction.Right: action += entity =>
                    {
                            PositionComponent pos = entity.GetComponent <PositionComponent>();
                            if (pos != null)
                            {
                                pos.SetPosition(new PointF(pos.Position.X + offset, pos.Position.Y));
                            }
                    };
                        break;

                    case Direction.Down: action += entity =>
                    {
                            PositionComponent pos = entity.GetComponent <PositionComponent>();
                            if (pos != null)
                            {
                                pos.SetPosition(new PointF(pos.Position.X, pos.Position.Y + offset));
                            }
                    };
                        break;

                    case Direction.Up: action += entity =>
                    {
                            PositionComponent pos = entity.GetComponent <PositionComponent>();
                            if (pos != null)
                            {
                                pos.SetPosition(new PointF(pos.Position.X, pos.Position.Y - offset));
                            }
                    };
                        break;
                    }
                }
            }
            return(action);
        }
    }