Beispiel #1
0
    private bool CheckVertical(TileBehavior tile)
    {
        bool found = false;
        List <TileBehavior> markedList = new List <TileBehavior>();

        markedList.Add(tile);

        //if has neighbours, search
        if (tile.neighbours.yPosTile)
        {
            CheckUp(tile.neighbours.yPosTile, tile.piece, markedList);
        }
        if (tile.neighbours.yNegTile)
        {
            CheckDown(tile.neighbours.yNegTile, tile.piece, markedList);
        }

        //found enough to clear, add to checked list
        if (markedList.Count >= 3)
        {
            found = true;
            for (int i = 0; i < markedList.Count; i++)
            {
                if (!checkedTiles.Contains(markedList[i]))
                {
                    checkedTiles.Add(markedList[i]);
                }
            }
        }

        return(found);
    }
Beispiel #2
0
 public void PressAttackButton()
 {
     if (TileBehavior.selectedUnit != null && TileBehavior.selectedUnit.GetComponent <Character>().GetCanAttack())
     {
         TileBehavior.AttackSelection();
     }
 }
Beispiel #3
0
 public Tile(TileBehavior behavior, Texture2D image, Vector2 position, TileScript script)
 {
     this.Behavior = behavior;
     this.image    = image;
     this.Position = position;
     this.Script   = script;
 }
Beispiel #4
0
    //Mega Punch
    public override void Ability1()
    {
        //get target
        GameManager.actionInProcess = true;
        Debug.Log("Ability1");
        Debug.Log("Cooldown : " + currentCooldowns[0]);
        if (currentCooldowns[0] > 0)
        {
            GameManager.actionInProcess = false;
            return;
        }
        TileBehavior targetTile = GetTarget();

        if (targetTile == null)
        {
            return;
        }
        HitEnemy(targetTile, curStatArr[1]);

        //Make sound
        MakeAbilitySound(abilitySounds[0]);

        //activate cooldown
        updateCooldowns();
        currentCooldowns[0] += abilityCooldowns[0];
        Debug.Log("Cooldown After: " + currentCooldowns[0]);

        GameManager.actionInProcess = false;
    }
Beispiel #5
0
    //Head Smash
    public override void Ability4()
    {
        GameManager.actionInProcess = true;
        Debug.Log("Ability4");
        Debug.Log("Cooldown : " + currentCooldowns[3]);
        if (currentCooldowns[3] > 0)
        {
            GameManager.actionInProcess = false;
            return;
        }

        TileBehavior targetTile = GetTarget();

        if (targetTile == null)
        {
            return;
        }
        if (HitEnemy(targetTile, curStatArr[0] + curStatArr[1]))
        {
            TakeDamage(curStatArr[1] / 5);
            Debug.Log("Recoil: " + curStatArr[1] / 5);
        }

        //Make sound
        MakeAbilitySound(abilitySounds[3]);

        updateCooldowns();
        currentCooldowns[3] += abilityCooldowns[3];
        Debug.Log("Cooldown After: " + currentCooldowns[3]);
        GameManager.actionInProcess = false;
    }
Beispiel #6
0
    //Dragon Kick
    public override void Ability3()
    {
        GameManager.actionInProcess = true;
        Debug.Log("Ability3");
        Debug.Log("Cooldown : " + currentCooldowns[2]);
        if (currentCooldowns[2] > 0)
        {
            GameManager.actionInProcess = false;
            return;
        }
        //Need to fix
        TileBehavior targetTile = GetTarget();

        if (targetTile == null)
        {
            return;
        }
        TileBehavior LeftTile  = targetTile.Left;
        TileBehavior RightTile = targetTile.Right;

        HitEnemy(targetTile, curStatArr[1]);
        HitEnemy(LeftTile, curStatArr[1]);
        HitEnemy(RightTile, curStatArr[1]);

        //Make sound
        MakeAbilitySound(abilitySounds[2]);

        updateCooldowns();
        currentCooldowns[2] += abilityCooldowns[2];
        Debug.Log("Cooldown After: " + currentCooldowns[2]);
        GameManager.actionInProcess = false;
    }
