Esempio n. 1
0
    /// <summary>
    /// Calculates all Lines making up the given level and puts them into the WallLines dictionary.
    /// </summary>
    private void CalculateLines(bool[,] levelMap)
    {
        Lines = new WallToLines();

        Generator g   = WorldConstants.MatchWrapper.GetComponent <CreateLevel>().LevelGen;
        int       max = Math.Max(levelMap.GetLength(0), levelMap.GetLength(1));

        //Create the lines in each row and column.
        for (int n = 0; n < max; ++n)
        {
            if (n < levelMap.GetLength(0))
            {
                Line.GetVerticalLines(g.FillData, Lines, n);
            }
            if (n < levelMap.GetLength(1))
            {
                Line.GetHorizontalLines(g.FillData, Lines, n);
            }
        }

        //Lengthen each end by half a wall size.
        foreach (Line l in Lines.GetAllLines())
        {
            l.LineRange.Range += 1.0f;
        }

        //Combine any duplicated lines.
        Lines.CombineReferences();
    }
    void FixedUpdate()
    {
        //Rebuild bounds.
        actorBounds.Clear();
        otherBounds.Clear();
        foreach (StateMachine a in Actors)
        {
            actorBounds.Add(a.ActorBounds);
        }
        foreach (GameObject g in Others)
        {
            otherBounds.Add(new RecBounds(g.collider.bounds));
        }

        //Otherwise, check for actor collisions.
        for (int i = 0; i < Actors.Count; ++i)
        {
            //TODO: If the actor moves at least 0.25 per fixed update, check halfway between his old and new bounds.

            //With other actors.
            for (int j = i + 1; j < Actors.Count; ++j)
            {
                if (actorBounds[i].Intersects(actorBounds[j]))
                {
                    Actors[i].SendMessage("CollideWithActor", Actors[j], SendMessageOptions.DontRequireReceiver);
                    Actors[j].SendMessage("CollideWithActor", Actors[i], SendMessageOptions.DontRequireReceiver);
                }
            }

            //With collectibles.
            for (int j = 0; j < Others.Count; ++j)
            {
                if (actorBounds[i].Intersects(otherBounds[j]))
                {
                    Actors[i].SendMessage("CollideWithOther", Others[j], SendMessageOptions.DontRequireReceiver);
                    Others[j].SendMessage("CollideWithActor", Actors[i], SendMessageOptions.DontRequireReceiver);
                }
            }

            //With walls.
            for (int j = 0; j < wallBounds.Count; ++j)
            {
                if (DrawWalls)
                {
                    StateMachine.DrawBounds(wallBounds[j], Color.white);
                }

                if (actorBounds[i].Intersects(wallBounds[j]))
                {
                    Actors[i].SendMessage("CollideWithWall", wallBounds[j], SendMessageOptions.DontRequireReceiver);
                }
            }
        }

        //Now check for objective/collectible collisions with other objectives/collectibles.
        for (int i = 0; i < Others.Count; ++i)
        {
            for (int j = i + 1; j < Others.Count; ++j)
            {
                if (otherBounds[i].Intersects(otherBounds[j]))
                {
                    Others[i].SendMessage("CollideWithOther", Others[j], SendMessageOptions.DontRequireReceiver);
                    Others[j].SendMessage("CollideWithOther", Others[i], SendMessageOptions.DontRequireReceiver);
                }
            }
        }

        if (!DrawLines)
        {
            return;
        }

        foreach (Line l in Lines.GetAllLines())
        {
            Debug.DrawLine(l.Endpoint1, l.Endpoint2, Color.red);
        }

        StateMachine.DrawBounds(new RecBounds(WorldConstants.Size * 0.5f, WorldConstants.Size), Color.yellow);
    }