public void MakeCrittersTest() { WorldMaker testBang = new WorldMaker(); List <char[]> testList = new List <char[]>() { { new char[] { '4', ' ', 'y', '9' } }, { new char[] { } }, { new char[] { 'h', '[', ' ' } }, { new char[] { ' ', ' ', ' ' } } }; Organism[,] actual = testBang.MakeCritters(testList); Assert.AreEqual('4', actual[1, 1].Body); Assert.AreEqual(null, actual[0, 0]); Assert.AreEqual(null, actual[5, 5]); Assert.AreEqual(null, actual[0, 5]); Assert.AreEqual(null, actual[5, 0]); Assert.AreEqual(null, actual[0, 3]); Assert.AreEqual(null, actual[2, 0]); Assert.AreEqual('[', actual[3, 2].Body); Assert.AreEqual(' ', actual[2, 3].Body); Assert.AreEqual(' ', actual[2, 1].Body); Assert.AreEqual(' ', actual[3, 4].Body); Assert.AreEqual(' ', actual[4, 2].Body); }
private void Start() { world = NetBridge.Instance.world; transform.position = world.GetPlayerSpawn(); if (isLocalPlayer || isServer) { chatUIManager.enabled = true; } if (!isLocalPlayer) { cam.enabled = false; ls.enabled = false; Destroy(playerUI); renderer.material.color = myColor; nameTag.text = charName; } else { myColor = NetBridge.Instance.localPlayerColor; CmdSetColor(myColor); charName = NetBridge.Instance.avatarName; CmdSetName(charName); playerUI.SetActive(true); lastVerifiedState.pos = transform.position; lastVerifiedState.eulerAvatar = avatar.eulerAngles; lastVerifiedState.eulerCam = camTrans.eulerAngles; lastVerifiedState.yvel = yvel; lastVerifiedState.id = packetId; lastVerifiedState.blockType = blockType; } }
void Start() { player = new Player("Player"); actors = new List <Actor> (); actors.Add(player); actors.Add(new AIActor()); currentActor = 0; pc = new GameObject("Player Camera").AddComponent <PlayerCamera> (); pc.init(this, Camera.main); this.l = new Layout(Orientation.Pointy, new Vector2(1, 1), new Vector2(0, 0)); w = new GameObject("World Map").AddComponent <WorldMap> (); w.init(l); int seed = Random.Range(1000000000, int.MaxValue); WorldMaker maker = new WorldMaker(w, player, seed, false); maker.genWorld(); var lookat = w.l.HexPixel(new HexLoc((int)maker.spawn.x, (int)maker.spawn.y)); pc.setLocation(lookat.x, lookat.y); w.PreTurn(null, actors[currentActor]); w.NewTurn(null, actors[currentActor]); w.PostTurn(null, actors[currentActor]); if (false) { foreach (KeyValuePair <HexLoc, Hex> kv in w.map) { kv.Value.reveal(); } } am = gameObject.AddComponent <AnnihilationManager>(); am.init(w, player); var obj = new GameObject("UI Manager"); obj.AddComponent <UIManager> ().init(this, player, w); //gameObject.AddComponent<UIManager> ().init (this, player, w); gameObject.AddComponent <AudioManager> ().init(this); gameObject.AddComponent <AmbienceManager>().init(pc, w); }
public void CountNeighborsTest() { WorldMaker testBang = new WorldMaker(); Organism[,] result = new Organism[6, 6] { { null, null, null, null, null, null }, { null, new Organism() { Body = '4' }, new Organism() { Body = ' ' }, new Organism() { Body = 'y' }, new Organism() { Body = '9' }, null }, { null, new Organism() { Body = 'r' }, new Organism() { Body = 't' }, new Organism() { Body = ' ' }, new Organism() { Body = 'h' }, null }, { null, new Organism() { Body = 'h' }, new Organism() { Body = '[' }, new Organism() { Body = ' ' }, new Organism() { Body = ' ' }, null }, { null, new Organism() { Body = ' ' }, new Organism() { Body = ' ' }, new Organism() { Body = ' ' }, new Organism() { Body = 'h' }, null }, { null, null, null, null, null, null } }; testBang.CountNeighbors(result); Assert.AreEqual(2, result[1, 1].NeighborCount); Assert.AreEqual(0, result[4, 4].NeighborCount); Assert.AreEqual(4, result[2, 1].NeighborCount); Assert.AreEqual(5, result[2, 3].NeighborCount); }
public void BuildMesh() { List <Vector3> vertices; List <int> triangles; List <Vector3> normals; List <Vector2> uv; int vertCount = cubeModel.cubeVertices.Length; int triCount = cubeModel.cubeTris.Length; int faceCount = vertCount / 4; vertices = new List <Vector3>(); triangles = new List <int>(); uv = new List <Vector2>(); normals = new List <Vector3>(); Vector3 blockpos; Vector3 cp = transform.position; WorldMaker world = NetBridge.Instance.world; for (int z = 0; z < chunkSize; ++z) { for (int y = 0; y < chunkSize; ++y) { for (int x = 0; x < chunkSize; ++x) { if (blocks[x + (y * chunkSize) + (z * chunkSize * chunkSize)] > 0) { blockpos.x = x; blockpos.y = y; blockpos.z = z; for (int i = 0; i < faceCount; ++i) { switch (i) { case 0: //front if (world.GetBlock(x + (int)cp.x, y + (int)cp.y, z + (int)cp.z + 1) > 0) { continue; } break; case 1: //back if (world.GetBlock(x + (int)cp.x, y + (int)cp.y, z + (int)cp.z - 1) > 0) { continue; } break; case 2: //top if (world.GetBlock(x + (int)cp.x, y + (int)cp.y + 1, z + (int)cp.z) > 0) { continue; } break; case 3: //bot if (world.GetBlock(x + (int)cp.x, y + (int)cp.y - 1, z + (int)cp.z) > 0) { continue; } break; case 4: //right if (world.GetBlock(x + (int)cp.x + 1, y + (int)cp.y, z + (int)cp.z) > 0) { continue; } break; case 5: //left if (world.GetBlock(x + (int)cp.x - 1, y + (int)cp.y, z + (int)cp.z) > 0) { continue; } break; default: break; } int blockType = GetBlock(x, y, z); float atlasXIncrement = 1.0f / cubeModel.atlasSize.x; float atlasYIncrement = 1.0f / cubeModel.atlasSize.y; for (int n = 0; n < 4; ++n) { vertices.Add(cubeModel.cubeVertices[n + i * 4] + blockpos); Vector2 uvpos = cubeModel.cubeUv[n + i * 4]; uvpos.x = uvpos.x * atlasXIncrement + ((blockType % cubeModel.atlasSize.x) + 1) * atlasXIncrement; uvpos.y = uvpos.y * atlasYIncrement + (cubeModel.atlasSize.x - 1 - (int)((blockType - 1) / cubeModel.atlasSize.x)) * atlasYIncrement; uv.Add(uvpos); normals.Add(cubeModel.cubeNormal[n + i * 4]); } triangles.Add(vertices.Count - 2); triangles.Add(vertices.Count - 3); triangles.Add(vertices.Count - 4); triangles.Add(vertices.Count - 4); triangles.Add(vertices.Count - 1); triangles.Add(vertices.Count - 2); } } } } } Mesh mesh = new Mesh(); filter.mesh = mesh; mesh.vertices = vertices.ToArray(); mesh.triangles = triangles.ToArray(); mesh.normals = normals.ToArray(); mesh.uv = uv.ToArray(); collider.sharedMesh = mesh; }