Exemple #1
0
    public void GetNextClydeGhostNode()
    {
        GhostNode tempGhostNode = _currentNode;

        if (_chaseCorner)
        {
            _currentNode = tempGhostNode.GetFurthesrPacManGhostNode(_lastGhostNode);
        }
        else
        {
            _currentNode = tempGhostNode.GetNextPacManGhostNode(_lastGhostNode);
        }
        _lastGhostNode = tempGhostNode;
        LookAtTarget();
        _moving = true;

        if (_chaseCorner && _cornerChaseTimer >= 20.0f)
        {
            _chaseCorner      = false;
            _cornerChaseTimer = 0.0f;
            return;
        }

        if (!_chaseCorner && (Vector3.Distance(transform.position, GameManager.instance.pacManTransform.position) < 10.0f))
        {
            _chaseCorner      = true;
            _cornerChaseTimer = 0.0f;
            return;
        }
    }
Exemple #2
0
 public GhostEdge(GhostNode a, GhostNode b, bool isConstraint)
 {
     this.a       = a;
     this.b       = b;
     Length       = (a.position - b.position).magnitude;
     IsConstraint = isConstraint;
 }
Exemple #3
0
    private void ApplyConstraints()
    {
        for (int i = 0; i < vertices.Count; i++)
        {
            vertices[i].NextPosition();
        }

        for (int iter = 0; iter < constraintIter; iter++)
        {
            for (int i = 0; i < vertices.Count; i++)
            {
                GhostNode a = vertices[i];
                for (int j = 0; j < a.Connection.Count; j++)
                {
                    GhostEdge e = a.Connection[j];
                    GhostNode b = e.ConnectedTo(a);

                    Vector3 delta = a.position - b.position;

                    float distance = delta.magnitude;
                    float f        = (distance - e.Length) / distance;

                    a.position -= f * 0.5f * delta;
                    b.position += f * 0.5f * delta;
                }
            }
        }
    }
Exemple #4
0
    public void GetClosestPacManNode()
    {
        GhostNode tempGhostNode = _currentNode;

        _currentNode   = tempGhostNode.GetNextPacManGhostNode(_lastGhostNode);
        _lastGhostNode = tempGhostNode;
        LookAtTarget();
        _moving = true;
    }
Exemple #5
0
    public void Respawn()
    {
        _moving = false;
        Vector3 newPos = transform.position;

        newPos.x           = _spawnPos.x;
        newPos.z           = _spawnPos.z;
        transform.position = newPos;
        GoBlue(false);
        _currentNode = _firstGhostNode;
        LookAtTarget();
    }
Exemple #6
0
    public GhostNode GetNextGhostNode(GhostNode lastGhostNode)
    {
        int newNodeIndex = (int)Random.Range(0, _connectedGhostNodes.Count);

        if (_connectedGhostNodes[newNodeIndex] != lastGhostNode)
        {
            return(_connectedGhostNodes[newNodeIndex]);
        }
        else
        {
            return(GetNextGhostNode(lastGhostNode));
        }
    }
Exemple #7
0
    // Use this for initialization
    void Start()
    {
        if (!_rb)
        {
            _rb = GetComponent <Rigidbody>();
        }

        _firstGhostNode = _currentNode;
        _spawnPos       = transform.position;
        _renderer       = GetComponent <Renderer>();
        _normalColor    = _renderer.material.color;
        LookAtTarget();
    }
Exemple #8
0
        /// <summary>
        /// Prepares a node
        /// </summary>
        /// <param name="nodeId">Unique ID of the node for which to create</param>
        /// <param name="ghostNode">Indicates whether or not a GhostNode should be created</param>
        /// <returns>An INode object with the given specifications</returns>
        private static INode PrepareNode(string nodeId, bool ghostNode)
        {
            INode node;

            if (ghostNode)
            {
                node = new GhostNode(nodeId);
            }
            else
            {
                node = new Node(nodeId);
            }

            node.SourceMechanism = CreationType.Live;

            return(node);
        }
Exemple #9
0
    public GhostNode GetNextPacManFlankGhostNode(GhostNode lastGhostNode)
    {
        GhostNode closestNode     = null;
        float     closestDistance = Mathf.Infinity;
        Vector3   playerFlankPos  = GameManager.instance.pacManTransform.position + (Camera.main.transform.forward * 10.0f);

        foreach (GhostNode node in _connectedGhostNodes)
        {
            if (node == lastGhostNode)
            {
                continue;
            }
            float distance = Vector3.Distance(node.transform.position, playerFlankPos);
            if (distance < closestDistance)
            {
                closestNode     = node;
                closestDistance = distance;
            }
        }

        return(closestNode);
    }
