Offset() public méthode

public Offset ( float x, float y ) : void
x float
y float
Résultat void
Exemple #1
0
        protected virtual void Finish(PositionComponent playerPos)
        {
            if (direction == Direction.Right)
            {
                playerPos.SetX(OffsetDist());
                playerPos.Offset(0, NextScreenY);
            }
            else if (direction == Direction.Left)
            {
                playerPos.SetX(nextWidth - OffsetDist());
                playerPos.Offset(0, NextScreenY);
            }
            else if (direction == Direction.Down)
            {
                playerPos.SetY(OffsetDist());
                playerPos.Offset(NextScreenX, 0);
            }
            else if (direction == Direction.Up)
            {
                playerPos.SetY(nextHeight - OffsetDist());
                playerPos.Offset(NextScreenX, 0);
            }

            if (ScrollDone != null)
            {
                ScrollDone(this);
            }
        }
Exemple #2
0
 protected void MovePlayer(PositionComponent playerPos)
 {
     if (direction == Direction.Right)
     {
         playerPos.Offset(tickdist, 0);
     }
     else if (direction == Direction.Left)
     {
         playerPos.Offset(-tickdist, 0);
     }
     else if (direction == Direction.Down)
     {
         playerPos.Offset(0, tickdist);
     }
     else if (direction == Direction.Up)
     {
         playerPos.Offset(0, -tickdist);
     }
 }
Exemple #3
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;

                if (collision == null)
                {
                    position.Offset(deltaX, deltaY);
                }
                else
                {
                    if ((!collision.BlockLeft && deltaX < 0) || (!collision.BlockRight && deltaX > 0))
                    {
                        position.Offset(deltaX, 0);
                    }
                    if ((!collision.BlockTop && deltaY < 0) || (!collision.BlockBottom && deltaY > 0))
                    {
                        position.Offset(0, deltaY);
                    }
                }

                nextOverTile = Parent.Screen.TileAt(position.X, 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;
        }