Exemplo n.º 1
0
        void AdvanceWayPoint()
        {
            m_cur_way_point += 1;
            if (m_cur_way_point > m_path.Count - 1)
            {
                m_cur_way_point = INVALID_WAYPOINT_INDEX;
                m_callback.MovementFinished();
                return;
            }
            m_direction = m_path[m_cur_way_point] - m_path[m_cur_way_point - 1];
            FixPoint distance = m_direction.Normalize();

            m_remain_time = distance / m_max_speed;
            m_position_component.SetFacing(m_direction);
        }
Exemplo n.º 2
0
        void UpdateKeyboardEvent()
        {
            if (m_current_operate_entityi_id < 0)
            {
                return;
            }
            int old_state = m_wsad_state;

            if (Input.GetKeyDown(KeyCode.W))
            {
                m_wsad_state |= W_STATE;
            }
            if (Input.GetKeyDown(KeyCode.S))
            {
                m_wsad_state |= S_STATE;
            }
            if (Input.GetKeyDown(KeyCode.A))
            {
                m_wsad_state |= A_STATE;
            }
            if (Input.GetKeyDown(KeyCode.D))
            {
                m_wsad_state |= D_STATE;
            }
            if (Input.GetKeyUp(KeyCode.W))
            {
                m_wsad_state &= ~W_STATE;
            }
            if (Input.GetKeyUp(KeyCode.S))
            {
                m_wsad_state &= ~S_STATE;
            }
            if (Input.GetKeyUp(KeyCode.A))
            {
                m_wsad_state &= ~A_STATE;
            }
            if (Input.GetKeyUp(KeyCode.D))
            {
                m_wsad_state &= ~D_STATE;
            }
            if (m_wsad_state == old_state)
            {
                return;
            }
            if (m_wsad_state == 0)
            {
                EntityMoveCommand cmd = Command.Create <EntityMoveCommand>();
                cmd.ConstructAsStopMove(m_current_operate_entityi_id);
                PushLocalCommand(cmd);
            }
            else
            {
                RenderEntity render_entity = m_render_entity_manager.GetObject(m_current_operate_entityi_id);
                if (render_entity == null)
                {
                    return;
                }
                m_direction.MakeZero();
                if ((m_wsad_state & W_STATE) != 0)
                {
                    m_direction.z += FixPoint.One;
                }
                if ((m_wsad_state & S_STATE) != 0)
                {
                    m_direction.z -= FixPoint.One;
                }
                if ((m_wsad_state & A_STATE) != 0)
                {
                    m_direction.x -= FixPoint.One;
                }
                if ((m_wsad_state & D_STATE) != 0)
                {
                    m_direction.x += FixPoint.One;
                }
                m_direction.Normalize();
                EntityMoveCommand cmd = Command.Create <EntityMoveCommand>();
                cmd.ConstructAsDirection(m_current_operate_entityi_id, m_direction);
                PushLocalCommand(cmd);
            }
        }