Exemple #10
0
    public GhostNode GetFurthesrPacManGhostNode(GhostNode lastGhostNode)
    {
        GhostNode closestNode     = null;
        float     closestDistance = 0;
        Vector3   playerPos       = GameManager.instance.pacManTransform.position;

        foreach (GhostNode node in _connectedGhostNodes)
        {
            if (node == lastGhostNode)
            {
                continue;
            }
            float distance = Vector3.Distance(node.transform.position, playerPos);
            if (distance > closestDistance)
            {
                closestNode     = node;
                closestDistance = distance;
            }
        }

        return(closestNode);
    }
Exemple #11
0
 //Find which Node does p connected to
 public GhostNode ConnectedTo(GhostNode p)
 {
     return(a == p ? b : a);
 }
Exemple #12
0
        /// <summary>
        /// Adds the specificed edge
        /// </summary>
        /// <param name="graphComponents">The Graph that data is being imported into</param>
        /// <param name="creationType">The specified CreationType</param>
        /// <param name="objEdge">Edge to be added</param>
        public static void AddEdge(GraphComponents graphComponents, CreationType creationType, EdgeMapData objEdge)
        {
            INode uiSourceNode = graphComponents.Data.GetNode(objEdge.Source);

            if (uiSourceNode == null && creationType == CreationType.Imported)
            {
                throw new Exception("Missing Source Node");
            }
            else if (uiSourceNode == null)// && creationType == CreationType.Live
            {
                uiSourceNode = new GhostNode(objEdge.Source);
            }

            INode uiTargetNode = graphComponents.Data.GetNode(objEdge.Target);

            if (uiTargetNode == null && creationType == CreationType.Imported)
            {
                throw new Exception("Missing Target Node");
            }
            else if (uiTargetNode == null)// && creationType == CreationType.Live
            {
                uiTargetNode = new GhostNode(objEdge.Target);
            }

            if (string.IsNullOrEmpty(objEdge.Label) && objEdge.Attributes.Count == 0)
            {
                Berico.SnagL.Model.Edge uiEdge = new Berico.SnagL.Model.Edge(uiSourceNode, uiTargetNode);
                uiEdge.SourceMechanism = creationType;

                // Properties
                uiEdge.Type = objEdge.Type;

                // the EdgeViewModel must be created after uiEdge has had a Type specified
                IEdgeViewModel uiEdgeVM = EdgeViewModelBase.GetEdgeViewModel(uiEdge, graphComponents.Scope);
                graphComponents.AddEdgeViewModel(uiEdgeVM);
            }
            else
            {
                DataEdge uiEdge = new DataEdge(uiSourceNode, uiTargetNode);
                uiEdge.SourceMechanism = creationType;

                // Properties
                uiEdge.Type         = objEdge.Type;
                uiEdge.DisplayValue = objEdge.Label;

                // the EdgeViewModel must be created after uiEdge has had a Type specified
                IEdgeViewModel uiEdgeVM = EdgeViewModelBase.GetEdgeViewModel(uiEdge, graphComponents.Scope);
                graphComponents.AddEdgeViewModel(uiEdgeVM);

                uiEdgeVM.Thickness     = objEdge.Thickness;
                uiEdgeVM.Color         = new SolidColorBrush(objEdge.Color);
                uiEdgeVM.EdgeLine.Text = objEdge.Label;
                uiEdgeVM.EdgeLine.LabelTextUnderline   = objEdge.IsLabelTextUnderlined;
                uiEdgeVM.EdgeLine.LabelBackgroundColor = new SolidColorBrush(objEdge.LabelBackgroundColor);
                uiEdgeVM.EdgeLine.LabelForegroundColor = new SolidColorBrush(objEdge.LabelForegroundColor);
                uiEdgeVM.EdgeLine.LabelFontStyle       = objEdge.LabelFontStyle;
                uiEdgeVM.EdgeLine.LabelFontWeight      = objEdge.LabelFontWeight;
                if (objEdge.LabelFont != null)
                {
                    uiEdgeVM.EdgeLine.LabelFont = objEdge.LabelFont;
                }

                // Attributes
                foreach (KeyValuePair <string, AttributeMapData> objEdgeAttrKVP in objEdge.Attributes)
                {
                    Attributes.Attribute uiEdgeAttribute      = new Attributes.Attribute(objEdgeAttrKVP.Value.Name);
                    AttributeValue       uiEdgeAttributeValue = new AttributeValue(objEdgeAttrKVP.Value.Value);

                    uiEdge.Attributes.Add(uiEdgeAttribute.Name, uiEdgeAttributeValue);
                    //GlobalAttributeCollection.GetInstance(graphComponents.Scope).Add(uiEdgeAttribute, uiEdgeAttributeValue);

                    uiEdgeAttribute.SemanticType = objEdgeAttrKVP.Value.SemanticType;
                    uiEdgeAttribute.PreferredSimilarityMeasure = objEdgeAttrKVP.Value.SimilarityMeasure;
                    uiEdgeAttribute.Visible = !objEdgeAttrKVP.Value.IsHidden;
                }
            }
        }
