示例#1
0
    public void moveAlongCurrentPath()
    {
        Debug.Log(currentPath[pathCounter]);
        transform.position = Vector2.MoveTowards(new Vector2(transform.position.x, transform.position.y), IsometricHelper.gridToGamePostion(currentPath[pathCounter]) + spriteOffset, spriteMoveSpeed * Time.deltaTime);
        Vector2 goalPosition = IsometricHelper.gridToGamePostion(currentPath[pathCounter]) + spriteOffset;

        if (Math.Abs(transform.position.x - goalPosition.x) < .1 && Math.Abs(transform.position.y - goalPosition.y) < .1)
        {
            if (pathCounter < currentPath.Count - 1)
            {
                pathCounter++;
            }
            else
            {
                isMoving    = false;
                position    = currentPath[pathCounter];
                pathCounter = 0;
                currentPath = new List <GridPosition>();
            }
        }
        if (checkForTrap(currentPath[pathCounter]))
        {
            isMoving    = false;
            position    = currentPath[pathCounter];
            pathCounter = 0;
            currentPath = new List <GridPosition>();
        }
    }
    public List <GridPosition> getPossibleActionTargets(GridPosition currentPos, Action action)
    {
        List <GridPosition> possibleTargets = new List <GridPosition>();

        foreach (WalkableArea wa in levelController.walkableArea)
        {
            //TODO account for elevation difference
            if (IsometricHelper.distanceBetweenGridPositions(wa.position, currentPos) <= action.range)
            {
                if (getObjectAtPosition(wa.position) == null)
                {
                    possibleTargets.Add(wa.position);
                }
                else if (wa.position.Equals(currentPos) && action.canTargetSelf)
                {
                    possibleTargets.Add(wa.position);
                }
                else if (!wa.position.Equals(currentPos) && action.canTargetUnit)
                {
                    possibleTargets.Add(wa.position);
                }
            }
        }

        return(possibleTargets);
    }
示例#3
0
    public void instantiateUnitGroups()
    {
        UnitGroup playerGroup = battleData.playerGroup;
        UnitGroup enemyGroup  = battleData.enemyGroup;

        foreach (UnitPosition up in playerGroup.unitList)
        {
            GridPosition unitPos = IsometricHelper.battleCoordToPostion(up.position, true);
            Debug.Log("Position " + unitPos.x + ", " + unitPos.y);
            GameObject go = (GameObject)Instantiate(Resources.Load("Monk"));
            go.transform.SetParent(GameObject.Find("Player Units").transform);
            go.transform.position = IsometricHelper.gridToGamePostion(unitPos);
            go.GetComponent <SpriteRenderer>().sortingOrder = IsometricHelper.getTileSortingOrder(unitPos);
            go.name = up.unit.unitName;
            go.GetComponent <CombatUnitController>().facing = Facing.Back;
        }
        foreach (UnitPosition up in enemyGroup.unitList)
        {
            GridPosition unitPos = IsometricHelper.battleCoordToPostion(up.position, false);
            Debug.Log("Position " + (int)unitPos.x + ", " + (int)unitPos.y);
            GameObject go = (GameObject)Instantiate(Resources.Load("Monk"));
            go.transform.SetParent(GameObject.Find("Enemy Units").transform);
            go.transform.position = IsometricHelper.gridToGamePostion(unitPos);
            go.GetComponent <SpriteRenderer>().sortingOrder = IsometricHelper.getTileSortingOrder(unitPos);
            go.name = up.unit.unitName;
            go.GetComponent <CombatUnitController>().facing = Facing.Forward;
        }
    }
    private GameObject getClosestTarget()
    {
        GameObject playerUnits = GameObject.Find("Player Units");
        GameObject closest     = null;

        if (playerUnits != null)
        {
            int closestDistance = 99;
            foreach (Transform unit in playerUnits.transform)
            {
                //TODO account for environment targets
                if (unit.gameObject.tag.Equals("Player Unit"))
                {
                    if (unit.gameObject.activeSelf)
                    {
                        if (closestTarget == null)
                        {
                            closest         = unit.gameObject;
                            closestDistance = IsometricHelper.distanceBetweenGridPositions(position, unit.gameObject.GetComponent <UnitController>().position);
                        }
                        else
                        {
                            int tempDistance = IsometricHelper.distanceBetweenGridPositions(position, unit.gameObject.GetComponent <UnitController>().position);
                            if (tempDistance < closestDistance)
                            {
                                closest = unit.gameObject;
                            }
                        }
                    }
                }
            }
        }
        return(closest);
    }
    public void initWall(Build wall)
    {
        wallPrefab.GetComponent <WallData>().position = wall.destination;
        GameObject wallObject = Instantiate(wallPrefab, IsometricHelper.gridToGamePostion(wall.destination), Quaternion.identity);

        wallObject.transform.SetParent(actionObjectParent.transform);
    }
    /**
     *
     *
     */
    public void updateCursor()
    {
        LevelData levelData = levelController.levelData;
        MapTile   mt        = levelData.getMapTileFromXY(cursorPosition);

        cursor.transform.position = IsometricHelper.gridToGamePostion(mt.position);
    }
