Ejemplo n.º 1
0
    public List<Tile> SweepingFire(Vector2 originLocation,int intern, int extrn)
    {
        List <Tile> Intern = new List<Tile>();
        List <Tile> Extern = new List<Tile>();
        Intern = TileHighlight.FindHighlight(map[(int)originLocation.x][(int)originLocation.y],intern,true,false);
        Extern = TileHighlight.FindHighlight(map[(int)originLocation.x][(int)originLocation.y],extrn,true,false);
        var _ring = Extern.Except(Intern);
        List <Tile> FinalRing = _ring.ToList();

        Vector2 vector = (MousePosition - originLocation).normalized;
        float angle = Mathf.Atan2(vector.y, vector.x)*Mathf.Rad2Deg; //if i need to debug and i want degrees
        float AngleRad = angle*Mathf.Deg2Rad;
        Vector2 lelPos = new Vector2 (Mathf.RoundToInt(originLocation.x+mapSize*2*Mathf.Cos(AngleRad)),Mathf.RoundToInt(originLocation.y+mapSize*2*Mathf.Sin (AngleRad)));

        BresenhamThingy line = new BresenhamThingy( new Vector3( originLocation.x, originLocation.y, 0 ), new Vector3( lelPos.x, lelPos.y, 0 ) );
        List<Vector2> myLine = new List<Vector2>();
        List<Tile> HitTiles = new List<Tile> ();
        int MouseDistance = (int)Vector2.Distance(MousePosition,originLocation);

        foreach( Vector2 point in line ) myLine.Add(point);
        for (int i = MouseDistance-1;i<MouseDistance+2;i++)
        if (MouseDistance != 0 && myLine[i]!=originLocation && myLine[i].x>-1 && myLine[i].y>-1 && myLine[i].x<mapSize && myLine[i].y<mapSize)
        HitTiles.Add(map[(int)myLine[i].x][(int)myLine[i].y]);
        var IntersectTiles = FinalRing.Intersect(HitTiles);
        List<Tile> Final = IntersectTiles.ToList();

            highlightTilesAt(originLocation,Color.white,999);
        foreach (Tile t in FinalRing)
            t.visual.transform.GetComponent<Renderer>().materials[0].color = Color.gray;
            foreach (Tile t in Final)
                t.visual.transform.GetComponent<Renderer>().materials[0].color = Color.red;
        return Final;
    }
Ejemplo n.º 2
0
    public List<Tile> WhiteDestructionBeam(TroopScript Caster)
    {
        Vector2 originLocation = Caster.gridPosition;
        List <TroopScript> Targets;
        Vector2 vector = (MousePosition - originLocation).normalized;
        float angle = Mathf.Atan2(vector.y, vector.x)*Mathf.Rad2Deg; //if i need to debug and i want degrees
        float AngleRad = angle*Mathf.Deg2Rad;
        Vector2 lelPos = new Vector2 (Mathf.RoundToInt(originLocation.x+mapSize*Mathf.Cos(AngleRad)),Mathf.RoundToInt(originLocation.y+mapSize*Mathf.Sin (AngleRad)));
        BresenhamThingy line = new BresenhamThingy( new Vector3( originLocation.x, originLocation.y, 0 ), new Vector3( lelPos.x, lelPos.y, 0 ) );
        List<Vector2> myLine = new List<Vector2>();
        List<Tile> HitTiles = new List<Tile> ();
        highlightTilesAt(originLocation,Color.white,999);
        if (lelPos.x ==originLocation.x || lelPos.y == originLocation.y){
            foreach( Vector2 point in line ) myLine.Add(point);

            for (int i = 0;i<mapSize;i++)
            if (myLine[i]!=originLocation && myLine[i].x>-1 && myLine[i].y>-1 && myLine[i].x<mapSize && myLine[i].y<mapSize)
                    HitTiles.Add(map[(int)myLine[i].x][(int)myLine[i].y]);}
        foreach (Tile t in HitTiles) t.visual.transform.GetComponent<Renderer>().materials[0].color = Color.magenta;

                    return HitTiles;
    }
Ejemplo n.º 3
0
    public List<TroopScript> SharpShoot(TroopScript Caster,TroopScript TargetBridge)
    {
        //(TroopScript Caster, TroopScript Target){
        List<TroopScript> targets= new List<TroopScript>();
        Vector2 myPos = Caster.gridPosition;
        //		Vector2 tarPos = Target.gridPosition;
        //		Vector2 myPos = new Vector2 (11,11);
        //		Vector2 tarPos = MousePosition;

        Vector2 tarPos = TargetBridge.gridPosition;
        Vector2 vector = (tarPos - myPos).normalized;
        float angle = Mathf.Atan2(vector.y, vector.x)*Mathf.Rad2Deg; //if i need to debug and i want degrees

        float AngleRad = angle*Mathf.Deg2Rad;
        Vector2 lelPos = new Vector2 (Mathf.RoundToInt(myPos.x+mapSize*2*Mathf.Cos(AngleRad)),Mathf.RoundToInt(myPos.y+mapSize*2*Mathf.Sin (AngleRad)));

        BresenhamThingy line = new BresenhamThingy( new Vector3( myPos.x, myPos.y, 0 ), new Vector3( lelPos.x, lelPos.y, 0 ) );

        List<Vector2> myLine = new List<Vector2>();
        List<Tile> HitTiles = new List<Tile> ();

        foreach( Vector2 point in line )
        {

            myLine.Add(point);
        }
        int xPos = Mathf.RoundToInt(Caster.gridPosition.x);
        int yPos = Mathf.RoundToInt(Caster.gridPosition.y);
        Tile _positionOfPlayer = map[xPos][yPos];
        List <Tile> MapAsAList = TileHighlight.FindHighlight(_positionOfPlayer,999);
        //	Debug.Log(myLine.Count+" "+(int)Vector2.Distance(myPos,tarPos));
        //	if ((int)Vector2.Distance(myPos,tarPos)>myLine.Count)
        for (int i = 0;i<(int)Vector2.Distance(myPos,tarPos)+5;i++)
        //for (int i = 0;i<23;i++)
            if (myLine[i]!=myPos && myLine[i].x>-1 && myLine[i].y>-1 && myLine[i].x<mapSize && myLine[i].y<mapSize)
            HitTiles.Add(map[(int)myLine[i].x][(int)myLine[i].y]);
        highlightTilesAt(myPos,Color.white,999);
        foreach (Tile t in HitTiles)
            t.visual.transform.GetComponent<Renderer>().materials[0].color = Color.red;

        for (int i=0;i<HitTiles.Count;i++)
            for (int j=0;j<players.Count;j++)
                if (players[j].gridPosition == HitTiles[i].gridPosition && players[j].Faction != Caster.Faction)
                    targets.Add(players[j]);

        //		BresenhamThingy Line =	BresenhamThingy(myPos,lelPos);
        //		foreach( Vector2 point in Line )
        //		{
        //			Debug.Log( "Point on line at 1f intervals: " + point );
        //		}
        return targets;
    }