public void TestSetup() { _eventsFired = EventFlags.None; _registry = new TileRegistry(_service.GraphicsDevice); _pool = new TilePool("pool", _registry, 16, 16); Texture2D tex1 = new Texture2D(_service.GraphicsDevice, 16, 16); Texture2D tex2 = new Texture2D(_service.GraphicsDevice, 16, 16); _tile1 = _pool.GetTile(_pool.AddTile(tex1)); _tile2 = _pool.GetTile(_pool.AddTile(tex2)); }
public void ModifyTileTextureDirect() { Texture2D tex1 = RandomTexture(16, 16); Texture2D tex2 = RandomTexture(16, 16); Assert.IsFalse(TexturesEqual(tex1, tex2)); int id = _pool.AddTile(tex1); _eventsFired = EventFlags.None; _pool.TileModified += (s, e) => { Assert.AreEqual(_pool, e.Tile.Pool); Assert.AreEqual(id, e.Tile.Uid); Assert.IsTrue(TexturesEqual(tex2, e.Tile.Pool.GetTileTexture(id))); }; byte[] data = new byte[16 * 16 * 4]; tex2.GetData(data); Tile tile = _pool.GetTile(id); tile.Update(data); Assert.AreEqual(EventFlags.Modified | EventFlags.TileModified, _eventsFired); Assert.AreEqual(1, _registry.TileCount); Assert.AreEqual(1, _pool.Count); }
public void RemoveTileNotPresentTest() { TileStack stack = new TileStack(); stack.Add(_tile1); stack.Add(_tile2); AttachEvents(stack); Texture2D texture = new Texture2D(_service.GraphicsDevice, 16, 16); Tile tile3 = _pool.GetTile(_pool.AddTile(texture)); stack.Remove(tile3); Assert.AreEqual(EventFlags.None, _eventsFired); Assert.AreEqual(2, stack.Count); Assert.AreEqual(_tile1, stack[0]); Assert.AreEqual(_tile2, stack[1]); }
private void UpdateTiles(int x, int y) { for (int i = Mathf.Max(0, x - 30); i < Mathf.Min(mapWidth * 10, x + 30); i++) { for (int j = Mathf.Max(0, y - 30); j < Mathf.Min(mapHeight * 10, y + 30); j++) { if (i < x - 20 || i > x + 20 || j < y - 20 || j > y + 20) { if (tileMapTiles[i, j] != null) { tilePool.ReplaceTile(tileMap[i, j], tileMapTiles[i, j]); tileMapTiles[i, j] = null; } } else { if (tileMapTiles[i, j] == null) { tileMapTiles[i, j] = tilePool.GetTile(tileMap[i, j]); tileMapTiles[i, j].transform.position = new Vector3(i - mapWidth * 5, -j, 1); } } if (i < x - 10 || i > x + 10 || j < y - 10 || j > y + 10) { if (enemyMapCreatures[i, j] != null) { creaturePool.ReplaceCreature(0, enemyMapCreatures[i, j]); enemyMapCreatures[i, j] = null; } } else { if (enemyMap[i, j] >= 0 && enemyMapCreatures[i, j] == null) { enemyMapCreatures[i, j] = creaturePool.GetCreature(enemyMap[i, j]); enemyMapCreatures[i, j].transform.position = new Vector3(i - mapWidth * 5, -j, 1); enemyMapCreatures[i, j].MultiplyHealth(Mathf.Max(1, (int)((j - 3) / 10))); } } } } }
public TileSelection GetAsTileSelection(Project project, int tileWidth, int tileHeight) { Dictionary <TileCoord, TileStack> xlat = new Dictionary <TileCoord, TileStack>(); foreach (KeyValuePair <TileCoord, Guid[]> item in _tiles) { TileStack stack = new TileStack(); foreach (Guid tileId in item.Value) { TilePool pool = project.TilePoolManager.PoolFromItemKey(tileId); Tile tile = pool.GetTile(tileId); stack.Add(tile); } xlat.Add(item.Key, stack); } TileSelection selection = new TileSelection(tileWidth, tileHeight); selection.AddTiles(xlat); return(selection); }