示例#7
0
    private void InstantiateMovesDisplay(List <GridPosition> moves)
    {
        int count = 0;

        foreach (GridPosition pos in moves)
        {
            count++;
            GameObject go        = null;
            UnitGroup  unitGroup = unitData.getUnitAt(pos);
            if (unitGroup == null)
            {
                go = (GameObject)Instantiate(Resources.Load("Possible Move"));
            }
            else
            {
                if (unitGroup.isEnemy)
                {
                    go = (GameObject)Instantiate(Resources.Load("Enemy Present"));
                }
                else
                {
                    go = (GameObject)Instantiate(Resources.Load("Possible Move"));
                }
            }
            go.transform.SetParent(movesContainer.transform);
            go.transform.position = IsometricHelper.gridToGamePostion(pos);
            go.GetComponent <SpriteRenderer>().sortingOrder = IsometricHelper.getTileSortingOrder(pos);
            go.name = "Move " + count;
        }
    }
    /**
     *
     *
     */
    public void updateCursor()
    {
        LevelData levelData = GameObject.Find("Level Editor Controller").GetComponent <LevelEditorController>().levelData;
        MapTile   mt        = levelData.getMapTileFromXY(cursorPosition);

        cursor.transform.position = IsometricHelper.gridToGamePostion(mt.position);
    }
    private void MakeMove()
    {
        Vector2 _movementTarget = Vector2.zero;

        switch (facing)
        {
        case Facing.Down:
            _movementTarget = transform.position + IsometricHelper.getMovementVector(facing);
            break;

        case Facing.Up:
            _movementTarget = transform.position + IsometricHelper.getMovementVector(facing);
            break;

        case Facing.Left:
            _movementTarget = transform.position + IsometricHelper.getMovementVector(facing);
            break;

        case Facing.Right:
            _movementTarget = transform.position + IsometricHelper.getMovementVector(facing);
            break;
        }
        Debug.Log("Enemy Move: " + _movementTarget + "Facing " + facing);
        if (levelData.isMoveValid(_movementTarget))
        {
            movementTarget = _movementTarget;
        }
        else
        {
            FlipAndMove();
        }
    }
    /**
     *
     *
     */
    public void updateCursor()
    {
        LevelData levelData = GameObject.Find("Level Controller").GetComponent <LevelController>().levelData;
        MapTile   mt        = levelData.getMapTileFromXY(cursorX, cursorY);

        cursor.transform.position = IsometricHelper.coordXYToPostion(cursorX, cursorY, mt.elevation);
    }
    public void initTrap(Trap trap)
    {
        trapPrefab.GetComponent <TrapData>().position = trap.destination;
        trapPrefab.GetComponent <TrapData>().damage   = trap.damage;
        GameObject trapObject = Instantiate(trapPrefab, IsometricHelper.gridToGamePostion(trap.destination), Quaternion.identity);

        trapObject.transform.SetParent(actionObjectParent.transform);
    }
示例#12
0
 void Update()
 {
     transform.position = IsometricHelper.gridToGamePostion(position) + spriteOffset;
     if (health <= 0)
     {
         Destroy(gameObject);
     }
 }
示例#13
0
    public void createTileFromTileSave(TileSave ts)
    {
        GridPosition pos = new GridPosition(ts.position.x, ts.position.y, ts.position.elevation);
        GameObject   go  = (GameObject)Instantiate(Resources.Load("Tile"));

        go.name = "x" + pos.x + "y" + pos.y;
        go.transform.position = IsometricHelper.gridToGamePostion(pos);
        go.GetComponent <SpriteRenderer>().sortingOrder = IsometricHelper.getTileSortingOrder(pos);
        go.transform.SetParent(GameObject.Find("Tiles").transform);
    }
