/* * Add operation on all objects in sector to a render update queue */ public void ScheduleUpdateOnSectorObjects(RenderObjectUpdateOperations operation, WorldSector sector) { for (int x = sector.lower_boundary_x; x < sector.upper_boundary_x; ++x) { for (int y = sector.lower_boundary_y; y < sector.upper_boundary_y; ++y) { GTile tile = GameData.GData.getTile(new Vector2(x, y)); // schedule structures for (int i = 0; i < tile.Contained_Objects.structures.all.count(); ++i) { ScheduleObjectUpdate(operation, tile.Contained_Objects.structures.all.getObjectAt(i)); } // schedule items for (int i = 0; i < tile.Contained_Objects.items.all.count(); ++i) { ScheduleObjectUpdate(operation, tile.Contained_Objects.items.all.getObjectAt(i)); } } } // schedule actors for (int i = 0; i < sector.Contained_Objects.actors.all.count(); ++i) { ScheduleObjectUpdate(operation, sector.Contained_Objects.actors.all.getObjectAt(i)); } }
public override void setPosition(GTile tile, Vector2 offset) { removeFromTile (); if (placeAtPoint (tile.getCenter (offset))) { addToTile (tile); } }
public void destroyAllHoveringPanels() { for (int i = 0; i < renderedSectors.Count; ++i) { for (int x = renderedSectors[i].lower_boundary_x; x < renderedSectors[i].upper_boundary_x; ++x) { for (int y = renderedSectors[i].lower_boundary_y; y < renderedSectors[i].upper_boundary_y; ++y) { GTile tile = GameData.GData.getTile(new Vector2(x, y)); for (int k = 0; k < tile.Contained_Objects.structures.all.count(); ++k) { UIManager.UI.destroySHP(tile.Contained_Objects.structures.all.getObjectAt(k).renderedGameObject); } for (int k = 0; k < tile.Contained_Objects.items.all.count(); ++k) { UIManager.UI.destroySHP(tile.Contained_Objects.items.all.getObjectAt(k).renderedGameObject); } } } for (int j = 0; j < renderedSectors[i].Contained_Objects.actors.all.count(); ++j) { UIManager.UI.destroySHP(renderedSectors[i].Contained_Objects.actors.all.getObjectAt(j).renderedGameObject); } } }
private static void _write(GTile tile, ref int pos, byte[] arr) { Write(tile.X, ref pos, ref arr); Write(tile.Y, ref pos, ref arr); Write(tile.Type, ref pos, ref arr); Write(tile.Direction, ref pos, ref arr); }
/* * Function: getTileSubdivisionBoundaries * * Parameters: GTile:<tile>, TileSubdivisions:<subdivision> * * Returns: Vector2[2] * * -Returns a two-element array containing Vector2s to represent the position boundary points of <tile>s <subdivision> * * Tiles are subdivided as follows: * +---+---+ * |[0]|[1]| * +---+---+ * |[2]|[3]| * +---+---+ * where: * subdivision [0] = TileSubdivisions.TopLeft * subdivision [1] = TileSubdivisions.TopRight * subdivision [2] = TileSubdivisions.BottomLeft * subdivision [3] = TileSubdivisions.BottomRight * * Then the returned array contains the position of the 2 points that delimitate <tile>s <subdivision>, as follows: * <returned>[0] = Top-Left point * <returned>[1] = Bottom-Right point * */ public Vector2[] getTileSubdivisionBoundaries(GTile tile, TileSubdivisions subdivision) { Vector2 tile_origin = tile.getOrigin(); Vector2[] boundaries = new Vector2[2] { Vector2.zero, Vector2.zero }; switch (subdivision) { case TileSubdivisions.TopLeft: boundaries[0] = new Vector2(tile_origin.x + 0, tile_origin.y + GameController.DataSettings.tile_width / 2); boundaries[1] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width / 2, tile_origin.y + GameController.DataSettings.tile_width); break; case TileSubdivisions.TopRight: boundaries[0] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width / 2, tile_origin.y + GameController.DataSettings.tile_width / 2); boundaries[1] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width, tile_origin.y + GameController.DataSettings.tile_width); break; case TileSubdivisions.BottomLeft: boundaries[0] = new Vector2(tile_origin.x + 0, tile_origin.y + 0); boundaries[1] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width / 2, tile_origin.y + GameController.DataSettings.tile_width / 2); break; case TileSubdivisions.BottomRight: boundaries[0] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width / 2, tile_origin.y + 0); boundaries[1] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width, tile_origin.y + GameController.DataSettings.tile_width / 2); break; } return(boundaries); }
public void generateScenery() { Vector2 selected_tile_index; GTile selected_tile; TileSubdivisions subdivision; GStructure veg; int objs = 1000; while (objs > 0) { selected_tile_index = new Vector2(UnityEngine.Random.Range(0, 50), UnityEngine.Random.Range(0, 50)); selected_tile = GameData.GData.getTile(selected_tile_index); veg = null; int vegType = UnityEngine.Random.Range(0, 100); if (vegType >= 0 && vegType < 20) { veg = getRandomTree(); } if (vegType >= 20 && vegType < 30) { veg = getRandomSceneryProp(); } if (vegType >= 30 && vegType < 100) { veg = getRandomBush(); } if (veg != null) { if (veg.dimensions.size == StructureSizes.Large) { if (!selected_tile.containsStructures()) { // set position objs--; } } else if (veg.dimensions.size == StructureSizes.Medium) { if (!selected_tile.containsStructures()) { veg.setPosition(selected_tile, Vector2.zero); objs--; } } else if (veg.dimensions.size == StructureSizes.Small) { subdivision = GTile.GetRandomSubdivision(); if (!selected_tile.containsStructures(subdivision)) { veg.setPosition(selected_tile, subdivision); objs--; } } } } }
public override void setPosition(GTile tile, Vector2 offset) { removeFromTile(); if (placeAtPoint(tile.getCenter(offset))) { addToTile(tile); } }
public bool tileBelongsToSector(GTile tile) { Vector2 sectorIndexes = GameData.GData.tileIndexesToSectorIndexes (new Vector2 (tile.index_x, tile.index_y)); if (sectorIndexes.x == index_x && sectorIndexes.y == index_y) { return true; } return false; }
public bool pointBelongsToTile(Vector2 point, GTile tile) { if (getTile(worldPointToTileIndexes(point)) == tile) { return(true); } return(false); }
public void addToTile(GTile tile) { if (this.tile == null) { // object does not belong to a tile this.tile = tile; tile.Contained_Objects.addObject(this); } }
public void removeFromTile() { if (tile != null) { // object belongs to a tile tile.Contained_Objects.removeObject(this); tile = null; } }
public void transferToTile(GTile tile) { if (this.tile != null) { // object belongs to a tile removeFromTile(); } addToTile (tile); }
public void transferToTile(GTile tile) { if (this.tile != null) { // object belongs to a tile removeFromTile(); } addToTile(tile); }
public bool tileBelongsToSector(GTile tile) { Vector2 sectorIndexes = GameData.GData.tileIndexesToSectorIndexes(new Vector2(tile.index_x, tile.index_y)); if (sectorIndexes.x == index_x && sectorIndexes.y == index_y) { return(true); } return(false); }
private static GTile _readTile(byte[] arr, ref int pos) { GTile Tile = null; float x = ReadFloat(arr, ref pos); float y = ReadFloat(arr, ref pos); int type = ReadInt32(arr, ref pos); Directions dir = (Directions)ReadInt32(arr, ref pos); if (type == TileType.GRASS) { Tile = new Grass(x, y); } if (type == TileType.GRAVEL) { Tile = new Gravel(x, y); } if (type == TileType.METAL) { Tile = new Metal(x, y); } if (type == TileType.SAND) { Tile = new Sand(x, y); } if (type == TileType.WATER) { Tile = new Water(x, y); } if (type == TileType.D_FLOWER) { Tile = new Flower(x, y); } if (type == TileType.D_GRASS_SHORE) { Tile = new GrassShore(x, y, dir); } if (type == TileType.D_GRAVEL_SHORE) { Tile = new GravelShore(x, y, dir); } if (type == TileType.D_SAND_SHORE) { Tile = new SandShore(x, y, dir); } if (type == TileType.D_SAND_TRACE) { Tile = new SandTrace(x, y, dir); } if (type == 0) { Tile = new GTile(x, y, true); } return(Tile); }
public bool pointBelongsToTileSubdivision(Vector2 point, GTile tile, TileSubdivisions subdivision) { if (pointBelongsToTile(point, tile)) { Vector2[] boundaries = getTileSubdivisionBoundaries(tile, subdivision); if (point.x > boundaries[0].x && point.x <boundaries[1].x && point.y> boundaries[0].y && point.y < boundaries[1].y) { return(true); } } return(false); }
private void setTileUvs(int tile_index, Vector2[] uvs, WorldSector sector, int tile_index_x, int tile_index_y) { Vector2 abs_indexes = new Vector2(sector.lower_boundary_x + tile_index_x, sector.lower_boundary_y + tile_index_y); GTile tile = GameData.GData.getTile(abs_indexes); Vector2[] uvCoords = texMan.getUvCoords(texMan.getRandomTexture(tile.biome.type)); //Vector2[] uvCoords = texMan.getUvCoords(UnityEngine.Random.Range(0, texMan.grid_cells_x), UnityEngine.Random.Range (0, texMan.grid_cells_y)); uvs [4 * tile_index + (int)TileVertices.topLeft] = new Vector2(uvCoords[0].x, uvCoords[0].y); uvs [4 * tile_index + (int)TileVertices.topRight] = new Vector2(uvCoords[0].x, uvCoords[1].y); uvs [4 * tile_index + (int)TileVertices.bottomRight] = new Vector2(uvCoords[1].x, uvCoords[1].y); uvs [4 * tile_index + (int)TileVertices.bottomLeft] = new Vector2(uvCoords[1].x, uvCoords[0].y); }
/* * Sets the position of this GStructure to the center of <tile>, offset by <offset> */ public override void setPosition(GTile tile, Vector2 offset) { removeFromTile(); if (placeAtPoint(tile.getCenter(offset))) { addToTile(tile); if (dimensions.size == StructureSizes.Small) { reflist_index.subdivision = GameData.GData.getSubdivisionFromPoint(getPosition()); } } else { Debug.LogError("Failed to place GStructure at " + tile.getCenter(offset)); } }
/* * Sets the position of this GStructure to the center of <tile>, at the specified <subdivision> */ public void setPosition(GTile tile, TileSubdivisions subdivision) { if (dimensions.size == StructureSizes.Small) { removeFromTile(); if (placeAtPoint(tile.getCenter(subdivision))) { addToTile(tile); reflist_index.subdivision = subdivision; } else { Debug.LogError("Failed to place GStructure at " + tile.getCenter()); } } else { Debug.LogError("GStructure must be of size small."); } }
/* * Function: getSubdivisionFromPoint * * Parameters: Vector2:<point> * * Returns: TileSubdivisions * * -Returns the TileSubdivision of the tile which contains <point> in which <point> is located. */ public TileSubdivisions getSubdivisionFromPoint(Vector2 point) { GTile tile = getTileFromWorldPoint(point); if (pointBelongsToTileSubdivision(point, tile, TileSubdivisions.TopLeft)) { return(TileSubdivisions.TopLeft); } if (pointBelongsToTileSubdivision(point, tile, TileSubdivisions.TopRight)) { return(TileSubdivisions.TopRight); } if (pointBelongsToTileSubdivision(point, tile, TileSubdivisions.BottomLeft)) { return(TileSubdivisions.BottomLeft); } if (pointBelongsToTileSubdivision(point, tile, TileSubdivisions.BottomRight)) { return(TileSubdivisions.BottomRight); } return(TileSubdivisions.TopLeft); }
private void setupDataStructures() { // init tiles worldTiles = new GTile[GameController.DataSettings.world_size, GameController.DataSettings.world_size]; for (int x = 0; x < GameController.DataSettings.world_size; ++x) { for (int y = 0; y < GameController.DataSettings.world_size; ++y) { worldTiles[x, y] = new GTile(x, y); } } // init sectors sectorsWithinRange = new List <WorldSector> (); if (GameController.DataSettings.world_size % GameController.DataSettings.sector_size != 0) { Debug.LogError("Invalid sector size: Must be multiple of world size"); } else { worldSectors = new WorldSector[GameController.DataSettings.world_side_sectors, GameController.DataSettings.world_side_sectors]; for (int x = 0; x < GameController.DataSettings.world_side_sectors; ++x) { for (int y = 0; y < GameController.DataSettings.world_side_sectors; ++y) { worldSectors[x, y] = new WorldSector( x, y, x * GameController.DataSettings.sector_size, x * GameController.DataSettings.sector_size + GameController.DataSettings.sector_size, y * GameController.DataSettings.sector_size, y * GameController.DataSettings.sector_size + GameController.DataSettings.sector_size ); } } } }
public virtual void setPosition(GTile tile) { }
public bool pointBelongsToTileSubdivision(Vector2 point, GTile tile, TileSubdivisions subdivision) { if (pointBelongsToTile (point, tile)) { Vector2[] boundaries = getTileSubdivisionBoundaries(tile, subdivision); if(point.x > boundaries[0].x && point.x < boundaries[1].x && point.y > boundaries[0].y && point.y < boundaries[1].y) { return true; } } return false; }
private void setupDataStructures() { // init tiles worldTiles = new GTile[GameController.DataSettings.world_size, GameController.DataSettings.world_size]; for (int x = 0; x < GameController.DataSettings.world_size; ++x) { for (int y = 0; y < GameController.DataSettings.world_size; ++y) { worldTiles[x, y] = new GTile(x, y); } } // init sectors sectorsWithinRange = new List<WorldSector> (); if (GameController.DataSettings.world_size % GameController.DataSettings.sector_size != 0) { Debug.LogError ("Invalid sector size: Must be multiple of world size"); } else { worldSectors = new WorldSector[GameController.DataSettings.world_side_sectors, GameController.DataSettings.world_side_sectors]; for (int x = 0; x < GameController.DataSettings.world_side_sectors; ++x) { for (int y = 0; y < GameController.DataSettings.world_side_sectors; ++y) { worldSectors[x, y] = new WorldSector( x, y, x * GameController.DataSettings.sector_size, x * GameController.DataSettings.sector_size + GameController.DataSettings.sector_size, y * GameController.DataSettings.sector_size, y * GameController.DataSettings.sector_size + GameController.DataSettings.sector_size ); } } } }
public MapEditor(InputHandler Input, int levelWidth, int levelHeight, int fillTile, Modes mapMode, MapEditorGuiScreen parent) { _parent = parent; _mode = mapMode; LevelWidth = levelWidth; LevelHeight = levelHeight; this.Input = Input; Tiles = new List <GEntity>(); Entities = new List <GEntity>(); Spawners = new List <GEntity>(); GEntity e, t; int tx, ty; for (int i = 0; i < LevelHeight; i++) { ty = i * GTile.HEIGHT; for (int j = 0; j < levelWidth; j++) { e = t = null; tx = j * GTile.WIDTH; if (_isBorder(j, i)) { Entities.Add(new Metal(tx, ty)); Tiles.Add(new GTile(tx, ty, true)); continue; } switch (fillTile) { case TileType.WALL: e = new Wall(tx, ty); t = new Gravel(tx, ty); break; case TileType.METAL: e = new Metal(tx, ty); break; case TileType.SAND: t = new Sand(tx, ty); break; case TileType.WATER: t = new Water(tx, ty); break; case TileType.GRAVEL: t = new Gravel(tx, ty); break; case TileType.GRASS: t = new Grass(tx, ty); break; } if (t == null) { t = new GTile(tx, ty, true); } Tiles.Add(t); Entities.Add(e); } } _endConstruct(); }
/* * Function: getTileSubdivisionBoundaries * * Parameters: GTile:<tile>, TileSubdivisions:<subdivision> * * Returns: Vector2[2] * * -Returns a two-element array containing Vector2s to represent the position boundary points of <tile>s <subdivision> * * Tiles are subdivided as follows: * +---+---+ * |[0]|[1]| * +---+---+ * |[2]|[3]| * +---+---+ * where: * subdivision [0] = TileSubdivisions.TopLeft * subdivision [1] = TileSubdivisions.TopRight * subdivision [2] = TileSubdivisions.BottomLeft * subdivision [3] = TileSubdivisions.BottomRight * * Then the returned array contains the position of the 2 points that delimitate <tile>s <subdivision>, as follows: * <returned>[0] = Top-Left point * <returned>[1] = Bottom-Right point * */ public Vector2[] getTileSubdivisionBoundaries(GTile tile, TileSubdivisions subdivision) { Vector2 tile_origin = tile.getOrigin(); Vector2[] boundaries = new Vector2[2] { Vector2.zero, Vector2.zero }; switch (subdivision) { case TileSubdivisions.TopLeft: boundaries[0] = new Vector2(tile_origin.x + 0, tile_origin.y + GameController.DataSettings.tile_width / 2); boundaries[1] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width / 2, tile_origin.y + GameController.DataSettings.tile_width); break; case TileSubdivisions.TopRight: boundaries[0] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width / 2, tile_origin.y + GameController.DataSettings.tile_width / 2); boundaries[1] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width, tile_origin.y + GameController.DataSettings.tile_width); break; case TileSubdivisions.BottomLeft: boundaries[0] = new Vector2(tile_origin.x + 0, tile_origin.y + 0); boundaries[1] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width / 2, tile_origin.y + GameController.DataSettings.tile_width / 2); break; case TileSubdivisions.BottomRight: boundaries[0] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width / 2, tile_origin.y + 0); boundaries[1] = new Vector2(tile_origin.x + GameController.DataSettings.tile_width, tile_origin.y + GameController.DataSettings.tile_width / 2); break; } return boundaries; }
/* * Sets the position of this GStructure to the center of <tile>, at the specified <subdivision> */ public void setPosition(GTile tile, TileSubdivisions subdivision) { if (dimensions.size == StructureSizes.Small) { removeFromTile (); if (placeAtPoint (tile.getCenter (subdivision))) { addToTile (tile); reflist_index.subdivision = subdivision; } else { Debug.LogError ("Failed to place GStructure at " + tile.getCenter ()); } } else { Debug.LogError ("GStructure must be of size small."); } }
public bool pointBelongsToTile(Vector2 point, GTile tile) { if (getTile (worldPointToTileIndexes (point)) == tile) { return true; } return false; }
public virtual void setPosition(GTile tile, Vector2 offset) { }
private static object[] _parseLevel(BinaryReader br) { List <GEntity> ParsedTiles = new List <GEntity>(); List <GEntity> ParsedEntities = new List <GEntity>(); List <GEntity> ParsedSpawners = new List <GEntity>(); int TileWidth = GTile.WIDTH; int TileHeight = GTile.HEIGHT; int Cx = 0; int Cy = 0; int width = br.ReadInt32(); int height = br.ReadInt32(); MapEntity mp; GEntity tTile = null; GEntity tEntity = null; GEntity tSpawner = null; for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { Cx = x * TileWidth; Cy = y * TileHeight; tTile = null; tEntity = null; tSpawner = null; mp = (MapEntity)br.ReadByte(); switch (mp) { case MapEntity.WallOnGravel: tTile = new Gravel(Cx, Cy); tEntity = new Wall(Cx, Cy); break; case MapEntity.WallOnWater: tTile = new Water(Cx, Cy); tEntity = new Wall(Cx, Cy); break; case MapEntity.WallOnSand: tTile = new Sand(Cx, Cy); tEntity = new Wall(Cx, Cy); break; case MapEntity.WallOnGrass: tTile = new Grass(Cx, Cy); tEntity = new Wall(Cx, Cy); break; case MapEntity.Metal: tTile = new GTile(Cx, Cy, true); tEntity = new Metal(Cx, Cy); break; case MapEntity.Water: tTile = new Water(Cx, Cy); break; case MapEntity.Gravel: tTile = new Gravel(Cx, Cy); break; case MapEntity.Sand: tTile = new Sand(Cx, Cy); break; case MapEntity.Grass: tTile = new Grass(Cx, Cy); break; case MapEntity.RedSpawnerOnGravel: tTile = new Gravel(Cx, Cy); tSpawner = new Spawner(Cx, Cy, Teams.Red); break; case MapEntity.RedSpawnerOnWater: tTile = new Water(Cx, Cy); tSpawner = new Spawner(Cx, Cy, Teams.Red); break; case MapEntity.RedSpawnerOnSand: tTile = new Sand(Cx, Cy); tSpawner = new Spawner(Cx, Cy, Teams.Red); break; case MapEntity.RedSpawnerOnGrass: tTile = new Grass(Cx, Cy); tSpawner = new Spawner(Cx, Cy, Teams.Red); break; case MapEntity.BluSpawnerOnGravel: tTile = new Gravel(Cx, Cy); tSpawner = new Spawner(Cx, Cy, Teams.Blu); break; case MapEntity.BluSpawnerOnWater: tTile = new Water(Cx, Cy); tSpawner = new Spawner(Cx, Cy, Teams.Blu); break; case MapEntity.BluSpawnerOnSand: tTile = new Sand(Cx, Cy); tSpawner = new Spawner(Cx, Cy, Teams.Blu); break; case MapEntity.BluSpawnerOnGrass: tTile = new Grass(Cx, Cy); tSpawner = new Spawner(Cx, Cy, Teams.Blu); break; case MapEntity.BluFlagOnGravel: tTile = new Gravel(Cx, Cy); tEntity = new Flag(Cx, Cy, Teams.Blu); break; case MapEntity.BluFlagOnWater: tTile = new Water(Cx, Cy); tEntity = new Flag(Cx, Cy, Teams.Blu); break; case MapEntity.BluFlagOnSand: tTile = new Sand(Cx, Cy); tEntity = new Flag(Cx, Cy, Teams.Blu); break; case MapEntity.BluFlagOnGrass: tTile = new Grass(Cx, Cy); tEntity = new Flag(Cx, Cy, Teams.Blu); break; case MapEntity.RedFlagOnGravel: tTile = new Gravel(Cx, Cy); tEntity = new Flag(Cx, Cy, Teams.Red); break; case MapEntity.RedFlagOnWater: tTile = new Water(Cx, Cy); tEntity = new Flag(Cx, Cy, Teams.Red); break; case MapEntity.RedFlagOnSand: tTile = new Sand(Cx, Cy); tEntity = new Flag(Cx, Cy, Teams.Red); break; case MapEntity.RedFlagOnGrass: tTile = new Grass(Cx, Cy); tEntity = new Flag(Cx, Cy, Teams.Red); break; } if (tTile != null) { ParsedTiles.Add(tTile); } if (tEntity != null) { ParsedEntities.Add(tEntity); } if (tSpawner != null) { ParsedSpawners.Add(tSpawner); } } } return(new object[] { width, height, ParsedTiles, ParsedEntities, ParsedSpawners }); }
/* * Sets the position of this GStructure to the center of <tile>, offset by <offset> */ public override void setPosition(GTile tile, Vector2 offset) { removeFromTile (); if (placeAtPoint (tile.getCenter (offset))) { addToTile (tile); if(dimensions.size == StructureSizes.Small) { reflist_index.subdivision = GameData.GData.getSubdivisionFromPoint(getPosition()); } } else { Debug.LogError("Failed to place GStructure at "+tile.getCenter (offset)); } }