示例#1
0
    private void drawLaser(laserNode start, laserNode end)
    {
        Vector3 startPos = coordToPos(start.getX(), start.getY(), start.getHeading(), start.getMarchDir(), true);
        Vector3 endPos   = coordToPos(end.getX(), end.getY(), end.getHeading(), end.getMarchDir(), false);

        laserContainer.transform.GetChild(laserCounter).GetComponent <LineRenderer>().SetPosition(0, startPos);
        laserContainer.transform.GetChild(laserCounter).GetComponent <LineRenderer>().SetPosition(1, endPos);
        laserContainer.transform.GetChild(laserCounter).GetComponent <LineRenderer>().enabled    = true;
        laserContainer.transform.GetChild(laserCounter).GetComponent <LineRenderer>().startColor = new Color(1, 1, 1, start.getStrength() * laserIntensity);
        laserContainer.transform.GetChild(laserCounter).GetComponent <LineRenderer>().endColor   = new Color(1, 1, 1, end.getStrength() * laserIntensity);
        if (start.getOwner() == Player.Shared)
        {
            laserContainer.transform.GetChild(laserCounter).GetComponent <LineRenderer>().material = laserMaterialCombined;
        }
        else
        {
            laserContainer.transform.GetChild(laserCounter).GetComponent <LineRenderer>().material = start.getOwner() == Player.PlayerOne ? laserMaterialP1 : laserMaterialP2;
        }
        laserCounter++;
    }
示例#2
0
    private void laserStep(laserNode node) // Need to add: if strength <= 0 return
    {
        // Get data from node
        int       x = node.getX(), y = node.getY(), indx = node.getIndex(), subIndx = node.getSubIndex();
        float     strength = node.getStrength();
        Direction heading = node.getHeading(), direction = node.getMarchDir();
        Player    player = node.getOwner();

        // Check if valid iteration
        if (x < 0 || y < 0 || x >= gridManager.theGrid.getDimX() || y >= gridManager.theGrid.getDimY() || iterationCount > iterationLimit)
        {
            return;
        }
        iterationCount++;

        // Check if opposing laser
        if (laserData.checkOpposing(x, y, heading, direction))
        {
            return;
        }

        // Make sure lasers list is initialized
        while (lasers.Count <= laserIndex)
        {
            lasers.Add(new List <laserNode>());
        }

        // Check if on same path as existing laser
        int[] indeces = laserData.checkOverlapping(x, y, strength, heading, direction, player);
        if (indeces != null)
        {
            lasers[indeces[0]][indeces[1]] = new laserNode(x, y, lasers[indeces[0]][indeces[1]].getStrength() + strength, heading, direction, Player.Shared, indx, subIndx);
        }
        else
        {
            // Add node to list for line rendering later
            laserData.insertNode(x, y, strength, heading, direction, player, indx, subIndx);
            lasers[indx].Add(new laserNode(x, y, strength, heading, direction, player, indx, subIndx));
        }

        // Determine next laser step
        int   newX; int newY; Direction newDir;
        float newStrength = strength - laserDecay;

        switch (heading)
        {
        case Direction.NE:
        {
            if (direction == Direction.Right)
            {
                newDir = Direction.Up;
                newX   = x; newY = y + 1;
            }
            else
            {
                newDir = Direction.Right;
                newX   = x + 1; newY = y;
            }

            laserSolver(newX, newY, newStrength, heading, newDir, player, indx, subIndx);
            break;
        }

        case Direction.NW:
        {
            if (direction == Direction.Left)
            {
                newDir = Direction.Up;
                newX   = x; newY = y + 1;
            }
            else
            {
                newDir = Direction.Left;
                newX   = x - 1; newY = y;
            }

            laserSolver(newX, newY, newStrength, heading, newDir, player, indx, subIndx);
            break;
        }

        case Direction.SE:
        {
            if (direction == Direction.Right)
            {
                newDir = Direction.Down;
                newX   = x; newY = y - 1;
            }
            else
            {
                newDir = Direction.Right;
                newX   = x + 1; newY = y;
            }

            laserSolver(newX, newY, newStrength, heading, newDir, player, indx, subIndx);
            break;
        }

        case Direction.SW:
        {
            if (direction == Direction.Left)
            {
                newDir = Direction.Down;
                newX   = x; newY = y - 1;
            }
            else
            {
                newDir = Direction.Left;
                newX   = x - 1; newY = y;
            }

            laserSolver(newX, newY, newStrength, heading, newDir, player, indx, subIndx);
            break;
        }
        }
    }