Beispiel #7
0
    private bool CheckHorizontal(TileBehavior tile)
    {
        bool found = false;
        List <TileBehavior> markedList = new List <TileBehavior>();

        markedList.Add(tile);

        //if has neighbours, search
        if (tile.neighbours.xPosTile)
        {
            CheckRight(tile.neighbours.xPosTile, tile.piece, markedList);
        }
        if (tile.neighbours.xNegTile)
        {
            CheckLeft(tile.neighbours.xNegTile, tile.piece, markedList);
        }

        //if enough found, add to checked list
        if (markedList.Count >= 3)
        {
            found = true;
            for (int i = 0; i < markedList.Count; i++)
            {
                if (!checkedTiles.Contains(markedList[i]))
                {
                    checkedTiles.Add(markedList[i]);
                }
            }
        }

        return(found);
    }
    //map drawing function
    private void DrawMap()
    {
        //get map start pos
        float mapBaseX = position.width * sidePanelSizeRatio;
        float mapBaseZ = spaceFromTop;

        //for all contents in details list
        for (int i = 0; i < boardDetails.Count; i++)
        {
            //get a rect
            Rect      boardTile = new Rect(/*mapBaseX + */ (boardDetails[i].information.xPos * tileWidth) + (gapBetweenTiles * boardDetails[i].information.xPos), (mapBaseZ + boardDetails[i].information.zPos * tileHeight) + (gapBetweenTiles * boardDetails[i].information.zPos), tileWidth, tileHeight);
            Texture2D tex       = new Texture2D(1, 1);
            Color[]   color     = new Color[1];
            color[0] = ColourTexture(boardDetails[i].properties.type);
            //tex.SetPixel(0, 0, ColourTexture(boardDetails[i].properties.type));
            tex.SetPixels(color);
            tex.Apply();
            GUI.DrawTexture(boardTile, tex);

            //set event for if clicked on
            if (thingshappenin.type == EventType.MouseDown && boardTile.Contains(thingshappenin.mousePosition))
            {
                //pass this tile's information over to info panel
                tileXText = boardDetails[i].information.xPos.ToString();
                tileZText = boardDetails[i].information.zPos.ToString();
                tileType  = boardDetails[i].properties.type;

                //set current tile ref to this tile
                tile = boardDetails[i];

                //do event
                thingshappenin.Use();
            }
        }
    }
Beispiel #9
0
    //recursively search through list
    public bool CheckForSameInBoard(TileBehavior tileToCheck, int currentIndex)
    {
        //set up bool
        bool sameFound = false;

        //first, check to see if list empty
        if (boardDetails.Count > 0)
        {
            //see if current index tile is same as tile to check
            if (tileToCheck.CheckIfSame(boardDetails[currentIndex]))
            {
                //if so, then call true
                sameFound = true;
                return(sameFound);
            }
            else
            {
                //else, check that current index not last
                if (currentIndex != boardDetails.Count - 1)
                {
                    //increment current index
                    currentIndex++;
                    //call function again
                    sameFound = CheckForSameInBoard(tileToCheck, currentIndex);
                }
            }
        }


        return(sameFound);
    }
 void HighlightSummonableTiles()
 {
     if (highlightedTiles.Contains(gameObject))
     {
         return;
     }
     if (tileType != "nexus" && myUnit == null)
     {
         //Change to something else once we have the code/art
         HighlightCanMove();
     }
     highlightedTiles.Add(gameObject);
     Vector2[] directions = { Vector2.right, Vector2.left, Vector2.up, Vector2.down };
     foreach (Vector2 direction in directions)
     {
         RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, 1.0f);
         if (hit.collider != null)
         {
             TileBehavior otherTile = hit.transform.GetComponent <TileBehavior>();
             if (otherTile.tileType == "nexus" && tileType == "nexus" || tileType == "nexus")
             {
                 hit.transform.GetComponent <TileBehavior>().HighlightSummonableTiles();
             }
         }
     }
 }
