Ejemplo n.º 1
0
 public void Destroy()
 {
     if (cell.item is Rail rl)
     {
         rl.CartStopApproaching();
     }
     if (futureRail != null)
     {
         futureRail.CartStopApproaching();
     }
     Globals.player.carts.Remove(this);
 }
Ejemplo n.º 2
0
 public void Teleport(Portal toPortal)
 {
     position = toPortal.ToVector2();
     previousRail.CartStopApproaching();
     previousRail  = (Rail)cell.item;
     cell          = Cell.GetCell(position);
     moveDirection = MoveDirection.None;
     CalculateTravelDirection();
     SetFutureCell();
     if (cell.item is Rail rl)
     {
         rl.CartStartApproaching();
     }
     futureRail.CartStartApproaching();
     //previousRail.CartStopApproaching();
 }
Ejemplo n.º 3
0
        public void Move(GameTime gameTime)
        {
            move = Vector2.Zero;

            if (moveDirection == MoveDirection.None)
            {
                Destroy();
            }

            if (futureRail != null) // move
            {
                position = Vector2.Lerp(cell.ToVector2(), futureRail.cell.ToVector2(), t);

                //velocity = MathHelper.Lerp(startVel, endVel, acceleration * -t);

                velocity += acceleration * (float)gameTime.ElapsedGameTime.TotalSeconds * 0.1f;

                //velocity *= (float)gameTime.ElapsedGameTime.TotalSeconds;

                if (velocity <= endVel) // the cart is no longer travelling
                {
                    velocity = endVel;
                }

                t += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds * 0.1f;

                if (t >= 1)
                {
                    t = 0;

                    switch (moveDirection)
                    {
                    case MoveDirection.None:
                        break;

                    case MoveDirection.Up:
                        rotation = MathHelper.Pi;
                        break;

                    case MoveDirection.Down:
                        rotation = 0;
                        break;

                    case MoveDirection.Right:
                        rotation = -MathHelper.PiOver2;
                        break;

                    case MoveDirection.Left:
                        rotation = MathHelper.PiOver2;
                        break;

                    default:
                        break;
                    }

                    previousRail = (Rail)cell.item;
                    cell         = Cell.GetCell(position);

                    position = futureRail.cell.ToVector2();

                    if (cell.item is Rail rail)
                    {
                        rail.CartPassOver(this);
                    }

                    SetFutureCell();

                    if (previousRail != null)
                    {
                        previousRail.CartStopApproaching();
                    }

                    if (futureRail != null)
                    {
                        futureRail.CartStartApproaching();
                    }

                    if (cell.item is Rail rl)
                    {
                        rl.CartStartApproaching();
                    }

                    if (futureRail == null)
                    {
                        CalculateTravelDirection();
                        SetFutureCell();
                        if (futureRail != null)
                        {
                            futureRail.CartStartApproaching();
                        }
                    }
                }
            }
            else
            {
                CalculateTravelDirection();
                SetFutureCell();

                if (futureRail == null)
                {
                    Destroy();
                }
            }
        }