示例#14
0
    public List <GridPosition> getBestPath(GridPosition start, GridPosition goal, int maxMovement, int maxJump)
    {
        List <GridPosition> path = new List <GridPosition>();
        int closestDistace       = 999;

        for (int i = 0; i < maxMovement; i++)
        {
            GridPosition up    = getGridPositionFromCoord(0, 1);
            GridPosition left  = getGridPositionFromCoord(-1, 0);
            GridPosition right = getGridPositionFromCoord(1, 0);
            GridPosition down  = getGridPositionFromCoord(0, -1);

            if (!up.Equals(new GridPosition(0, 0)))
            {
                int tempDistance = IsometricHelper.distanceBetweenGridPositions(up, goal);
                if (tempDistance < closestDistace)
                {
                    closestDistace = tempDistance;
                    path[i]        = up;
                }
            }
            if (!left.Equals(new GridPosition(0, 0)))
            {
                int tempDistance = IsometricHelper.distanceBetweenGridPositions(left, goal);
                if (tempDistance < closestDistace)
                {
                    closestDistace = tempDistance;
                    path[i]        = left;
                }
            }
            if (!right.Equals(new GridPosition(0, 0)))
            {
                int tempDistance = IsometricHelper.distanceBetweenGridPositions(right, goal);
                if (tempDistance < closestDistace)
                {
                    closestDistace = tempDistance;
                    path[i]        = right;
                }
            }
            if (!down.Equals(new GridPosition(0, 0)))
            {
                int tempDistance = IsometricHelper.distanceBetweenGridPositions(down, goal);
                if (tempDistance < closestDistace)
                {
                    closestDistace = tempDistance;
                    path[i]        = down;
                }
            }
        }

        return(path);
    }
示例#15
0
    private void ExportLevelMap()
    {
        int count = 0;

        foreach (MapTile mt in levelData.map)
        {
            count++;
            GameObject go = (GameObject)Instantiate(Resources.Load("Grass Tile"));
            go.transform.SetParent(GameObject.Find("Tiles").transform);
            go.transform.position = IsometricHelper.gridToGamePostion(mt.position);
            go.GetComponent <SpriteRenderer>().sortingOrder = IsometricHelper.getTileSortingOrder(mt.position);
            go.name = "Tile " + count;
        }
    }
示例#16
0
    private void InstantiateTargetsDisplay(List <GridPosition> targets)
    {
        int count = 0;

        foreach (GridPosition pos in targets)
        {
            count++;
            GameObject go = (GameObject)Instantiate(Resources.Load("Possible Move"));
            go.transform.SetParent(targetsContainer.transform);
            go.transform.position = IsometricHelper.gridToGamePostion(pos);
            go.GetComponent <SpriteRenderer>().sortingOrder = IsometricHelper.getTileSortingOrder(pos);
            go.name = "Target " + count;
        }
    }
示例#17
0
 protected override void doUpdateTasks()
 {
     base.doUpdateTasks();
     animator.SetInteger("Facing", (int)facing);
     checkIfDefeated();
     if (!isBeingPlacing && !isMoving)
     {
         transform.position = IsometricHelper.gridToGamePostion(position) + spriteOffset;
     }
     else if (isMoving)
     {
         moveAlongCurrentPath();
     }
 }
    // Update is called once per frame
    void Update()
    {
        float   _horizontal = Input.GetAxis("Horizontal");
        float   _vertical   = Input.GetAxis("Vertical");
        Vector2 movement    = Vector2.zero;

        if (!isMoving)
        {
            bool    _attemptMove    = false;
            Vector3 _movementTarget = Vector3.zero;
            if (_horizontal > 0)
            {
                facing          = Facing.Right;
                _movementTarget = transform.position + IsometricHelper.getMovementVector(facing);
                _attemptMove    = true;
            }
            else if (_horizontal < 0)
            {
                facing          = Facing.Left;
                _movementTarget = transform.position + IsometricHelper.getMovementVector(facing);
                _attemptMove    = true;
            }
            else if (_vertical > 0)
            {
                facing          = Facing.Up;
                _movementTarget = transform.position + IsometricHelper.getMovementVector(facing);
                _attemptMove    = true;
            }
            else if (_vertical < 0)
            {
                facing          = Facing.Down;
                _movementTarget = transform.position + IsometricHelper.getMovementVector(facing);
                _attemptMove    = true;
            }

            if (_attemptMove)
            {
                if (levelData.isMoveValid(_movementTarget))
                {
                    StartCoroutine(TakeTurn(_movementTarget));
                }
            }
        }


        float step = transitionSpeed * Time.deltaTime;

        transform.position = Vector2.MoveTowards(transform.position, movementTarget, step);
    }
    private GameObject getActionTarget(Action action)
    {
        GameObject target = null;

        if (closestTarget != null)
        {
            GridPosition unitPosition = closestTarget.GetComponent <UnitController>().position;
            int          distance     = IsometricHelper.distanceBetweenGridPositions(unitPosition, position);
            if (distance <= action.range)
            {
                target = closestTarget;
            }
        }
        return(target);
    }