Beispiel #11
0
    public override void ShipAction(TileBehavior tile)
    {
        TileBehavior[,] tiles = tile.ParentGrid.Tiles2D;

        Vector2Int centerTileId = tile.TileID;
        int        singleOffset = 1;

        //Center of the attack
        tile.AttackTile();

        Vector2Int[] ids =
        {
            //TOP
            new Vector2Int(centerTileId.x,                centerTileId.y + singleOffset),
            //BOT
            new Vector2Int(centerTileId.x,                centerTileId.y - singleOffset),
            //LEFT
            new Vector2Int(centerTileId.x + singleOffset, centerTileId.y),
            //RIGHT
            new Vector2Int(centerTileId.x - singleOffset, centerTileId.y)
        };

        //Attacks surrounding tiles
        foreach (var tileId in ids)
        {
            if (tileId.x >= 0 && tileId.x < tiles.GetLength(0) &&
                tileId.y >= 0 && tileId.y < tiles.GetLength(1))
            {
                tiles[tileId.x, tileId.y].AttackTile();
            }
        }
    }
Beispiel #12
0
 public Tile(TileBehavior behavior, Texture2D image, Vector2 position, TileScript script)
 {
     this.Behavior = behavior;
     this.image = image;
     this.Position = position;
     this.Script = script;
 }
Beispiel #13
0
    private void SetUpTiles()
    {
        this.tileBehaviors = new List <TileBehavior>();

        int i = 0;

        foreach (Tile t in this.tiles)
        {
            Canvas        canvas        = GameObject.FindObjectOfType <Canvas>();
            Vector3       canvasScale   = canvas.transform.localScale;
            GameObject    obj           = Resources.Load("Prefabs/TileContainer") as GameObject;
            GameObject    tileContainer = GameObject.Instantiate(obj, transform);
            RectTransform rt            = tileContainer.GetComponent <RectTransform>();
            //RectTransform ourRect = this.GetComponent<RectTransform>();
            //float width = Screen.width * ourRect.anchorMax.x;
            float height = rt.sizeDelta.y;
            //rt.sizeDelta = new Vector2(width, height);
            tileContainer.transform.localPosition = new Vector3(0, (height + 10) * i);
            tileContainer.transform.localScale    = Vector3.one;

            GameObject gameObj = new GameObject("Tile Behavior");
            gameObj.transform.SetParent(tileContainer.transform);
            gameObj.transform.localPosition = new Vector2(0, 0);
            gameObj.transform.localScale    = Vector3.one;
            i++;
            TileBehavior beh = gameObj.AddComponent <TileBehavior>();
            this.tileBehaviors.Add(beh);
            beh.SetUpWithGamePiece(t);
        }
    }
Beispiel #14
0
    public void OnTileClicked(TileBehavior tileClicked)
    {
        if (this.selectedAction == null)
        {
            if (this.prevTileClicked != null) //todo: && !this.Player.ActionExecuted.Started)
            {
                Point destination = tileClicked.Pos;
                this.EnqueueMovePath(destination);
            }
            else
            {
                this.prevTileClicked = tileClicked;
                StartCoroutine(this.RemoveClickedTileAfterDelay());
            }
            return;
        }

        if (highlightedTiles.Contains(tileClicked))
        {
            this.ActionExecutor.EnqueueAction(this.Player, this.selectedAction, this.targetTiles.ToArray());
        }

        this.Player.ActionMenu.IsVisible = false;

        this.selectedAction = null;
    }
