Exemplo n.º 1
0
 public void TestAbs()
 {
     Assert.Equal(FixPoint.Abs((FixPoint)(17)), (FixPoint)(17));
     Assert.Equal(FixPoint.Abs((FixPoint)(-17)), (FixPoint)(17));
     Assert.Equal(FixPoint.Abs((FixPoint)(0)), (FixPoint)(0));
     Assert.Equal(FixPoint.Abs((FixPoint)(-0)), (FixPoint)(0));
     Assert.Equal(FixPoint.Abs((FixPoint)(-1.5f)), (FixPoint)(1.5f));
     Assert.Equal(FixPoint.Abs((FixPoint)(-int.MaxValue)), (FixPoint)(int.MaxValue));
     Assert.Equal(FixPoint.Abs((FixPoint)(-140737488355327L)), (FixPoint)(140737488355327L));
 }
Exemplo n.º 2
0
        public bool UpdateProjectile(FixPoint delta_time)
        {
            PositionComponent position_component = ParentObject.GetComponent(PositionComponent.ID) as PositionComponent;

            if (m_track_mode == TrackModeLockTarget)
            {
                Entity            target = null;
                PositionComponent target_position_component = null;
                if (m_param.m_target_entity_id > 0)
                {
                    target = GetLogicWorld().GetEntityManager().GetObject(m_param.m_target_entity_id);
                    if (target != null && !ObjectUtil.IsDead(target))
                    {
                        target_position_component = target.GetComponent(PositionComponent.ID) as PositionComponent;
                        if (target_position_component != null)
                        {
                            m_param.m_target_position = target_position_component.CurrentPosition;
                        }
                    }
                    else
                    {
                        target = null;
                    }
                }
                if (m_trajectory_type == TrajectoryTypeBezier)
                {
                    FixPoint t = (GetCurrentTime() - m_param.m_start_time) / m_param.m_life_time;
                    if (t < FixPoint.One)
                    {
                        FixPoint  l_t          = FixPoint.One - t;
                        Vector3FP new_position = l_t * l_t * m_param.m_start_position + FixPoint.Two * t * l_t * m_param.m_bezier_b + t * t * m_param.m_target_position;
                        position_component.CurrentPosition = new_position;
                        return(false);
                    }
                    else
                    {
                        position_component.CurrentPosition = m_param.m_target_position;
                        Explode(target);
                        return(true);
                    }
                }
                else
                {
                    m_param.m_fixed_facing = m_param.m_target_position - position_component.CurrentPosition;
                    if (m_trajectory_type == TrajectoryTypeHorizontalLine)
                    {
                        m_param.m_fixed_facing.y = FixPoint.Zero;
                    }
                    FixPoint  distance       = m_param.m_fixed_facing.Normalize();
                    FixPoint  delta_distance = m_speed * delta_time;
                    Vector3FP new_position   = position_component.CurrentPosition + m_param.m_fixed_facing * delta_distance;
                    position_component.CurrentPosition = new_position;
                    distance = FixPoint.Abs(distance - delta_distance);
                    bool hit = false;
                    if (target_position_component != null)
                    {
                        if (distance <= position_component.Radius + target_position_component.Radius)
                        {
                            hit = true;
                        }
                    }
                    else
                    {
                        if (distance <= m_speed * LOGIC_UPDATE_INTERVAL)
                        {
                            hit = true;
                        }
                    }
                    if (hit)
                    {
                        Explode(target);
                        return(true);
                    }
                    return(false);
                }
            }
            else
            {
                Vector3FP new_position = position_component.CurrentPosition + m_param.m_fixed_facing * (m_speed * delta_time);
                position_component.CurrentPosition = new_position;
                if (DetectCollision(position_component.GetSpacePartition(), new_position, position_component.Radius))
                {
                    return(true);
                }
                GridGraph grid_graph = position_component.GetGridGraph();
                if (grid_graph != null)
                {
                    GridNode node = grid_graph.Position2Node(new_position);
                    if (node == null)
                    {
                        m_task.LockRemainTime(m_speed);
                    }
                    else if (!node.Walkable && !m_can_cross_obstacle)
                    {
                        if (m_previous_walkable)
                        {
                            m_task.LockRemainTime(m_speed);
                        }
                    }
                    else
                    {
                        m_previous_walkable = true;
                    }
                }
                return(false);
            }
        }