// Use this for initialization void Start() { _worldModel = new HexWorld(_wordWidth, _worldHeight); _playerColony = new Colony(0, "test colony"); _worldModel.AddColony(_playerColony); // add unity objects to each cell _worldModel.ForEachPosition((coord) => { GameObject creatureCube = CreateCube(coord, new Vector3(_renderedCellSize / 2, _renderedCellSize / 2, _renderedCellSize)); GameObject hormoneCube = CreateCube(coord, new Vector3(_renderedCellSize, _renderedCellSize, _renderedCellSize * 0.3f)); _creatureCubes.Add(coord, creatureCube); _hormoneCubes.Add(coord, hormoneCube); }); // test dummy data _worldModel.AddCreatures(_playerColony, new Coord(3, 0), 4000); _worldModel.AddCreatures(_playerColony, new Coord(3, 1), 3000); _worldModel.AddCreatures(_playerColony, new Coord(3, 2), 2000); _worldModel.AddCreatures(_playerColony, new Coord(3, 3), 1000); _playerColony.HormoneTotemPosition = new Coord(6, 4); // end dummy data }
public HexTile(HexWorld hexGen, int x, int y) { helper = new Helper(); this.hexWorld = hexGen; this.x = x; this.y = y; tilePosition = getTransform(); PopulateNeighbours(); }
// ------------------------------------------------------- Other Functions void Initialize() { if (!hexWorld) { hexWorld = GetComponent <HexWorld>(); } if (!cameraTx) { cameraTx = Camera.main.transform; } }
public void SetUp() { _testColony = new Colony(0, "test colony"); _worldModel = new HexWorld(width, height); // test dummy data _worldModel.AddColony(_testColony); _worldModel.AddCreatures(_testColony, new Coord(1, 1), 30); _worldModel.AddCreatures(_testColony, new Coord(0, 0), 10); _worldModel.AddCreatures(_testColony, new Coord(2, 2), 40); _worldModel.AddCreatures(_testColony, new Coord(3, 3), 30); _worldModel.AddMoveHormone(_testColony, new Coord(1, 1), 3); _worldModel.AddMoveHormone(_testColony, new Coord(1, 0), 5); _worldModel.AddMoveHormone(_testColony, new Coord(2, 0), 35); // end dummy data }
// Use this for initialization void Start() { // Initialize empty texture mouseHexTex = new Texture2D(TextureWidth, TextureHeight, TextureFormat.RGB24, false); whiteTex = new Texture2D(TextureWidth, TextureHeight, TextureFormat.RGB24, true); blackTex = new Texture2D(TextureWidth, TextureHeight, TextureFormat.RGB24, true); falloffTex = new Texture2D(16, 1, TextureFormat.RGBA32, false); falloffTex.alphaIsTransparency = true; falloffTex.SetPixel(0, 0, Color.black); Color[] black = new Color[(TextureWidth * TextureHeight)]; for (int i = 0; i < black.Length; i++) { black[i] = new Color(0, 0, 0); } mouseHexTex.SetPixels(0, 0, TextureWidth, TextureHeight, black); hexWorld = new HexWorld(width, height); for (int x = 0; x < hexWorld.Width; x++) { for (int y = 0; y < hexWorld.Height; y++) { HexTile hexTile_data = hexWorld.GetHexTileAt(x, y); GameObject hexTile_go = GameObject.CreatePrimitive(PrimitiveType.Cylinder); hexTile_go.transform.position = hexTile_data.tilePosition; hexTile_go.transform.localScale = new Vector3(1, 0.1f, 1); } } //genMouseHexTex.SetRadius(32f, 48f); //genMouseHexTex.SetColor( Color.black, Color.black ); genMouseHexTex.Generate(mouseHexTex, LineDrawer.LineWidth.Medium, LineDrawer.LineWidth.Medium); mouseHexTex.wrapMode = TextureWrapMode.Clamp; mat = new Material(Shader.Find("Projector/Light")); //mat = new Material( Shader.Find( "Projector/Multiply" ) ); mat.SetTexture("_ShadowTex", mouseHexTex); mat.SetTexture("_FalloffTex", falloffTex); mat.SetColor("_Color", Color.red); projector.material = mat; }
// Use this for initialization void Start() { // We start the game instance _map = new Map(GridWidth, GridHeight, 2); // We obtain the hex -> world transformation SpriteRenderer spriteRenderer = HexagonPrefab.GetComponent <SpriteRenderer>(); Bounds spriteBounds = spriteRenderer.sprite.bounds; Vector3 hexagonExtents = spriteBounds.extents; _world = new HexWorld(hexagonExtents.x); // We instance the main object _gridObject = new GameObject("Grid"); _gridObject.transform.parent = WorldPrefab; Transform mainTransform = _gridObject.transform; _grid = new Transform[GridWidth * GridHeight]; // We instantiate the prefabs Vector3 hexCoords = Vector3.zero; for (int hY = 0; hY < GridHeight; ++hY) { for (int hX = 0; hX < GridWidth; ++hX) { if (_map.GetHexagon(hX, hY) == null) { continue; } hexCoords.x = hX; hexCoords.y = hY; Vector3 hexPosition = HexCoordsUtils.HexToWorld(_world, hexCoords); Transform t = (Transform)Instantiate(HexagonPrefab, hexPosition, Quaternion.identity); t.parent = mainTransform; // We store it in the array _grid[GridWidth * hY + hX] = t; } } // We instantiate the characters _entitiesObject = new GameObject("Entities"); _entitiesObject.transform.parent = WorldPrefab; List <Entity> entities = _map.GetEntities(); // We recycle hexCoords hexCoords = Vector3.zero; foreach (Entity entity in entities) { hexCoords.x = entity.Hexagon.X; hexCoords.y = entity.Hexagon.Y; Vector3 entityPos = HexCoordsUtils.HexToWorld(_world, hexCoords); entityPos.z = -1f; Transform t = (Transform)Instantiate(CharacterPrefab, entityPos, Quaternion.identity); t.parent = _entitiesObject.transform; EntityScript entityScriptInstance = t.GetComponent <EntityScript>(); entityScriptInstance.Entity = entity; } }