Пример #1
0
        void TryPlace(Vector2 position, int id)
        {
            if (Vector2.Distance(transform.position, position) < radius &&
                GSConsts.TileExists(id) &&
                character.GetCubeCount() >= GSConsts.tiles[id].cubeCost)
            {
                Gridlike.Grid grid;
                int           x;
                int           y;

                if (atlas [id].tileGO != null)
                {
                    GSTileBehaviour behaviour = atlas [id].tileGO.GetComponent <GSTileBehaviour> ();

                    Gridlike.GridUtility.GetEmptyInAreaOverBlock(position, behaviour.width, behaviour.height, out grid, out x, out y);
                }
                else
                {
                    Gridlike.GridUtility.GetEmptyNextToBlock(position, out grid, out x, out y);
                }

                if (grid != null)
                {
                    character.ConsumeCubes(GSConsts.tiles[id].cubeCost);
                    GSGrid gsGrid = grid.GetComponent <GSGrid> ();
                    gsGrid.Place(x, y, id);
                }
            }
        }
Пример #2
0
        public void Damage(GSCharacter character, int x, int y, int damage, Vector2 position)
        {
            Tile tile = grid.Get(x, y);

            if (tile != null)
            {
                GSTileBehaviour behaviour = grid.GetTileComponent(x, y) as GSTileBehaviour;
                int             id        = tile.id;
                int             HP        = (int)tile.state1;

                if (behaviour != null)
                {
                    id = behaviour.tile.id;
                    x  = behaviour.x;
                    y  = behaviour.y;

                    HP = (int)grid.Get(x, y).state1;
                }

                if (GSConsts.TileExists(id))
                {
                    int hpLost;

                    if (HP + damage >= GSConsts.tiles [id].HP)
                    {
                        hpLost = Mathf.Min(damage, GSConsts.tiles [id].HP - HP);
                        grid.Clear(x, y);
                    }
                    else
                    {
                        hpLost = damage;
                        grid.SetState(x, y, HP + damage, 0, 0);
                    }

                    if (position == Vector2.zero)
                    {
                        position = grid.TileCenterInWorld(x, y);
                    }

                    CubeParticle.CreateParticles(position, character, Mathf.CeilToInt(hpLost * GSConsts.tiles [id].cubePerHP));
                }
                else
                {
                    grid.Clear(x, y);
                }
            }
        }