示例#20
0
    // Update is called once per frame
    void Update()
    {
        int sortingOrder = IsometricHelper.getTileSortingOrder(position);

        GetComponent <SpriteRenderer>().sortingOrder        = sortingOrder;
        shadow.GetComponent <SpriteRenderer>().sortingOrder = sortingOrder - 1;
        if (!placingUnits)
        {
            foreach (Transform spawn in transform)
            {
                if (spawn.gameObject.tag.Equals("Spawn Point"))
                {
                    spawn.gameObject.SetActive(false);
                }
            }
        }
    }
    public List <GridPosition> getPossibleMovement(GridPosition currentPos, int maxMovement)
    {
        Debug.Log(currentPos + ", " + maxMovement);
        List <GridPosition> possibleMoves = new List <GridPosition>();

        foreach (WalkableArea wa in levelController.walkableArea)
        {
            //TODO account for elevation difference
            if (IsometricHelper.distanceBetweenGridPositions(wa.position, currentPos) <= maxMovement &&
                getObjectAtPosition(wa.position) == null)
            {
                possibleMoves.Add(wa.position);
            }
        }

        return(possibleMoves);
    }
    public List <GridPosition> getPossibleActionTargets(GridPosition currentPos, Action action)
    {
        Debug.Log(currentPos + ", " + action);
        List <GridPosition> possibleTargets = new List <GridPosition>();

        foreach (WalkableArea wa in levelController.walkableArea)
        {
            //TODO account for elevation difference
            if (IsometricHelper.distanceBetweenGridPositions(wa.position, currentPos) <= action.range &&
                getObjectAtPosition(wa.position) == null)
            {
                possibleTargets.Add(wa.position);
            }
        }

        return(possibleTargets);
    }
示例#23
0
 public void populateMap()
 {
     for (int i = 0; i < maxX; i++)
     {
         for (int j = 0; j < maxY; j++)
         {
             GridPosition pos = new GridPosition(i, j, 0);
             GameObject   go  = (GameObject)Instantiate(Resources.Load("Walkable Position"));
             go.name = "x" + i + "y" + j;
             go.GetComponent <SpriteRenderer>().enabled = false;
             go.transform.position = IsometricHelper.gridToGamePostion(pos);
             go.GetComponent <WalkableArea>().position = pos;
             walkableArea.Add(go.GetComponent <WalkableArea>());
             go.transform.SetParent(walkablePositions.transform);
         }
     }
 }
示例#24
0
    public List <GridPosition> getPossibleMovement(GridPosition currentPos, int maxMovement)
    {
        List <GridPosition> possibleMoves = new List <GridPosition>();

        foreach (MapTile mt in levelData.map)
        {
            //TODO account for elevation difference
            if (mt.safeToStand &&
                IsometricHelper.distanceBetweenGridPositions(mt.position, currentPos) <= maxMovement &&
                (unitData.getUnitAt(mt.position) == null || unitData.getUnitAt(mt.position).isEnemy))
            {
                possibleMoves.Add(mt.position);
            }
        }

        return(possibleMoves);
    }
示例#25
0
    public void UpdateLevelMap()
    {
        foreach (Transform child in GameObject.Find("Tiles").transform)
        {
            Destroy(child.gameObject);
        }
        int count = 0;

        foreach (MapTile mt in levelData.map)
        {
            count++;
            GameObject go = (GameObject)Instantiate(Resources.Load("Pixel Tile"));
            go.transform.SetParent(GameObject.Find("Tiles").transform);
            go.transform.position = IsometricHelper.gridToGamePostion(mt.position);
            go.GetComponent <SpriteRenderer>().sortingOrder = IsometricHelper.getTileSortingOrder(mt.position);
            go.name = "Tile " + count;
        }
    }