Beispiel #15
0
    public static void ExecuteTileMovements()
    {
        //List<Tile> tiles = new List<Tile>();
        //failedMovements.Sort();
        failedMovements = failedMovements.OrderByDescending(v => v).Distinct().ToList();
        foreach (int failedMovement in failedMovements)
        {
            tilesToMove.RemoveAt(failedMovement);
            destinations.RemoveAt(failedMovement);
        }
        for (int i = 0; i < tilesToMove.Count; i++)
        {
            Tile tile = new Tile(tree.GetTile(tilesToMove[i]));
            tree.RemoveTile(tilesToMove[i]);
            if (tile.HasBehavior())
            {
                TileBehavior behavior = tileBehaviors[tilesToMove[i]];
                behavior.coordinate = destinations[i];
                tileBehaviors.Remove(tilesToMove[i]);
                tileBehaviors.Add(destinations[i], behavior);
            }
            tree.InsertTile(destinations[i], tile.ID(), tile.HasBehavior(), tile.SpriteIndex());
            worldRenderer.UpdateAtCoordinate(tilesToMove[i]);
            worldRenderer.UpdateAtCoordinate(destinations[i]);
        }

        tilesToMove.Clear();
        destinations.Clear();
        failedMovements.Clear();
    }
    //logic to add new tile to current map
    private void NewTileButtonLogic()
    {
        //check that map exists
        if (map)
        {
            //create a gameobject to hold the tile
            GameObject newTileObject = new GameObject("Tile");
            //attach the tile to the object
            TileBehavior createdTile = newTileObject.AddComponent <TileBehavior>();
            //assign values to new tile
            createdTile.position.xPos = newTileX;
            createdTile.position.yPos = newTileY;
            createdTile.value.type    = newTileType;
            //check that this tile does not already exist
            if (!map.CheckForSameInBoard(createdTile, 0))
            {
                //attach this new object to the maps object as child
                newTileObject.transform.parent = map.gameObject.transform;

                //add this new tile to the map
                map.AddTileToBoard(createdTile);

                //draw the map again
                GetMapDetails();
            }
            //if it does, destroy the object after comparison
            else
            {
                DestroyImmediate(newTileObject);
            }
        }
    }
Beispiel #17
0
    public void PressEndTurnButton()
    {
        if (currentPlayer == 1)
        {
            currentPlayer = 2;
        }
        else
        {
            currentPlayer = 1;
        }

        //For every character in Player 1, set can move and can attack.
        foreach (GameObject unit in player1Units)
        {
            unit.GetComponent <Character>().SetCanMove(true);
            unit.GetComponent <Character>().SetCanAttack(true);
        }
        //For every character in Player 2/Enemy, set can move and can attack.
        foreach (GameObject unit in player2Units)
        {
            unit.GetComponent <Character>().SetCanMove(true);
            unit.GetComponent <Character>().SetCanAttack(true);
        }
        //Reset selection state.
        if (TileBehavior.GetSelectionState() != null)
        {
            TileBehavior.selectedTile.GetComponent <TileBehavior>().SelectionStateToNull();
        }
        AddCTPObjectivePoints();
    }
Beispiel #18
0
    GameObject SpawnArrowTo(TileBehavior tile)
    {
        Quaternion rotation = Quaternion.identity;
        Point      diff     = tile.Pos - this.Pos;

        if (diff.X == 1 && diff.Y == 0)
        {
            rotation = Quaternion.AngleAxis(-90, Vector3.forward);
        }
        else if (diff.X == 0 && diff.Y == -1)
        {
            rotation = Quaternion.AngleAxis(-180, Vector3.forward);
        }
        else if (diff.X == -1 && diff.Y == 0)
        {
            rotation = Quaternion.AngleAxis(-270, Vector3.forward);
        }
        var arrowGo = (GameObject)Instantiate(this.ArrowPrefab, this.transform.position, rotation);

        arrowGo.transform.SetParent(this.transform);
        arrowGo.transform.localPosition += arrowGo.transform.up * 0.5f;

        this.arrows.Add(arrowGo);

        return(arrowGo);
    }
Beispiel #19
0
    static public void SwapAssociatedTiles(HiddenTileBehavior tileBack, HiddenTileBehavior otherTileBack)
    {
        // swap associated tiles
        GameObject tmp = tileBack.tileAssociated;

        tileBack.tileAssociated      = otherTileBack.tileAssociated;
        otherTileBack.tileAssociated = tmp;

        TileBehavior tile      = tileBack.tileAssociated.GetComponent <TileBehavior>();
        TileBehavior otherTile = otherTileBack.tileAssociated.GetComponent <TileBehavior>();

        // swap tiles positions
        Vector3 tempPos = tile.transform.position;

        tile.transform.position      = otherTile.transform.position;
        otherTile.transform.position = tempPos;

        // swap tiles indices
        int tmpIndex = tile.index;

        tile.index      = otherTile.index;
        otherTile.index = tmpIndex;

        // finally update cells and swap rotation
        int rotation      = tile.tileRotation;
        int otherRotation = otherTile.tileRotation;

        tile.GetComponent <TileBehaviorIHM>().goToDesiredOrientation(0);
        otherTile.GetComponent <TileBehaviorIHM>().goToDesiredOrientation(0);
        tile.updateTileCells();
        otherTile.updateTileCells();
        tile.GetComponent <TileBehaviorIHM>().goToDesiredOrientation(otherRotation);
        otherTile.GetComponent <TileBehaviorIHM>().goToDesiredOrientation(rotation);
    }
