private void PostCharacterMovedEvent(
            RequestCache requestCache)
        {
            // Add a game event if the player is moving to the portal
            if (m_move_to_target)
            {
                GameEventParameters gameEvent =
                    new GameEvent_CharacterMoved()
                {
                    character_id = m_character_id,
                    room_x       = m_current_room_key.x,
                    room_y       = m_current_room_key.y,
                    room_z       = m_current_room_key.z,
                    from_x       = m_current_character_position.x,
                    from_y       = m_current_character_position.y,
                    from_z       = m_current_character_position.z,
                    from_angle   = m_current_character_angle,
                    to_x         = m_energy_tank.Position.x,
                    to_y         = m_energy_tank.Position.y,
                    to_z         = m_energy_tank.Position.z,
                    to_angle     = MathConstants.GetAngleForDirection(MathConstants.eDirection.down)
                };

                GameEventQueries.AddEvent(requestCache.DatabaseContext, m_game_id, gameEvent);

                m_ai_relevant_events.Add(gameEvent);
            }
        }
Пример #2
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)));
    }
Пример #3
0
        private bool UpdateCharacterState(
            RequestCache requestCache,
            out string result_code)
        {
            bool success;

            // Update the players position to the new position in the room
            Player player = requestCache.GetPlayer(m_room.room_key, m_character_id);

            if (player != null)
            {
                player.Position.Set(m_energy_tank.Position);
                player.Angle  = MathConstants.GetAngleForDirection(MathConstants.eDirection.down);
                player.Energy = m_current_character_energy + m_energy_tank_old_energy;

                result_code = SuccessMessages.GENERAL_SUCCESS;
                success     = true;
            }
            else
            {
                result_code = ErrorMessages.CACHE_ERROR + "(Failed to update character position and energy)";
                success     = false;
            }

            return(success);
        }
Пример #4
0
    public MobWidget(WidgetGroup parentGroup, MobWidgetStyle style, MobData mobData) :
        base(
            parentGroup,
            style.Width,
            style.Height,
            GameConstants.ConvertRoomPositionToPixelPosition(mobData.PositionInRoom).x,
            GameConstants.ConvertRoomPositionToPixelPosition(mobData.PositionInRoom).y) // Gross
    {
        MobType mobType = MobTypeManager.GetMobTypeByName(mobData.mob_type_name);

        m_style = style;

        m_title =
            new LabelWidget(
                this,
                style.LabelWidth,                                     // width
                style.LabelHeight,                                    // height
                (m_style.Width / 2.0f) - (m_style.LabelWidth / 2.0f), // local x
                -m_style.BoundsHeight - style.LabelHeight,            // local y
                mobType.Label);                                       // text
        m_title.Alignment = TextAnchor.UpperCenter;

        m_energy =
            new LabelWidget(
                this,
                style.LabelWidth,                                     // width
                style.LabelHeight,                                    // height
                (m_style.Width / 2.0f) - (m_style.LabelWidth / 2.0f), // local x
                0,                                                    // local y
                "");                                                  // text
        m_energy.Alignment = TextAnchor.UpperCenter;
        this.Energy        = mobData.energy;

        // Create the sprite game object
        {
            string archetype      = mobType.Name;
            string gameObjectPath = "Gfx/Sprites/Enemies/" + archetype + "/" + archetype + "_sprite";

            m_spriteObject =
                GameObject.Instantiate(
                    Resources.Load <GameObject>(gameObjectPath)) as GameObject;
            m_spriteAnimator = m_spriteObject.GetComponent <Animator>();

            UpdateWorldPosition();
        }

        // Create the dialog label
        m_dialog =
            new LabelWidget(
                this,
                style.DialogWidth,                                     // width
                style.DialogHeight,                                    // height
                (m_style.Width / 2.0f) - (m_style.DialogWidth / 2.0f), // local x
                m_title.LocalY - style.DialogHeight,                   // local y
                "");                                                   // text
        m_dialog.FontSize  = 14;
        m_dialog.Color     = Color.red;
        m_dialog.Alignment = TextAnchor.UpperCenter;
        m_dialog.Visible   = false;

        // Set the initial animation controller parameters
        m_spriteAnimator.SetFloat(SPEED_FLOAT_PARAMETER, 0.0f);
        m_spriteAnimator.SetFloat(FACING_X_FLOAT_PARAMETER, 0.0f);
        m_spriteAnimator.SetFloat(FACING_Y_FLOAT_PARAMETER, -1.0f);
        m_spriteAnimator.SetBool(IS_ATTACKING_BOOL_PARAMETER, false);

        // Create the vision cone
        m_visionCone =
            new VisionConeWidget(
                this,
                mobType.Name + mobData.mob_id.ToString(),
                mobType.VisionConeDistance,
                mobType.VisionConeAngleDegrees,
                0.0f,
                0.0f,
                0.0f);
        m_visionCone.ConeFacing = MathConstants.GetAngleForDirection(MathConstants.eDirection.down);
    }