public static Dictionary <Vector2Int, TileContainer> InitialWorld(DataStore store) { Dictionary <Vector2Int, TileContainer> world = new Dictionary <Vector2Int, TileContainer>(); for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { Vector2Int position = new Vector2Int(x, y); if (position == new Vector2Int(1, 1)) { world.Add(position, new TileContainer(store.Get <TerrainEntity>("grassTile"), store.Home)); } else { List <Vector2Int> grassPosition = new List <Vector2Int> { new Vector2Int(0, 0), new Vector2Int(1, 0), new Vector2Int(2, 0), }; TerrainEntity terrain = store.Get <TerrainEntity>(grassPosition.Contains(position) ? "grassTile" : "dirtTile"); BuildingIncarnation building = null; GrowableIncarnation growable = terrain.Growable != null && building == null ? new GrowableIncarnation(terrain.Growable.Entity) : null; world.Add(position, new TileContainer(terrain, growable, building)); } } } return(world); }
public Transform this[TerrainEntity ent] { get { return(termap[ent]); } }
public TileContainer(TerrainEntity terrain, GrowableIncarnation growable, BuildingIncarnation building) { this.specialEntity = null; this.terrain = terrain; this.growable = growable; this.building = building; }
public TileContainer(TerrainEntity terrain, ISpecialEntity special) { this.specialEntity = special; this.terrain = terrain; this.growable = null; this.building = null; }
private void GenerateMapWithPerlin(ContentManager contentManager) { for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { int terrainID = Convert.ToInt32(GameDepth.TERRAIN); double noise = noiseGen.GetNoise(x, y, terrainID); //int terrainType = (int)(14.0 * noise); int tileIdx = getEntityIndex(x, y, terrainID); if (noise <= 0.3f) { this.terrain[tileIdx] = new Tree(); } else if (noise <= 0.3f && noise < 0.6f) { this.terrain[tileIdx] = new River(); } else if (noise <= 0.6f && noise < 0.9f) { this.terrain[tileIdx] = new Ground(); } else { this.terrain[tileIdx] = new Wheat(); } TerrainEntity tEntity = this.terrain[tileIdx]; tEntity.LoadContent(contentManager); tEntity.Position = new Vector2(x, y); } } }
public Transform CreateTile(TerrainEntity terEnt, TilePosition posinfo) { var pos = posinfo.Point; var tileobj = (Transform)Instantiate(TerrainTemplate, new Vector3(-(float)pos.X, (float)pos.Y), TerrainTemplate.rotation); gameobjLookUp.Add(terEnt, tileobj.gameObject); return(tileobj); }
/// <summary> /// Converts the domain model into an entity. /// </summary> /// <returns>The entity.</returns> /// <param name="terrain">Texture.</param> internal static TerrainEntity ToEntity(this Terrain terrain) { TerrainEntity textureEntity = new TerrainEntity { Id = terrain.Id, Name = terrain.Name, Description = terrain.Description, ColourHexadecimal = terrain.Colour.ToHexadecimal() }; return(textureEntity); }
/// <summary> /// Converts the entity into a domain model. /// </summary> /// <returns>The domain model.</returns> /// <param name="textureEntity">Texture entity.</param> internal static Terrain ToDomainModel(this TerrainEntity textureEntity) { Terrain terrain = new Terrain { Id = textureEntity.Id, Name = textureEntity.Name, Description = textureEntity.Description, Colour = ColourTranslator.FromHexadecimal(textureEntity.ColourHexadecimal) }; return(terrain); }
public TextCell GetLook(TerrainEntity entity) { var appleEntity = entity as AppleEntity; var color = (appleEntity.Type == AppleEntity.AppleType.Normal) ? Color16.Lime : Color16.Red; if (appleEntity.IsDying && appleEntity.DelayBeforeDie.RemainingTicks % 2 == 0) // blinking { color = Color16.DarkRed; } return(new TextCell('o', color, Color16.Black)); }
private void OnTerrainEntity(EntityAddedEvent evt) { TerrainEntity terEnt = (TerrainEntity)evt.AddedXmasEntity; TilePosition posinfo = (TilePosition)evt.AddedPosition; Point pos = posinfo.Point; var transform = Factory.CreateTile(terEnt, posinfo); transform.gameObject.AddComponent <TerrainInformation>(); var terinfo = transform.gameObject.GetComponent <TerrainInformation>(); terinfo.SetTerrain(terEnt); this.termap[terEnt] = transform; transform.renderer.sharedMaterial.SetTexture("_MainTex", TextureDictionary.GetTexture(terEnt.TextureType)); }
private void Btn_AddTerrainClick(object sender, EventArgs e) { try { EntityUIForm lightobj = new EntityUIForm(); EntityUIForm skyobj = new EntityUIForm(); TerrainEntity heightfield = new TerrainEntity(HeightBox.Text, MeshBox.Text, new MaterialProperties("ground", 0.2f, 1.0f, 0.2f)); var light = lightobj.CreateEntity(new Vector3(), null, EntityUIForm.Entities.LightSourceEntity); var sky = skyobj.CreateEntity(new Vector3(), null, EntityUIForm.Entities.SkyDomeEntity); SimulationEngine.GlobalInstancePort.Insert(heightfield); SimulationEngine.GlobalInstancePort.Insert(light); } catch { } }
public TextCell GetLook(TerrainEntity entity) { var color = (entity as SnakeBodyPartEntity).IsHead ? Color16.White : Color16.Red; return(new TextCell('X', color, Color16.Black)); }
public override object Clone() { TerrainEntity entity = new TerrainEntity(this.tile); return entity; }
public void SetTerrain(TerrainEntity entity) { this.entity = entity; }
private static Tile GenerateTile(Point position) { Tile tile = new Tile(position, map.TileSize); int rNumber = rand.Next(100); int chance = 30; if (rNumber < chance) { TerrainEntity rockEntity = new TerrainEntity(tile); Texture2D texture = rock; Rectangle destinationRectangle = tile.Rect; Rectangle sourceRectangle = Rectangle.Empty; if (texture == null) { sourceRectangle = Rectangle.Empty; } rockEntity.SetDrawData(texture, destinationRectangle, sourceRectangle, 0.5f); rockEntity.IsBlocked = true; tile.AddEntity(rockEntity); } TerrainEntity terrainEntity = new TerrainEntity(tile); rNumber = rand.Next(100); chance = 80; if (rNumber < chance) { Texture2D texture2 = tile_green; Rectangle destinationRectangle2 = tile.Rect; Rectangle sourceRectangle2 = Rectangle.Empty; if (texture2 == null) { sourceRectangle2 = Rectangle.Empty; } terrainEntity.SetDrawData(texture2, destinationRectangle2, sourceRectangle2, 0.2f); } else { Texture2D texture3 = tile_brown; Rectangle destinationRectangle3 = tile.Rect; Rectangle sourceRectangle3 = Rectangle.Empty; if (texture3 == null) { sourceRectangle3 = Rectangle.Empty; } terrainEntity.SetDrawData(texture3, destinationRectangle3, sourceRectangle3, 0.2f); } tile.AddEntity(terrainEntity); //tile.MapIndex = map.AddTile(tile); return tile; }
private void editorControl1_MouseDown(object sender, MouseEventArgs e) { STATIC_GLOBAL_INPUT.HandleMouseButtons(e, true); switch (editorControl1.Gizmo.ActiveMode) { case GizmoMode.Placement: { if (tabControl1.SelectedTab == tabPage1) { // we are on the model page if (e.Button == MouseButtons.Left) { if (listBox_Models.SelectedItem != null) { if (IsValidContentFile(@"Models\" + listBox_Models.SelectedItem, typeof(Model))) { BoundingBox bb = new BoundingBox(); var useTerrain = false; var terrains = STATIC_EDITOR_MODE.LevelInstance.Entities.Where(entity => entity is TerrainEntity).ToList(); if (terrains.Count > 0) { bb = terrains[0].BoundingBox; terrains.Remove(terrains[0]); useTerrain = true; foreach (var terrain in terrains) { bb = BoundingBox.CreateMerged(bb, terrain.BoundingBox); } } terrains = null; var rayHitPos = RayHelpers.GetHitPoint(editorControl1.ray, (useTerrain? bb : Grid3D.BB)); if (rayHitPos != null) { var fileName = listBox_Models.SelectedItem.ToString(); var obj = STATIC_EDITOR_MODE.contentMan.Load <object>(Path.Combine("Models", fileName)); var se = new SceneEntity(obj as Model, fileName) { Position = (Vector3)rayHitPos }; se.LoadAsset(STATIC_EDITOR_MODE.contentMan); Engine.Entities.Add(se); STATIC_EDITOR_MODE.LevelInstance.Entities.Add(se); AddTreeNodeFromSceneEntity(se, hierarchyTreeView); editorControl1.SetSelectionTo(se); } } } else { MessageBox.Show("This is not a Model asset", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } else if (tabControl1.SelectedTab == tabPage2) { // we are on the texture page if (listBox_Heights.SelectedItem != null) { if (IsValidContentFile(@"HeightMaps\" + listBox_Heights.SelectedItem, typeof(Texture2D))) { // ?? to a default position var rayHitPos = RayHelpers.GetHitPoint(editorControl1.ray, Grid3D.BB) ?? new Vector3(0, 0, 0); var fileName = listBox_Heights.SelectedItem.ToString(); var obj = STATIC_EDITOR_MODE.contentMan.Load <object>(Path.Combine("HeightMaps", fileName)); var se = new TerrainEntity(obj as Texture2D, fileName) { Position = rayHitPos }; se.LoadAsset(STATIC_EDITOR_MODE.contentMan); //remove all terrains //Engine.Entities.RemoveAll(entity => entity is TerrainEntity); Engine.Entities.Add(se); STATIC_EDITOR_MODE.LevelInstance.Entities.Add(se); //STATIC_EDITOR_MODE.LevelInstance.Terrain = se; // rebuild the tree PopulateHeirarchy(); editorControl1.SetSelectionTo(se); } } } break; } } }