void OnCollisionEnter2D(Collision2D collision) { if (radius == 0) { GameObject go = TransformUtility.GetTopParent(collision.gameObject); Gridlike.Grid grid = go.GetComponent <Gridlike.Grid> (); if (grid != null) { int x; int y; Gridlike.GridUtility.GetClosestNonEmptyTile(grid, transform.position, out x, out y); if (grid != null) { GSGrid gsGrid = grid.GetComponent <GSGrid> (); gsGrid.Damage(character, x, y, damage, transform.position); } } } else { GridUtility.ExplodeInAllGrid(character, transform.position, radius, damage); } StartCoroutine(DestroyAnimation()); }
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); } } }
public static void ExplodeInAllGrid(GSCharacter character, Vector2 position, int radius, int damage) { foreach (Gridlike.Grid grid in Gridlike.Grid.GetAllGrids()) { GSGrid wrapper = grid.GetComponent <GSGrid> (); if (wrapper != null) { wrapper.Explosion(character, position, radius, damage); } else { Debug.LogWarning("Grid has no GSGrid"); } } }
void TryPickaxe(Vector2 position) { if (Time.time - lastPickaxe > cooldown && Vector2.Distance((Vector2)transform.position, position) < radius) { Gridlike.Grid grid; int x; int y; Gridlike.GridUtility.GetAnyNonEmptyTile(position, out grid, out x, out y); if (grid != null) { lastPickaxe = Time.time; GSGrid gsGrid = grid.GetComponent <GSGrid> (); gsGrid.Damage(character, x, y, damage, position); } } }