Beispiel #20
0
    void HighlightMoveableTiles(int moveEnergy, bool enemySelect = false)
    {
        // Don't do anything if you've run out of energy.
        if (moveEnergy < 0 || tileType == "wall")
        {
            return;
        }

        //Otherwise, hightlight yourself...
        if (myUnit == null)
        {
            HighlightCanMove(enemySelect);
        }
        else if (!myUnit.Equals(selectedUnit))
        {
            HighlightCanMoveCovered(enemySelect);
        }
        highlightedTiles.Add(gameObject);

        //...and all adjacent tiles (if they don't contain enemy units).

        Vector2[] directions = { Vector2.right, Vector2.left, Vector2.up, Vector2.down };
        foreach (Vector2 direction in directions)
        {
            RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, 1.0f);
            if (hit.collider != null)
            {
                TileBehavior otherTile = hit.transform.GetComponent <TileBehavior>();
                if (otherTile.myUnit == null || otherTile.myUnit.GetComponent <Character>().player == selectedUnit.GetComponent <Character>().player)
                {
                    hit.transform.GetComponent <TileBehavior>().HighlightMoveableTiles(moveEnergy - movementCost, enemySelect);
                }
            }
        }
    }
Beispiel #21
0
    //Dragon Kick
    public override void Ability3()
    {
        GameManager.actionInProcess = true;
        Debug.Log("Ability3");
        Debug.Log("Cooldown : " + currentCooldowns[2]);
        if (currentCooldowns[2] > 0)
        {
            GameManager.actionInProcess = false;
            return;
        }

        TileBehavior targetTile = GetTarget();

        if (targetTile != null && !HitEnemy(targetTile, curStatArr[1] + 2) && !targetTile.HasUnit() && targetTile.tileType != "wall")
        {
            Debug.Log("about to attack move");
            GetComponent <PlayerManager>().StartMoveDuringAttackAnimation();
            targetTile = GetTarget();
            HitEnemy(targetTile, curStatArr[1]);
        }

        updateCooldowns();
        currentCooldowns[2] += abilityCooldowns[2];
        Debug.Log("Cooldown After: " + currentCooldowns[2]);
        GameManager.actionInProcess = false;
    }
    void HighlightRangeAttack(int attackRange)
    {
        if (attackRange < 0)
        {
            return;
        }

        if (!moveableTiles.Contains(gameObject))
        {
            HighlightCanAttack();
            highlightedTiles.Add(gameObject);
        }

        Vector2[] directions = { Vector2.right, Vector2.left, Vector2.up, Vector2.down };
        foreach (Vector2 direction in directions)
        {
            RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, 1.0f);
            if (hit.collider != null)
            {
                TileBehavior otherTile = hit.transform.GetComponent <TileBehavior>();
                if (!moveableTiles.Contains(otherTile.gameObject) || !highlightedTiles.Contains(otherTile.gameObject))
                {
                    hit.transform.GetComponent <TileBehavior>().HighlightRangeAttack(attackRange - 1);
                }
            }
        }
    }
 //UserInput function checks swipeAngle(tan value for swipe) and determines isTurning and turningWay values
 //for the selected tiles.
 void UserInput(TileBehavior tile)
 {
     if (swipeAngle > -45 && swipeAngle <= 45)
     {
         //Right Swipe
         tile.turningWay = -1;
         tile.isTurning  = true;
     }
     else if (swipeAngle > 45 && swipeAngle <= 135)
     {
         //Up Swipe
         tile.turningWay = 1;
         tile.isTurning  = true;
     }
     else if (swipeAngle > 135 || swipeAngle <= -135)
     {
         //Left Swipe
         tile.turningWay = 1;
         tile.isTurning  = true;
     }
     else if (swipeAngle < -45 && swipeAngle >= -135)
     {
         //Down Swipe
         tile.turningWay = -1;
         tile.isTurning  = true;
     }
 }
