예제 #1
0
    public void Initialize(Grid <Tile> grid = null)
    {
        if (grid == null && string.IsNullOrEmpty(GridData))
        {
            return;
        }

        if (grid == null)
        {
            _grid = GridSerializer.Deserialize(GridData);
            if (_grid == null)
            {
                Debug.LogError("There was an error deserializing the grid data.");
            }
        }
        else
        {
            _grid    = grid;
            GridData = GridSerializer.Serialize(_grid);
        }

        GridWidth    = _grid.GetGrid().GetLength(0);
        GridHeight   = _grid.GetGrid().GetLength(1);
        GridCellSize = _grid.GetCellSize();
        GridOrigin   = _grid.GetOrigin();

        if (Instance != null && Instance != this)
        {
            Destroy(gameObject);
        }
        else
        {
            Instance = this;
        }
    }
예제 #2
0
    public List <BaseTile> OtherTilesToExplode(TileGridController grid)
    {
        List <BaseTile> toDestroy = new List <BaseTile>();

        Vector2[] positions;
        positions = new Vector2[8];

        Debug.Log("Area destruction around " + x + ", " + y);
        positions[0] = new Vector2(x - 1f, y - 1f);
        positions[1] = new Vector2(x, y - 1f);
        positions[2] = new Vector2(x + 1f, y - 1f);
        positions[3] = new Vector2(x - 1f, y);
        positions[4] = new Vector2(x + 1f, y);
        positions[5] = new Vector2(x - 1f, y + 1f);
        positions[6] = new Vector2(x, y + 1f);
        positions[7] = new Vector2(x + 1f, y + 1f);

        for (int i = 0; i < positions.Length; i++)
        {
            BaseTile baseTile = grid.FindBaseTileAtPosition(positions[i]);
            if (baseTile && !baseTile.isBeingDestroyed)
            {
                toDestroy.Add(baseTile);
            }
        }


        return(toDestroy);
    }
예제 #3
0
    public Resources Cost(TileGridController controller)
    {
        var typeCount = controller.typeCount(type) + 1;
        var floor     = (int)Math.Pow(10, (int)(typeCount / 5f));

        return(new Resources().Add(buildCost.items).Mul(typeCount * floor));
    }
예제 #4
0
    public Resources TickTile(TileGridController controller, CubeCoord pos, Upgrades upgrades, TileScript tile)
    {
        var buildingResources = upgrades.Calculate(new Resources());
        var modified          = globalUpgrades.Calculate(buildingResources);

        if (tile.Structure.type == StructureType.LUMBERJACK)
        {
            var neighborTiles = controller.GetNeighborTiles(pos);
            modified.Mul(ItemType.WOOD, neighborTiles.Count(t => t.GetComponent <TileScript>().Structure.type == StructureType.WOODS));
        }

        if (tile.Structure.type == StructureType.CHARCOAL_BURNER)
        {
            var neighborTiles = controller.GetNeighborTiles(pos);
            var cnt           = neighborTiles.Count(t => t.GetComponent <TileScript>().Structure.type == StructureType.CHARCOAL_BURNER) + 1;
            modified.Mul(ItemType.CHARCOAL, cnt);
        }

        if (modified.Items.Count > 0)
        {
            if (Global.Resources.Add(modified))
            {
                var floaty = tile.floaty(controller.worldUi.transform, modified, true, "");
                floaty.transform.position = Camera.main.WorldToScreenPoint(tile.transform.position);
            }
        }

        return(modified);
    }
