コード例 #1
0
    public void UpdateAnimation(Vector2d facing, Vector2d throttle)
    {
        // Compute the speed from throttle vector
        float speed = throttle.Magnitude() * m_style.MaxSpeed;

        // Translate the sprite based on the current throttle
        if (throttle.IsNonZero)
        {
            float distance = speed * Time.deltaTime;
            float dX       = throttle.i * distance;
            float dY       = throttle.j * distance;

            SetLocalPosition(this.LocalX + dX, this.LocalY + dY);
        }

        // Update the animation controller parameters
        m_spriteAnimator.SetFloat(SPEED_FLOAT_PARAMETER, speed);
        m_spriteAnimator.SetFloat(FACING_X_FLOAT_PARAMETER, facing.i);
        m_spriteAnimator.SetFloat(FACING_Y_FLOAT_PARAMETER, facing.j);
        m_spriteAnimator.SetBool(IS_ATTACKING_BOOL_PARAMETER, false);

        // Snap the cone facing angle to the cardinal directions
        m_visionCone.ConeFacing =
            MathConstants.GetAngleForDirection(
                MathConstants.GetDirectionForVector(new Vector2d(facing.i, facing.j)));
    }
コード例 #2
0
    private void UpdateMouseCursor(WidgetEvent widgetEvent)
    {
        if (widgetEvent.EventType == WidgetEvent.eEventType.mouseOver ||
            widgetEvent.EventType == WidgetEvent.eEventType.mouseOut ||
            widgetEvent.EventType == WidgetEvent.eEventType.mouseMove)
        {
            if (widgetEvent.EventSource is HotspotWidget)
            {
                HotspotWidget hotspotWidget = widgetEvent.EventSource as HotspotWidget;
                HotspotInfo   hotspotInfo   = hotspotWidget.Userdata as HotspotInfo;

                switch (hotspotInfo.hotspotType)
                {
                case eHotspotType.energy_tank:
                {
                    EnergyTankData energyTankData = hotspotInfo.hotspotEntity as EnergyTankData;

                    if (energyTankData.ownership != GameConstants.eFaction.player)
                    {
                        // If our faction doesn't control the energy tank, we'll have to hack it
                        SetMouseCursorState(eMouseCursorState.hack_energy_tank);
                    }
                    else if (energyTankData.energy > 0)
                    {
                        // If our faction does control the energy tank, then we can drain it if it has energy
                        SetMouseCursorState(eMouseCursorState.drain_energy_tank);
                    }
                    else
                    {
                        // Otherwise all we can do is walk to it
                        SetMouseCursorState(eMouseCursorState.walk);
                    }
                }
                break;

                case eHotspotType.portal:
                {
                    Point2d hotspotCenter =
                        hotspotWidget.WorldPosition.Offset(new Vector2d(hotspotWidget.Width / 2.0f, hotspotWidget.Height / 2.0f));
                    Point2d  screenCenter    = new Point2d(Screen.width / 2.0f, Screen.height / 2.0f);
                    Vector2d vectorToHotspot = hotspotCenter - screenCenter;

                    MathConstants.eDirection currentHotspotDirection = MathConstants.GetDirectionForVector(vectorToHotspot);

                    switch (currentHotspotDirection)
                    {
                    case MathConstants.eDirection.left:
                        SetMouseCursorState(eMouseCursorState.door_left);
                        break;

                    case MathConstants.eDirection.right:
                        SetMouseCursorState(eMouseCursorState.door_right);
                        break;

                    case MathConstants.eDirection.up:
                        SetMouseCursorState(eMouseCursorState.door_up);
                        break;

                    case MathConstants.eDirection.down:
                        SetMouseCursorState(eMouseCursorState.door_down);
                        break;

                    default:
                        SetMouseCursorState(eMouseCursorState.walk);
                        break;
                    }
                }
                break;

                default:
                {
                    SetMouseCursorState(eMouseCursorState.defaultCursor);
                }
                break;
                }
            }
            else if (widgetEvent.EventSource is TileGridWidget)
            {
                if (m_currentNavRef.IsValid)
                {
                    SetMouseCursorState(eMouseCursorState.walk);
                }
                else
                {
                    SetMouseCursorState(eMouseCursorState.defaultCursor);
                }
            }
            else
            {
                SetMouseCursorState(eMouseCursorState.defaultCursor);
            }
        }
    }