Beispiel #24
0
 public void Initialize(Vector3 attributes, TileBehavior tile, PlayerController owner)
 {
     rend = GetComponentInChildren <Renderer>();
     SetAttributes(attributes);
     this.tile   = tile;
     this.posHex = tile.posHex;
     this.owner  = owner;
 }
 //MouseDown function first checks the Current State and if it is on move it gets the first touch position
 //and calls ClosestTiles function from TileBehavior Class.
 public void MouseDown(TileBehavior tile)
 {
     if (board.currentState == GameState.move)
     {
         firstTouchPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         tile.ClosestTiles();
     }
 }
Beispiel #26
0
    public void ShowHintMovementTo(TileBehavior to)
    {
        var arrowGo = SpawnArrowTo(to);
        var color   = this.HighlightColor;

        color.a = 0.75f;
        arrowGo.GetComponent <SpriteRenderer>().color = color;
    }
 //MouseUp function first checks the Current State and dontSelect bool. dontSelect bool is for odd behaviour
 //when ClosestTiles is calculated. If it is on move and dontSelect is false(means there is none odd behavior
 //it gets the final touch position and calls CalculateAngle function.
 public void MouseUp(TileBehavior tile)
 {
     if (!dontSelect && board.currentState == GameState.move)
     {
         finalTouchPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         CalculateAngle(tile);
     }
 }
Beispiel #28
0
    public Move(GameAction owner, MoveComponent moveComp, TileBehavior from, TileBehavior to)
        : base(owner)
    {
        this.Displaces = moveComp.Displace;

        this.To   = to;
        this.From = from;
    }
Beispiel #29
0
    IEnumerator MoveInDirection(string direction)
    {
        float tileSize = GetComponent <SpriteRenderer>().sprite.bounds.size.x;

        // Calculate the steps you need to take

        //Take that step!
        if (direction.Equals("up"))
        {
            myCharacter.transform.position += new Vector3(0, tileSize);
            TileBehavior upTile = myCharacter.occupiedTile.Up;
            if (upTile != null && upTile.tileType != WALL && !upTile.HasUnit())
            {
                myCharacter.occupiedTile.ClearUnit();
                myCharacter.occupiedTile = upTile;
                myCharacter.myDirection  = Character.Direction.UP;
            }
        }
        else if (direction.Equals("right"))
        {
            myCharacter.transform.position += new Vector3(tileSize, 0);
            TileBehavior rightTile = myCharacter.occupiedTile.Right;
            if (rightTile != null && rightTile.tileType != WALL && !rightTile.HasUnit())
            {
                myCharacter.occupiedTile.ClearUnit();
                myCharacter.occupiedTile = rightTile;
                myCharacter.myDirection  = Character.Direction.RIGHT;
            }
        }
        else if (direction.Equals("down"))
        {
            myCharacter.transform.position += new Vector3(0, -tileSize);
            TileBehavior downTile = myCharacter.occupiedTile.Down;
            if (downTile != null && downTile.tileType != WALL && !downTile.HasUnit())
            {
                myCharacter.occupiedTile.ClearUnit();
                myCharacter.occupiedTile = downTile;
                myCharacter.myDirection  = Character.Direction.DOWN;
            }
        }
        else if (direction.Equals("left"))
        {
            myCharacter.transform.position += new Vector3(-tileSize, 0);
            TileBehavior leftTile = myCharacter.occupiedTile.Left;
            if (leftTile != null && leftTile.tileType != WALL && !leftTile.HasUnit())
            {
                myCharacter.occupiedTile.ClearUnit();
                myCharacter.occupiedTile = leftTile;
                myCharacter.myDirection  = Character.Direction.LEFT;
            }
        }
        myCharacter.updateCooldowns();
        myCharacter.RecalculateDepth();
        myCharacter.StartBounceAnimation();
        yield return(new WaitForSeconds(stepDuration));

        myCharacter.occupiedTile.PlaceUnit(myCharacter);
    }
Beispiel #30
0
    private void SelectSingle(TileBehavior tile)
    {
        if (!selectedTiles.Contains(tile))
        {
            selectedTiles.Add(tile);
        }

        tile.OnSelect();
    }