示例#26
0
    private void InstantiateLevelMap()
    {
        int count = 0;

        foreach (MapTile mt in battleData.battleMapData.map)
        {
            count++;
            GameObject go = (GameObject)Instantiate(Resources.Load("Grass Tile"));
            if (mt.position.x < 4 && mt.position.y < 3)
            {
                go.transform.SetParent(GameObject.Find("Player Tiles").transform);
            }
            else
            {
                go.transform.SetParent(GameObject.Find("Enemy Tiles").transform);
            }
            go.transform.position = IsometricHelper.gridToGamePostion(mt.position);
            go.GetComponent <SpriteRenderer>().sortingOrder = IsometricHelper.getTileSortingOrder(mt.position);
            go.name = "Tile " + count;
        }
    }
    private List <GridPosition> getMovePath()
    {
        List <GridPosition> movePath = new List <GridPosition>();

        if (closestTarget != null)
        {
            GridPosition unitPosition    = closestTarget.GetComponent <UnitController>().position;
            int          closestDistance = 99;
            foreach (List <GridPosition> path in possiblePaths)
            {
                int tempDistance = IsometricHelper.distanceBetweenGridPositions(unitPosition, path[path.Count - 1]);
                Debug.Log(tempDistance);
                if (tempDistance < closestDistance)
                {
                    movePath        = path;
                    closestDistance = tempDistance;
                }
            }
        }

        return(movePath);
    }
示例#28
0
 void Update()
 {
     transform.position = IsometricHelper.gridToGamePostion(position) + spriteOffset;
 }
    public void PopulateLevelFromFile()
    {
        if (!hasPopulated)
        {
            if (csvFile != null)
            {
                int y = 0;
                _lines = Regex.Split(csvFile.text, "\n");
                foreach (string _line in _lines)
                {
                    int      x      = 0;
                    string[] _tiles = _line.Split(',');

                    foreach (string _tile in _tiles)
                    {
                        if (_tile != null && !_tile.Equals(""))
                        {
                            GameObject go = InitGameObjectFromKey(_tile);

                            if (go.tag.Equals("Enemy"))
                            {
                                go.transform.position = IsometricHelper.gridToGamePostionUnit(x, y);
                                go.GetComponent <SpriteRenderer>().sortingOrder = IsometricHelper.getTileSortingOrder(x, y);
                                GameObject floor = Instantiate(baseTile);
                                floor.transform.position = IsometricHelper.gridToGamePostionTile(x, y);
                                floor.GetComponent <SpriteRenderer>().sortingOrder = IsometricHelper.getTileSortingOrder(x, y);
                                floor.transform.SetParent(tiles.transform);
                                string name = floor.name.Replace("(Clone)", "");
                                floor.name = name;
                                go.transform.SetParent(hazards.transform);
                            }
                            else
                            {
                                go.transform.SetParent(tiles.transform);
                                go.transform.position = IsometricHelper.gridToGamePostionTile(x, y);
                                go.GetComponent <SpriteRenderer>().sortingOrder = IsometricHelper.getTileSortingOrder(x, y);
                            }
                            if (_tile.Contains("enter"))
                            {
                                GameObject _player = Instantiate(player);
                                string     name    = _player.name.Replace("(Clone)", "");
                                _player.name = name;
                                _player.transform.position = IsometricHelper.gridToGamePostionUnit(x, y);
                                _player.GetComponent <SpriteRenderer>().sortingOrder = IsometricHelper.getTileSortingOrder(x, y);
                            }
                        }
                        else if (_tile.Equals(""))
                        {
                            GameObject floor = Instantiate(baseTile, IsometricHelper.gridToGamePostionTile(x, y), Quaternion.identity);
                            floor.GetComponent <SpriteRenderer>().sortingOrder = IsometricHelper.getTileSortingOrder(x, y);
                            floor.transform.SetParent(tiles.transform);
                            string name = floor.name.Replace("(Clone)", "");
                            floor.name = name;
                        }
                        x++;
                    }
                    y++;
                }
                hasPopulated = true;
            }
        }
    }
 protected void Update()
 {
     animator.SetInteger("Facing", (int)facing);
     updateIfDefeated();
     transform.position = IsometricHelper.gridToGamePostion(position) + spriteOffset;
 }