Exemple #13
0
    private void BuildGhost()
    {
        //Iterate through all the vertices and add them to the vertices array
        //vertice[] store GhostNode and the acutal GameObject is stored in verticesGO.
        //See my documentation for the position of each vertices.
        Transform t;

        for (int i = 0; i < numOfVertices; i++)
        {
            if (i == 5 || i == 7 || i == 9)
            {
                t = ghostBody.Find(i.ToString());
            }
            else if (i == 13)
            {
                t = ghostHead.Find("left_eye");
            }
            else if (i == 14)
            {
                t = ghostHead.Find("right_eye");
            }
            else
            {
                t = ghostHead.Find(i.ToString());
            }

            vertices.Add(new GhostNode(t.position));
            verticesGO.Add(t.gameObject);
        }

        for (int i = 0; i < numOfVertices; i++)
        {
            GhostNode a = vertices[i];

            //Basic Shape of Ghost:
            if (i < 12)
            {
                GhostNode b = vertices[i + 1];
                GhostEdge e = new GhostEdge(a, b, false);
                a.Connect(e);
                b.Connect(e);
            }

            //Additional Constraints:
            if (i == 4)
            {
                GhostNode b = vertices[0];
                GhostEdge e = new GhostEdge(a, b, true);
                a.Connect(e);
                b.Connect(e);
            }
            if (i == 6)
            {
                GhostNode b = vertices[4];
                GhostEdge e = new GhostEdge(a, b, true);
                a.Connect(e);
                b.Connect(e);

                b = vertices[8];
                e = new GhostEdge(a, b, true);
                a.Connect(e);
                b.Connect(e);
            }
            if (i == 7)
            {
                GhostNode b = vertices[1];
                GhostEdge e = new GhostEdge(a, b, true);
                a.Connect(e);
                b.Connect(e);
            }
            if (i == 10)
            {
                GhostNode b = vertices[8];
                GhostEdge e = new GhostEdge(a, b, true);
                a.Connect(e);
                b.Connect(e);

                b = vertices[1];
                e = new GhostEdge(a, b, true);
                a.Connect(e);
                b.Connect(e);
            }
            if (i == 11)
            {
                GhostNode b = vertices[3];
                GhostEdge e = new GhostEdge(a, b, false);
                a.Connect(e);
                b.Connect(e);
            }
            if (i == 12)
            {
                GhostNode b = vertices[0];
                GhostEdge e = new GhostEdge(a, b, false);
                a.Connect(e);
                b.Connect(e);

                b = vertices[2];
                e = new GhostEdge(a, b, true);
                a.Connect(e);
                b.Connect(e);
            }
            if (i == 13)
            {
                GhostNode b = vertices[0];
                GhostEdge e = new GhostEdge(a, b, true);
                a.Connect(e);
                b.Connect(e);

                b = vertices[12];
                e = new GhostEdge(a, b, true);
                a.Connect(e);
                b.Connect(e);

                b = vertices[14];
                e = new GhostEdge(a, b, true);
                a.Connect(e);
                b.Connect(e);
            }
            if (i == 14)
            {
                GhostNode b = vertices[1];
                GhostEdge e = new GhostEdge(a, b, true);
                a.Connect(e);
                b.Connect(e);

                b = vertices[2];
                e = new GhostEdge(a, b, true);
                a.Connect(e);
                b.Connect(e);
            }
        }
    }