Beispiel #31
0
    public void UpdateTileLookUp()
    {
        //Find all the tiles by using a tag.
        Tiles = GameObject.FindGameObjectsWithTag("Tile");

        //Instantiate a new Dictionary when the function is called.
        TileLookUp = new Dictionary<Vector2, TileData>();

        foreach(GameObject tile in Tiles)
        {
            tileBehavior = tile.GetComponent<TileBehavior>();
            // add all the tiles in the Tile list to the dictionary
            TileLookUp.Add(tileBehavior.TilePosition, tileBehavior.data);
        }
    }
Beispiel #32
0
 public void TileClicked(TileBehavior tile, int button) {
     if (disableUi_) {
         // ignore click while moving
         return;
     }
     DeactivateTiles();
     if (button == 0 && actionState_ == ActionState.MOVE) {
         MoveCharacterTo(tile);
         disableUi_ = true;
     } else if (button == 1) {
         tile.TogglePassable();
     }
     if (!disableUi_) {
         ActivateFrom(GetCurrentCharacter());
     }
 }
Beispiel #33
0
    /*
    void generateTiles(){
        tileArray = new TileBehavior[fieldSize,fieldSize];
        float tileSpacing = tilePrefab.GetComponent<MeshRenderer>().bounds.size.x;
        int position;
        for (int i = 0; i< fieldSize; i++)
        for(int j = 0; j< fieldSize; j++){
            position = (i*fieldSize + j);
            tileArray[i, j] = ((GameObject)Instantiate(tilePrefab, new Vector3(i*tileSpacing, 0, j*tileSpacing), Quaternion.identity)).GetComponent<TileBehavior>();
                tileArray[i, j].transform.parent = this.transform;
            tileArray[i,j].transform.Rotate(new Vector3(90,0,0));
            if (position%2 == 0)
                tileArray[i,j].GetComponent<MeshRenderer>().material.color = Color.grey;
            tileArray[i,j].GetComponent<TileBehavior>().X = i;
            tileArray[i,j].GetComponent<TileBehavior>().Z = j;
        }
    }
    */
    public void generateFromMap(Map map)
    {
        map.InitializeMap();

        fieldSizeX = map.Layout.width;
        fieldSizeZ = map.Layout.height;
        tileArray = new TileBehavior[fieldSizeX, fieldSizeZ];
        float tileSpacing = map.Tileset.Size;
        Debug.Log(fieldSizeX + "," + fieldSizeZ);
        int position;
        cameraFocus.SetCameraForMap(fieldSizeX, fieldSizeZ, tileSpacing);
        for (int i = 0; i < fieldSizeX; i++)
            for (int j = 0; j < fieldSizeZ; j++)
            {
                position = (i * 5 + j);
                TileType t = colorToTile[map.Layout.GetPixel(i, j)];

                tilePrefab = map.Tileset.TypeToTile[t];

                tileArray[i, j] = ((GameObject)Instantiate(tilePrefab, new Vector3(i * tileSpacing, 0, j * tileSpacing), Quaternion.identity)).GetComponent<TileBehavior>();
                tileArray[i, j].transform.parent = this.transform;
                tileArray[i, j].transform.Rotate(new Vector3(90, 0, 0));
                tileArray[i, j].Coords = new Coordinate(i, j);
                tileArray[i, j].TileType = t;

                if (t == TileType.SpawnpointCops)
                    copSpawn = TileArray[i, j];
                else if(t == TileType.SpawnpointThieves)
                    gangSpawn = TileArray[i, j];

                if (position % 2 == 0 && t == TileType.FloorIndoor)
                    tileArray[i, j].GetComponent<MeshRenderer>().material.color = Color.grey;
            }

        foreach (CommandPanel cp in PlayerRegisterRule.PlayerRegister.Values)
        {
            if (cp.Team == Alliance.Cops)
                cp.SpawnPlayerCharacter(copSpawn);
            else if (cp.Team == Alliance.Robbers)
                cp.SpawnPlayerCharacter(gangSpawn);
        }
    }
