public Tile(int type, int col, int row, TileGrid grid) { this.type = type; this.row = row; this.column = col; this.grid = grid; }
// Returns the appropriate color for the specified tile type. This // method is static for ease of access. public static Color TileTypeToColor( TileGrid.TileTypes type ) { Color color = Color.white; switch( type ) { case TileGrid.TileTypes.Red: color = Color.red; break; case TileGrid.TileTypes.Yellow: color = Color.yellow; break; case TileGrid.TileTypes.Green: color = Color.green; break; case TileGrid.TileTypes.Blue: color = Color.blue; break; case TileGrid.TileTypes.Purple: color = Color.magenta; break; } return color; }
void Awake () { goal = GameObject.FindGameObjectWithTag ("Goal"); tile_grid = GameObject.FindGameObjectWithTag ("TileGrid").GetComponent<TileGrid> (); m_animator = GetComponent<Animator> (); m_mobSound = GetComponent<MobSound> (); goal_position = transform.position; }
public static Bitmap RenderGrid(TileSet tileSet, Palette palette, TileGrid tileGrid, bool transparent) { Bitmap bitmap = new Bitmap(tileGrid.Width * tileGrid.TileWidth, tileGrid.Height * tileGrid.TileHeight, PixelFormat.Format32bppArgb); BitmapData canvas = bitmap.LockBits(); RenderGrid(canvas, 0, 0, tileSet, palette, tileGrid, transparent); bitmap.UnlockBits(canvas); return bitmap; }
public virtual void init(TileGrid grid, PointInt pos) { m_grid = grid; m_position = pos; transform.localPosition = new Vector2(pos.x, pos.y); tileUp = grid[pos.x, pos.y + 1]; tileDown = grid[pos.x, pos.y - 1]; tileLeft = grid[pos.x - 1, pos.y]; tileRight = grid[pos.x + 1, pos.y]; }
public void BuildMesh( TileGrid grid ){ //Create new mesh data int numTiles = size_x * size_y; int vsize_x = size_x + 1; int vsize_y = size_y +1; int numVerts = vsize_x * vsize_y; Vector3[] vertices = new Vector3[ numVerts ]; int[] triangles = new int[ numTiles * 2 * 3 ]; Vector3[] normals = new Vector3[ numVerts ]; Vector2[] uv = new Vector2[ numVerts ]; //vertices , normals, uv for( int y = 0; y < vsize_y; y++ ){ for( int x = 0; x < vsize_x; x++ ){ vertices[y * vsize_x + x] = new Vector3( x * tileScale, y * tileScale, 0); normals[ y * vsize_x + x ] = Vector3.up; uv[ y * vsize_x + x ] = new Vector2( (float) x/size_x,(float) y/size_y ); } } //triangles for( int y = 0; y < size_y; y++ ){ for( int x = 0; x < size_x; x++ ){ int squareIndex = y * size_x + x; int offset = squareIndex * 6; triangles[offset + 0] = y * vsize_x + x + 0; triangles[offset + 1] = y * vsize_x + x + vsize_x + 0; triangles[offset + 2] = y * vsize_x + x + vsize_x + 1; triangles[offset + 3] = y * vsize_x + x + 0; triangles[offset + 4] = y * vsize_x + x + vsize_x + 1; triangles[offset + 5] = y * vsize_x + x + 1; //Debug.Log("T : "+triangles[offset + 0]+", "+triangles[offset + 1]+", "+triangles[offset + 2]); } } //Create new Mesh and populate with the data Mesh mesh = new Mesh(); mesh.vertices = vertices;//point mesh.triangles = triangles;//polygon mesh.normals = normals;//n mesh.uv = uv; MeshFilter mesh_filter = GetComponent<MeshFilter>(); MeshCollider mesh_collider = GetComponent<MeshCollider>(); mesh_filter.mesh = mesh; mesh_collider.sharedMesh = mesh; BuildTexture(grid); }
// Use this for initialization new void Start() { base.Start (); endTurnDelegate = new EventDelegate (EndTurn); Events.Listen ("EndTurn", endTurnDelegate); Colorize (); colony.Nucleus = this; tileGrid = GameObject.Find ("grid").GetComponent<TileGrid> (); TileQuery q = new TileQuery (); q.FindTileAt (tileGrid.width / 2, tileGrid.height / 2).Cell = this; this.transform.position = new Vector2 (tileGrid.width / 2, tileGrid.height / 2); }
// Use this for initialization void Awake() { // Starting Conditions GridWidth = 100; GridHeight = 100; TilesPerUnit = 1; RoomList = new List<Room>(); grid = GetComponent<TileGrid>(); RNG = new System.Random(RNGSeed); }
private static Autotiler.Generated Generate(this Autotiler tiler, VirtualMap <char> mapData, int startX, int startY, VirtualMap <char> forceData, Autotiler.Behaviour behaviour) { usingCustomAutotiler = true; forceData_CustomAutotiler = forceData; startPoint_CustomAutotiler = new Point(startX, startY); TileGrid tileGrid = new TileGrid(8, 8, forceData.Columns, forceData.Rows); AnimatedTiles animatedTiles = new AnimatedTiles(forceData.Columns, forceData.Rows, GFX.AnimatedTilesBank); Rectangle empty = new Rectangle(startX, startY, forceData.Columns, forceData.Rows); for (int i = startX; i < startX + forceData.Columns; i += 50) { for (int j = startY; j < startY + forceData.Rows; j += 50) { if (!mapData.AnyInSegmentAtTile(i, j)) { j = j / 50 * 50; } else { int k = i; int num = Math.Min(i + 50, startX + forceData.Columns); while (k < num) { int l = j; int num2 = Math.Min(j + 50, startY + forceData.Rows); while (l < num2) { object tiles = m_TileHandler.Invoke(tiler, new object[] { mapData, k, l, empty, forceData[k - startX, l - startY], behaviour }); if (tiles != null) { tileGrid.Tiles[k - startX, l - startY] = Calc.Random.Choose(f_Tiles_Textures.GetValue(tiles)); if (f_Tiles_HasOverlays.GetValue(tiles)) { animatedTiles.Set(k - startX, l - startY, Calc.Random.Choose(f_Tiles_OverlapSprites.GetValue(tiles)), 1f, 1f); } } l++; } k++; } } } } usingCustomAutotiler = false; return(new Autotiler.Generated { TileGrid = tileGrid, SpriteOverlay = animatedTiles }); }
public HashSet <Tile> GetAvailableTargets(Tile tile) { HashSet <Tile> ret = new HashSet <Tile>(); foreach (Unit u in UnitManager.Instance.GetUnits()) { int d = TileGrid.GetDelta(this, u); if (d > 0 && d <= range) { ret.Add(u.Tile); } } return(ret); }
public static void RenderGrid(BitmapData canvas, int x, int y, TileSet tileSet, Palette palette, TileGrid tileGrid, bool transparent) { for (int ty = 0; ty < tileGrid.Height; ty++) { for (int tx = 0; tx < tileGrid.Width; tx++) { TileProperties properties = tileGrid[tx, ty]; RenderTile(canvas, x + (tx * tileGrid.TileWidth), y + (ty * tileGrid.TileHeight), tileSet[properties.TileIndex], palette, properties.PaletteIndex, properties.FlipX, properties.FlipY, transparent); } } }
/// <summary> /// Retrieves the unwrapped tilegrid from the scene. /// </summary> /// <returns>The tile grid instance (with no notion of monobehaviour).</returns> public TileGrid GetInstance() { // Create the base grid with the inspector arguments. TileGrid grid = new TileGrid( new Vector2Int { x = width, y = height }, gridUnit, transform.position ); // Fill in the terrain data based on the sprites // in the tilemap. Sprite spriteAtCoords; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { spriteAtCoords = terrainMap.GetSprite(new Vector3Int(x, y, 0)); // Find the corresponding sprite. // TODO this is slow but only runs once so I'm not super concerned. foreach (SpriteInteractionsPair pair in terrainData) { if (pair.whenSpriteUsed == spriteAtCoords) { // Process the inspector data into a dictionary. Dictionary <UnitType, UnitTerrainData> parsedData = new Dictionary <UnitType, UnitTerrainData>(); foreach (UnitInteraction interaction in pair.interactions) { parsedData[interaction.unitType] = interaction.interactionData; } // Use the parsed data to fill in accessible terrain data. // TODO I think this is creating redundant instances of TileTerrain. // Maybe refactor this so that the Terrain dictionary points to // single instances instead of identical copy instances. grid.Terrain[new Vector2Int(x, y)] = new TileTerrain(parsedData); break; } } } } // Destroy this script's Monobehaviour baggage, // and return the lightweight instance. Destroy(this); return(grid); }
/// <summary> /// Removes a shelf unit to the units going by its bottom left coordinate /// </summary> /// <param name="blx">Bottom left coordiante of shelf</param> /// <param name="bly">Bottom right coordinate of shelf</param> public static void removeUnit(int blx, int bly, float xsize, float ysize) { //Again, no need for bound checking as it is done for us by this point //Debug.Log("removing a shelf : " + blx + " " + bly); for (int x = 0; x < xsize; x++) { for (int y = 0; y < ysize; y++) { tiles.Remove(TileGrid.getKey(blx + x, bly + y)); } } }
//void PlaceDoors() // For a door to be valid //{ //for (int y = 0; y < grid.Height; y++) //{ //for (int x = 0; x < grid.Width; x++) //{ //TileNode<NodeState> targetNode = grid.GetNode(x, y); //TileNode<NodeState>[] neighbours = new TileNode<NodeState>[8]; //for (int i = 0; i < 8; i++) //{ //neighbours[i] = grid.GetNeighbour(x, y, i); //} //if () //} //} //} //NOTE (David) Ok , so this was overcomplicated to the extreme. //Simple solution: Create non colliding paths by just checking two neighbours away instead of one. //Sounds retarded but it works. Although for it to look proper the rooms must be positioned on an odd tile and be odd sizes private static void BuildPath(ref TileGrid <NodeState> tileGrid, TileNode <NodeState> currentNode, int prevDir) { currentNode.Visited = true; if (currentNode.Data != NodeState.Door) { currentNode.Data = NodeState.Path; } TileNode <NodeState>[] possibleChildren = new TileNode <NodeState> [4]; for (int i = 0; i < possibleChildren.Length; i++) { TileNode <NodeState> tmp = tileGrid.GetNeighbour(currentNode.position.x, currentNode.position.y, i * 2); if (tmp != null) { possibleChildren[i] = tileGrid.GetNeighbour(tmp.position.x, tmp.position.y, i * 2); } } List <int> randomIndices = new List <int>(); for (int i = 0; i < possibleChildren.Length; i++) { if (possibleChildren[i] != null && !possibleChildren[i].Visited) { randomIndices.Add(i); } } while (randomIndices.Count > 0) { int rand = Random.value > 0.55f ? randomIndices[Random.Range(0, randomIndices.Count)] : prevDir; randomIndices.Remove(rand); TileNode <NodeState> nextNode = possibleChildren[rand]; if (nextNode != null && !nextNode.Visited && nextNode.Data == NodeState.Empty) { TileNode <NodeState> midNode = tileGrid.GetNeighbour(currentNode.position.x, currentNode.position.y, rand * 2); currentNode.AddChild(midNode); midNode.AddChild(nextNode); tileGrid.GetNeighbour(currentNode.position.x, currentNode.position.y, rand * 2).Visited = true; tileGrid.GetNeighbour(currentNode.position.x, currentNode.position.y, rand * 2).Data = NodeState.Path; BuildPath(ref tileGrid, nextNode, rand); } } }
public static bool IsWithinRangeOfTile(Coordinate c, TileGrid tileGrid, System.Type type, float distance) { float distanceToNearest = -1.0f; Tile t = tileGrid.FindNearestTileOfType(c, type, ref distanceToNearest); if (t) { if (distanceToNearest < distance) { return(true); } } return(false); }
private void DrawButtons(TileGrid grid) { GUILayout.BeginHorizontal(); if (GUILayout.Button("Generate")) { grid.Generate(); } if (GUILayout.Button("Destroy")) { grid.DestroyGrid(); } GUILayout.EndHorizontal(); }
//public ControllerMineSweeperGameCode C_MineSweeperGame { get; set; } //public ControllerLeaderBoard C_LeaderBoard { get; set; } //public ControllerOptions C_OptionsForm { get; set; } //public ControllerRegister C_RegisterForm { get; set; } //public ControllerLogin C_LoginPage { get; set; } //public ControllerSearchUser C_SearchPage { get; set; } // Controllers //public static FormVencedor V_Vencedor { get; private set; } //public static GameController C_Master { get; private set; } /// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { this.InitializeComponent(); this.Suspending += OnSuspending; M_Grelha = new TileGrid(); M_Status = new ConnectionToServer(); M_Options = new Options(); M_BestScores = new BestScores(); // class que vai permitir a reprodução de audio SoundPlayer = new SoundEffects(); C_Master = new GameController(); }
private void PrintPathValues() { TileGrid tg = LevelGenerator.Instance.GetTileGrid(); string output = ""; for (int i = 0; i < tg.dimY; i++) { for (int j = 0; j < tg.dimX; j++) { output += tg.GetTileAt(new Coordinate(j, i)).numStepsFromCity + ", "; } output += "\n"; } print(output); }
private void Awake() { IDesignerParser parser = new UnitySceneParser(); grid = parser.GetFirstTileGrid(); damageTable = parser.GetFirstDamageTable(); parser.GetAllPreplacedActors(grid); Commander[] commanders = parser.GetAllPreplacedCommanders(grid, damageTable); FindObjectOfType <CommanderPanelManager>().InitializeCommanders(commanders); StartCoroutine(WaitInitThenStart()); }
/// <summary> /// Checks a square to see if it is occupied on the grid /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public static bool occupied(int x, int y, int myID) { string keyToCheck = TileGrid.getKey(x, y); //Debug.Log("Checking Key " + keyToCheck); //Debug.Log(tiles.ContainsKey(keyToCheck)); if (tiles.ContainsKey(keyToCheck)) { //it is allowed to collide with itself return(tiles[keyToCheck].getID() != myID); } return(false); }
public override void Added(Scene scene) { base.Added(scene); int tilesX = (int)Width / 8; int tilesY = (int)Height / 8; Level level = SceneAs <Level>(); Rectangle tileBounds = level.Session.MapData.TileBounds; VirtualMap <char> solidsData = level.SolidsData; int x = (int)X / 8 - tileBounds.Left; int y = (int)Y / 8 - tileBounds.Top; _tiles = GFX.FGAutotiler.GenerateOverlay(_fillTile, x, y, tilesX, tilesY, solidsData).TileGrid; Add(_tiles); Add(new TileInterceptor(_tiles, highPriority: false)); }
public string ToString() { string str = "Height = " + TileGrid.GetLength(0) + " Width = " + TileGrid.GetLength(1) + "\n"; for (int row = 0; row < Height; ++row) { for (int col = 0; col < width; ++col) { str += this[row, col].Id + " "; } str += "\n"; } return(str); }
public virtual void Update(float time, TileGrid grid) { // NOT EFFICIENT if (isBlockable) { if (myCurrentTile != null) { myPreviousTile = myCurrentTile; myPreviousTile.UnblockMe(); } myCurrentTile = grid.ReturnTile(myPosition); myCurrentTile.BlockMe(); } }
internal void SetAdjacentTiles() { TileGrid tileGrid = (TileGrid)this.Parent; List <Tile> adjecentTiles = new List <Tile>(8); foreach (int[] adjecentCoord in adjecentCoords) { Tile tile = tileGrid[new Point(this.GridPosition.X + adjecentCoord[0], this.GridPosition.Y + adjecentCoord[1])]; if (tile != null) { adjecentTiles.Add(tile); } } this.AdjecentTiles = adjecentTiles.ToArray(); }
/// <summary> /// Retrieves the unwrapped player commander from the scene. /// </summary> /// <returns>The tile grid instance (with no notion of monobehaviour).</returns> public PlayerCommander GetInstance(TileGrid grid) { // Create the new commander and add it to the grid. PlayerCommander commander = new PlayerCommander(teamID, grid, controller.GetInstance(grid), buttonsListener); grid.Commanders.Add(commander); // Bind the pause curtain to the new player. // TODO this approach does not support multiple human players. pauseCurtain.DrivingCommander = commander; // Destroy this script's Monobehaviour baggage, // and return the lightweight instance. Destroy(this); return(commander); }
protected void CreateTiles(TileGrid grid, TileType[,] tiles) { for (int x = 0; x < grid.GridSize.x; x++) { for (int y = 0; y < grid.GridSize.y; y++) { var tilePrefab = tiles[x, y] == TileType.land1 ? landPrefab1 : tiles[x, y] == TileType.land2 ? landPrefab2 : tiles[x, y] == TileType.water ? waterPrefab : null; TileCreator.CreateTile(grid, x, y, () => tilePrefab); } } }
// Creates a grid representation of an array of objects. // The dimensions parameter defines the dimensions of the grid // eg. [4, 7, 3] Would be a size x=4, y=7, z=3 grid. // The objects array must have a length equal to the product of all dimensions. public TileGrid <T> CreateGrid(int[] dimensions, T[] objects) { int objCount = 1; for (int ii = 0; ii < dimensions; ii++) { objCount *= dimensions[ii]; } if (objCount != objects.Length) { throw new System.ArgumentException(); } TileGrid <T> result = new TileGrid <T>(dimensions); }
public static int GetCurrentPopulationAvailable(TileGrid tileGrid) { if (tileGrid == null) { return(0); // HACK: assume tileGrid hasn't been initialized yet, so there must be no population } List <Tile> structures = TileGridFilter.GetAllStructureTiles(tileGrid); int populationAvailable = 0; for (int i = 0; i < structures.Count; i++) { populationAvailable += structures[i].GetPopulationAdjustment(); } return(populationAvailable); }
private static void OrientationChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { int oldRowSpan = TileGrid.GetRowSpan(sender); int oldColSpan = TileGrid.GetColumnSpan(sender); TileGrid.SetColumnSpan(sender, oldRowSpan); TileGrid.SetRowSpan(sender, oldColSpan); HorizontalAlignment oldHAlign = (sender as NumberSlider).s.HorizontalAlignment; VerticalAlignment oldVAlign = (sender as NumberSlider).s.VerticalAlignment; (sender as NumberSlider).s.HorizontalAlignment = oldHAlign == HorizontalAlignment.Center ? HorizontalAlignment.Stretch : HorizontalAlignment.Center; (sender as NumberSlider).s.VerticalAlignment = oldVAlign == VerticalAlignment.Center ? VerticalAlignment.Stretch : VerticalAlignment.Center; }
public void CreateNewLevel() { //initialize the map map = new TileGrid(mapSize, tileSize); moves = new Stack <int[]>(); DestroySpawnPoints(); InitializeSpawnPoints(); InitializeLevelBounds(); LoadEnvironment(environment); shouldGenerateMesh = true; ToggleObjects(isShowingObjects); }
/// <summary> /// Retrieves the unwrapped agent commander from the scene. /// </summary> /// <returns>The tile grid instance (with no notion of monobehaviour).</returns> public AgentCommander GetInstance(TileGrid grid, DamageTable damageTable) { // Create the new commander and add it to the grid. AgentCommander commander = new AgentCommander(teamID, grid, damageTable, controller.GetInstance(grid)) { ThoughtTime = thoughtTime }; grid.Commanders.Add(commander); // Destroy this script's Monobehaviour baggage, // and return the lightweight instance. Destroy(this); return(commander); }
public Selector() { options = new ComboBox() { VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(2) }; Content = options; TileGrid.SetColumnSpan(this, 3); TileGrid.SetRowSpan(this, 1); PropertyChanged += SendableChooserControl_PropertyChanged; SourceChanged += SendableChooserControl_SourceChanged; }
public SpecialLevel(int roomNumber, string name, bool saved = false) { drawSaveText = saved; firstTime = true; //Adding the player and grid player = new Player(Vector3.Zero); player.Parent = this; tileGrid = LoadLevel(name); tileGrid.Parent = this; gameObjects.Add(tileGrid); player.LoadContent(); gameObjects.Add(player); //Setting the roomcounter roomCounter = new TextGameObject("text"); roomCounter.text = roomNumber.ToString(); //Adding the hanging man if (roomCounter.text == "100") { BillBoard man = new BillBoard(new Vector3(700, 210, 200)); man.Parent = this; gameObjects.Add(man); } if (drawSaveText) { saveText = new TextGameObject("text"); saveText.text = "Progress Saved"; saveText.Position = new Vector2((GameEnvironment.Screen.X - saveText.Size.X) / 2, 0); } if (name == "Content\\Special Levels\\Final.txt") { exitText.text = "Press E to kill yourself"; } else { exitText.text = "Press E to proceed"; } //Adding the roomcounter gameObjects.Add(roomCounter); //Adding stamina stamina = new Stamina(); stamina.Parent = this; gameObjects.Add(stamina); }
public HashSet <Tile> GetAvailableTargets(Tile tile) { Unit u = GetComponent <Unit>(); HashSet <Unit> units = UnitManager.Instance.GetUnitsByHostility(u); HashSet <Tile> ret = new HashSet <Tile>(); foreach (Unit e in units) { if (TileGrid.GetDelta(u, e) < 5) { ret.Add(e.Tile); } } return(ret); }
public Commander[] GetAllPreplacedCommanders(TileGrid onGrid, DamageTable damageTable) { List <Commander> foundCommanders = new List <Commander>(); foreach (AgentCommanderInstance agentCommander in Object.FindObjectsOfType <AgentCommanderInstance>()) { foundCommanders.Add(agentCommander.GetInstance(onGrid, damageTable)); } foreach (PlayerCommanderInstance playerCommander in Object.FindObjectsOfType <PlayerCommanderInstance>()) { foundCommanders.Add(playerCommander.GetInstance(onGrid)); } return(foundCommanders.ToArray()); }
// Start is called before the first frame update void Start() { city = GameObject.Find("City").GetComponent <City>(); pathfinder = GameObject.Find("Pathfinder").GetComponent <Pathfinding>(); grid = GameObject.Find("Grid").GetComponent <TileGrid>(); GameObject goUnit = Instantiate(unitPrefab); goUnit.transform.position = new Vector3(0, 0, 0); TileCell unitsCell = grid.cells.First(p => p.x == 0 && p.y == 0); unitsCell.SetUnit(goUnit); goUnit.GetComponent <Unit>().SetTileCell(unitsCell); units.Add(goUnit.GetComponent <Unit>()); grid.DiscoverArea(unitsCell, 2); grid.RenderTileUI(); }
public static GameObject GenerateGameObject(LevelData saveData) { TileGrid map = new TileGrid(saveData); LevelBlueprint l = Assets.Get(saveData.environment); Vector2Int textureSize = new Vector2Int( l.texture.width / saveData.pixelsPerTile, l.texture.height / saveData.pixelsPerTile ); Mesh mesh = GenerateMesh(map, textureSize); DynamicMesh dm = new GameObject().AddComponent <DynamicMesh> (); dm.CreateMesh(mesh, l.texture, l.mat); return(dm.gameObject); }
void Awake() { maxSize = MaxGridSize; if (instance == null) { instance = this; // put initiation code here! tiles = new Tile[maxSize, maxSize]; tilesSet = new HashSet <Tile>(); } else { Destroy(gameObject); } }
// Use this for initialization void Start() { //Create Hit check table for the turn radius(es?) here. this.activatedX = this.tileX; this.activatedY = this.tileY; TileGrid.Instance().AddToGrid(this); CurrentMoveDistance = MaxMoveDistance; var go = GameObject.FindGameObjectWithTag("GameEventSystem"); gameEventSystem = go.GetComponent <GameEventSystem>(); // gameEventSystem.Subscribe(this.gameObject, GameEventType.SpeedChanged, DiscreteSpeedChanged); }
public static IPropagatorBlock<int[], TileRange> CreateTileChildRangePropagatorBlock(TileGrid grid) { var source = new BufferBlock<TileRange>(); var target = new ActionBlock<int[]>((coord) =>{ source.Post(grid.GetTileCoordChildTileRange(coord)); }); // When the target is set to the completed state, propagate out any // remaining data and set the source to the completed state. target.Completion.ContinueWith(delegate { source.Complete(); }); return DataflowBlock.Encapsulate(target, source); }
protected void Awake() { m_gridScreenPos = m_screenOffset; if( m_centerGridScreen ) { m_gridScreenPos.x += ( ( Screen.width - ( m_gridWidth * TILE_SIZE ) ) / 2 ); m_gridScreenPos.y += ( ( Screen.height - ( m_gridHeight * TILE_SIZE ) ) / 2 ); } m_grid = new TileGrid( m_gridWidth, m_gridHeight ); m_lastSeenSolutions = m_grid.GetPossibleSolutions(); if( m_grid == null ) { Debug.LogError( "Failed to create TileGrid." ); enabled = false; return; } }
public SpecialLevel(int roomNumber, string name, bool saved = false) { drawSaveText = saved; firstTime = true; //Adding the player and grid player = new Player(Vector3.Zero); player.Parent = this; tileGrid = LoadLevel(name); tileGrid.Parent = this; gameObjects.Add(tileGrid); player.LoadContent(); gameObjects.Add(player); //Setting the roomcounter roomCounter = new TextGameObject("text"); roomCounter.text = roomNumber.ToString(); //Adding the hanging man if (roomCounter.text == "100") { BillBoard man = new BillBoard(new Vector3(700, 210, 200)); man.Parent = this; gameObjects.Add(man); } if (drawSaveText) { saveText = new TextGameObject("text"); saveText.text = "Progress Saved"; saveText.Position = new Vector2((GameEnvironment.Screen.X - saveText.Size.X) / 2, 0); } if (name == "Content\\Special Levels\\Final.txt") exitText.text = "Press E to kill yourself"; else exitText.text = "Press E to proceed"; //Adding the roomcounter gameObjects.Add(roomCounter); //Adding stamina stamina = new Stamina(); stamina.Parent = this; gameObjects.Add(stamina); }
public void init(int level){ if( dungeonPrefab == null )return; this.level = level; rectangles = new List<GameObject>(); Rooms = new List<GameObject>(); if (rootDungeon != null) { context.DestroyObj (rootDungeon); } rootDungeon = context.InstantiateObj (dungeonPrefab); rootDungeon.GetComponent<Rectangle>().setRectangle( WorldSize, WorldSize, level ); if (Grid == null) { Grid = new TileGrid (WorldSize, WorldSize); } else { Grid.rebuild (WorldSize,WorldSize); } rectangles.Add (rootDungeon); generate(); }
void BuildTexture( TileGrid grid ){ int textWidth = size_x * tileResolution; int textHeight = size_y * tileResolution; // = 50 *10 Color[][] tiles = ChopUpTiles(); Texture2D texture = new Texture2D(textWidth, textHeight); for( int y = 0; y < size_y; y++ ){ for( int x = 0; x < size_x; x++ ){ Color[] c = tiles[grid.getTileType(x,y)]; texture.SetPixels(x * tileResolution, y * tileResolution, tileResolution, tileResolution, c); } } texture.filterMode = FilterMode.Point; texture.wrapMode = TextureWrapMode.Clamp; texture.Apply(); MeshRenderer mesh_renderer = GetComponent<MeshRenderer>(); mesh_renderer.sharedMaterials[0].mainTexture = texture; }
internal TileLayer(string name, int width, int height, bool visible, float opacity, PropertyCollection properties, Map map, int[] data, bool makeUnique) : base(name, width, height, visible, opacity, properties) { Tiles = new TileGrid(width, height); // data is left-to-right, top-to-bottom for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { int index = data[y * width + x]; // get the tile Tile t = map.Tiles[index]; // if the tile is non-null and we want unique instances, clone it. if (t != null && makeUnique) t = t.Clone(); // put that tile in our grid Tiles[x, y] = t; } } }
public void Setup(int xSize, int ySize) { Awake(); gridSizeX = xSize; gridSizeY = ySize; betterGrid = new TileGrid(); betterGrid.column = new TileGrid.TileList[xSize]; for (int i = 0; i < xSize; ++i) { betterGrid.column[i] = new TileGrid.TileList(); betterGrid.column[i].row = new Tile[ySize]; } GenerateGrid(); }
/// <summary> /// Loads the level's grid of tiles /// </summary> /// <param name="name">The name of the file from which to open the level</param> /// <returns>Returns the TileGrid filled with the complete level</returns> private TileGrid LoadLevel(string name) { List<string> text = new List<string>(); TileGrid tileGrid; using (StreamReader streamReader = new StreamReader(name)) { string line = streamReader.ReadLine(); int width = line.Length; //read the file while (line != null) { text.Add(line); line = streamReader.ReadLine(); } //make a grid for the tiles tileGrid = new TileGrid(width + 1, text.Count + 1, "TileGrid"); //Load the tiles into the grid for (int x = 0; x < width; ++x) { for (int y = 0; y < text.Count; ++y) { Tile tile = LoadTile(text[y][x], x, y, name); if (tile != null) { tileGrid.Add(tile, x, y); if (tile is WallTile) { tile.Position += new Vector3(0, 200, 0); } } } } } return tileGrid; }
protected void CreateNote(NoteObject note, TileGrid tileGrid) { for (int x = 0; x < tileGrid.Columns; x++) { for (int y =0; y < tileGrid.Rows; y++) { if (tileGrid.Get(x, y) != null && tileGrid.Get(x, y) is WallTile) { if(tileGrid.Get(x + 1, y) is PathTile) { note.Position = tileGrid.Get(x, y).Position + new Vector3(102/*100+modelDepth*/, 0, 0); } else if(tileGrid.Get(x, y + 1) is PathTile) { note.Position = tileGrid.Get(x, y).Position + new Vector3(0, 0, 102); } else if(tileGrid.Get(x - 1, y) is PathTile) { note.Position = tileGrid.Get(x, y).Position - new Vector3(102, 0, 0); } else if(tileGrid.Get(x, y - 1)is PathTile) { note.Position = tileGrid.Get(x, y).Position - new Vector3(0, 0, 102); } } } } }
public void LoadContent() { level = parent as Level; grid = level.Find("TileGrid") as TileGrid; stamina = 2000; }
/// <summary> /// Clones this instance. /// </summary> public TileGrid Clone() { TileGrid tileGrid = new TileGrid(Width, Height); for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { tileGrid[x, y] = this[x, y].Clone(); } } return tileGrid; }
public TileQuery() { grid = GameObject.Find ("grid").GetComponent<TileGrid>(); }