예제 #5
0
    // Use this for initialization
    public virtual void Awake()
    {
        sndsource = GetComponent <AudioSource>();
        bonus     = 0;
        //adjacency = 1;
        doresistcalc     = true;
        dieAfterMove     = false;
        damagesources    = new List <Vector3>();
        damageresistance = 0;
        unitCanvas       = GetComponentInChildren <UnitCanvas>();
        animating        = false;
        Morale           = MaxMorale;

        unitCanvas.SetMaxMP(MaxMorale);
        unitCanvas.SetCurrentMP(MaxMorale);

        actions     = new List <Action>();
        movesLeft   = movesPerTurn;
        currentVect = Vector3.zero;
        rb          = GetComponent <Rigidbody2D>();
        steps       = new List <Vector3Int>();
        //position = Vector3Int.RoundToInt(transform.position - offset);
        gridController = transform.parent.gameObject.GetComponent <TileGridController>();
        //gridController.blockPosition()
        actions.Add(new Action("Move", MoveDistance, ActType.Movement, 0, -1, "", "", Color.white));
        actions.Add(new Action("Blow vuvuzela", 6, ActType.Cone, 6, 6, "EnemyUnit", "DOOT!", Color.white, 0, 4));
        actions.Add(new Action("Finger guns", 9, ActType.Targetted, 6, 0, "Unit", "Finger guns", Color.white, 0, 1));
        actions.Add(new Action("Glitterbomb", 6, ActType.Grenade, 10, 10, "", "Glitterbomb", Color.white, 0, 6));
        //actions.Add(new Action("Strike a pose", 0, ActType.Grenade, 10, 20));
        actions.Add(new Action("Bear hug", MoveDistance, ActType.Melee, 6, -1, "", "Bear hug", Color.cyan, 0, 0));
    }
예제 #6
0
    public List <BaseTile> OtherTilesToExplode(TileGridController grid)
    {
        List <BaseTile> toDestroy = new List <BaseTile>();

        List <Vector2> positions = new List <Vector2>();

        for (int i = 1; i < Constants.gridSizeHorizontal; i++)
        {
            float px = x - 1f * i;
            float py = y - 1f * i;
            if (LeftUp(px, py))
            {
                positions.Add(new Vector2(px, py));
            }
        }
        for (int i = 1; i < Constants.gridSizeHorizontal; i++)
        {
            float px = x + 1f * i;
            float py = y - 1f * i;
            if (RightUp(px, py))
            {
                positions.Add(new Vector2(px, py));
            }
        }
        for (int i = 1; i < Constants.gridSizeHorizontal; i++)
        {
            float px = x - 1f * i;
            float py = y + 1f * i;
            if (LeftDown(px, py))
            {
                positions.Add(new Vector2(px, py));
            }
        }
        for (int i = 1; i < Constants.gridSizeHorizontal; i++)
        {
            float px = x + 1f * i;
            float py = y + 1f * i;
            if (RightDown(px, py))
            {
                positions.Add(new Vector2(px, py));
            }
        }

        for (int i = 0; i < positions.Count; i++)
        {
            BaseTile baseTile = grid.FindBaseTileAtPosition(positions[i]);
            if (baseTile && !baseTile.isBeingDestroyed)
            {
                toDestroy.Add(baseTile);
            }
        }

        return(toDestroy);
    }
예제 #7
0
    void Start()
    {
        quitbutton     = 0;
        restartcounter = 0;
        difficulty     = 1;
//occupied.
        addnew       = true;
        recalcresist = true;
        won          = false;
        lost         = false;
        cam          = GameObject.FindGameObjectWithTag("MainCamera");
        newcampos    = cam.transform.position;
        camscript    = cam.GetComponent <Camera>();
        enemyid      = 0;
        playerturn   = false;
        //snaptoentity = false;
        actionMenu     = actMenu.GetComponent <ActionMenu>();
        validpath      = false;
        linesteps      = new List <Vector3Int>();
        attackarealine = new List <Vector3Int>();
        line           = GetComponent <LineRenderer>();
        gridController = transform.parent.gameObject.GetComponent <TileGridController>();

        srend       = GetComponent <SpriteRenderer>();
        newpos      = Vector3Int.zero;
        oldpos      = Vector3Int.zero;
        PlayerUnits = new List <Unit>();
        EnemyUnits  = new List <EnemyUnit>();
        foreach (GameObject obj in GameObject.FindGameObjectsWithTag("Unit"))
        {
            PlayerUnits.Add(obj.GetComponent <Unit>());
        }

        /*for (int i = 0; i < 4;i++)
         * {
         *  difficulty++;
         *  gridController.AddPod(difficulty);
         * }*/

        EnemyUnits.Clear();
        foreach (GameObject obj in GameObject.FindGameObjectsWithTag("EnemyUnit"))
        {
            EnemyUnits.Add(obj.GetComponent <EnemyUnit>());
            //EnemyUnits[EnemyUnits.Count - 1].movesLeft += 3;
        }
        firstupdate = true;
        //won = true;
    }