Beispiel #34
0
 // TODO: Add functionality!
 public void SpawnPlayerCharacter(TileBehavior spawnPos)
 {
     GameObject pc;
     if (character != null)
     {
         pc = GameObject.Instantiate(character.gameObject);
         pc.transform.position = new Vector3(spawnPos.transform.position.x, 0.125f, spawnPos.transform.position.z);
         pc.GetComponent<CharacterBehavior>().Coords = spawnPos.Coords;
         pc.GetComponent<CharacterBehavior>().Owner = playerName;
         CurrentUnit = pc.GetComponent<CharacterBehavior>();
         character = CurrentUnit;
     }
 }
Beispiel #35
0
    public void PathSelection(TileBehavior tile)
    {
        if (unit != null && tile.IsPathable)
            if (moveSelectEnabled)
            {
                // if the list is empty, set the start at where you're at, idiot
                if (queuedPath.Count == 0)
                {
                    RaycastHit hit = new RaycastHit();
                    Physics.Raycast(unit.transform.position, Vector3.down, out hit, 10f);
                    GameObject tileBelow = hit.collider.gameObject;
                    if (tileBelow.GetComponent<TileBehavior>() != null)
                    {
                        //Debug.Log("Below you is " + tileBelow.GetComponent<TileBehavior>().X + "," + tileBelow.GetComponent<TileBehavior>().Z);
                        TileBehavior tb = tileBelow.GetComponent<TileBehavior>();
                        queuedPath.Add(tb);
                    }
                }
                int currentPos = queuedPath.Count;
                // checks the distance between the selected tile indexes (moves are only valid if this number is one)
                Coordinate distance = queuedPath[currentPos - 1].Coords - tile.Coords;
                int dx = Mathf.Abs(distance.X);
                int dz = Mathf.Abs(distance.Z);
                //if you click on an already-existant tile, remove everything past there
                if (queuedPath.Contains(tile))
                {
                    int index = queuedPath.IndexOf(tile);
                    Debug.Log("Duplicate tile found at " + index + "/" + currentPos);
                    for (int i = queuedPath.Count - 1; i > index; i--)
                    {
                        Debug.Log("Removing index " + i + ":" + queuedPath[i].Coords.ToString());
                        queuedPath.RemoveAt(i);
                    }
                }
                else if ((((dx == 1 && dz == 0) || (dx == 0 && dz == 1))
                          && (dx + dz <= 1))
                          && queuedPath.Count - 1 < unit.Stats.movement)
                {
                    queuedPath.Add(tile);
                }

                foreach (TileBehavior tb in queuedPath)
                {
                    Debug.Log("Next Step: " + tb.Coords.ToString());
                }

                UpdateMovesLeft();
            }
    }
Beispiel #36
0
    private void MoveCharacterTo(TileBehavior tile) {
        var startTile = GetCurrentCharacter().Tile;
        var endTile = tile.Tile;
        Debug.Log(String.Format("Path from {0} to {1}", startTile.Location, endTile.Location));

        Func<Tile, Tile, double> distance = (x, y) => 1; // we expect it to be called only for adjacent tiles

        var path = PathFinding.FindPath(startTile, endTile, distance, Tile.Distance);
        if (path == null) {
            Debug.Log("Empty path");
            return;
        }
        
        var pathTiles = path.Reverse().ToList();
        GetCurrentCharacter().MoveTo(pathTiles, MoveEnded);
    }
Beispiel #37
0
        private List<TileBehavior> FindEmptyAdjacent(int x, int y, TileBehavior[] tiles, bool[] visited)
        {
            List<TileBehavior> res = new List<TileBehavior> ();
            int idx = y * grid.width + x;
            if (visited [idx])
                return res;
            visited [idx] = true;

            if (tiles [idx].Cell == null) {
                res.Add (tiles [idx]);
            } else {
                if (x > 0) {
                    res.AddRange (FindEmptyAdjacent (x - 1, y, tiles, visited));
                }
                if (x < grid.width - 1) {
                    res.AddRange (FindEmptyAdjacent (x + 1, y, tiles, visited));
                }
                if (y > 0) {
                    res.AddRange (FindEmptyAdjacent (x, y - 1, tiles, visited));
                }
                if (y < grid.height - 1) {
                    res.AddRange (FindEmptyAdjacent (x, y + 1, tiles, visited));
                }
            }
            return res;
        }