Exemple #1
0
        public void Update(Diver diver, Room room, State s)
        {
            switch (action)
            {
                case Action.Shooting:
                    if (direction != diver.FacingDirection)
                    {
                        action = Action.Retracting;
                        break;
                    }

                    length += shootSpeed;
                    int tipX = diver.X + diver.Width / 2 + length * direction;
                    int tipY = diver.Y + diver.Height - 12;
                    if (room.TileMap.IsSolid(tipX / 16, tipY / 16))
                    {
                        diver.Freeze = true;
                        action = Action.Pulling;
                    }
                    else if (length > maxLength)
                    {
                        action = Action.Retracting;
                    }
                    break;

                case Action.Pulling:
                    length -= pullSpeed;
                    diver.Velocity = new Point(direction * pullSpeed * Diver.Resolution, 0);
                    diver.MoveWithCollision(room);
                    diver.JumpVelocity = 0;
                    if (length <= 0 || diver.Velocity.X == 0)
                    {
                        action = Action.None;
                        diver.Freeze = false;
                    }
                    break;

                case Action.Retracting:
                    length -= pullSpeed;
                    if (length <= 0)
                    {
                        action = Action.None;
                        diver.Freeze = false;
                    }
                    break;

                case Action.None:
                    break;
            }
        }