예제 #8
0
    public bool IsBuildAllowed(TileGridController controller, CubeCoord coord)
    {
        if (!buildable)
        {
            return(false);
        }
        var neighborTiles = controller.GetNeighborTiles(coord);

        if (limit)
        {
            if (limit.BuildLimited(neighborTiles))
            {
                return(false);
            }
        }

        return(true);
    }
예제 #9
0
    public bool CanBuildDeductCost(TileGridController controller, CubeCoord coord)
    {
        if (!buildable)
        {
            return(false);
        }
        if (!IsBuildAllowed(controller, coord))
        {
            return(false);
        }

        var cost = Cost(controller);

        if (Global.Resources.HasResources(cost))
        {
            Global.Resources.AddNoCheck(cost);
            return(true);
        }
        return(false);
    }
예제 #10
0
    private void GenerateGrid()
    {
        var grid = new GameObject("Grid");

        grid.transform.parent = _levelContainer.transform;

        _grid = new GridGenerator().Generate(LevelProfile.GridProfile);

        _gridController = grid.AddComponent <TileGridController>();
        _gridController.Initialize(_grid);
        _gridController.PrimaryHighlightPrefab   = LevelProfile.PrimaryHighlightPrefab;
        _gridController.SecondaryHighlightPrefab = LevelProfile.SecondaryHighlightPrefab;
        _gridController.TertiaryHighlightPrefab  = LevelProfile.TertiaryHighlightPrefab;;

        var tileGridView = grid.AddComponent <TileGridView>();

        tileGridView.GridController       = _gridController;
        tileGridView.TileInfos            = LevelProfile.GridProfile.TileInfos;
        tileGridView.LevelObjectivePrefab = LevelProfile.LevelObjectivePrefab;
        tileGridView.CreateGridMesh();
    }
예제 #11
0
    public List <BaseTile> OtherTilesToExplode(TileGridController grid)
    {
        List <BaseTile> toDestroy = new List <BaseTile>();

        List <Vector2> positions = new List <Vector2>();
        int            tries     = Mathf.Max(Constants.gridSizeHorizontal, Constants.gridSizeVertical);

        //Diagonal
        for (int i = 1; i < tries; i++)
        {
            float px = x - 1f * i;
            float py = y - 1f * i;
            if (LeftUp(px, py))
            {
                positions.Add(new Vector2(px, py));
            }
        }
        for (int i = 1; i < tries; i++)
        {
            float px = x + 1f * i;
            float py = y - 1f * i;
            if (RightUp(px, py))
            {
                positions.Add(new Vector2(px, py));
            }
        }
        for (int i = 1; i < tries; i++)
        {
            float px = x - 1f * i;
            float py = y + 1f * i;
            if (LeftDown(px, py))
            {
                positions.Add(new Vector2(px, py));
            }
        }
        for (int i = 1; i < tries; i++)
        {
            float px = x + 1f * i;
            float py = y + 1f * i;
            if (RightDown(px, py))
            {
                positions.Add(new Vector2(px, py));
            }
        }
        //Straight
        for (int i = 1; i < tries; i++)
        {
            float px = x - 1f * i;
            float py = y;
            if (Left(px, py))
            {
                positions.Add(new Vector2(px, py));
            }
        }
        for (int i = 1; i < tries; i++)
        {
            float px = x + 1f * i;
            float py = y;
            if (Right(px, py))
            {
                positions.Add(new Vector2(px, py));
            }
        }
        for (int i = 1; i < tries; i++)
        {
            float px = x;
            float py = y + 1f * i;
            if (Down(px, py))
            {
                positions.Add(new Vector2(px, py));
            }
        }
        for (int i = 1; i < tries; i++)
        {
            float px = x;
            float py = y + 1f * i;
            if (Up(px, py))
            {
                positions.Add(new Vector2(px, py));
            }
        }


        for (int i = 0; i < positions.Count; i++)
        {
            BaseTile baseTile = grid.FindBaseTileAtPosition(positions[i]);
            if (baseTile && !baseTile.isBeingDestroyed)
            {
                toDestroy.Add(baseTile);
            }
        }

        return(toDestroy);
    }
예제 #12
0
 // Start is called before the first frame update
 void Start()
 {
     InvokeRepeating(nameof(BuildingTick), 1f, 1f);
     _controller = GetComponentInParent <TileGridController>();
     _renderer   = GetComponentInChildren <Renderer>();
 }