public static Entity GetFoodPellet(Color color) { float radius = 10f; var foodEntity = new Entity("food"); var transform = new TransformComponent(foodEntity) { LocalPosition = Vector2.Zero, LocalRotation = new Rotation(0), LocalDepth = 0.09f, Scale = new Vector2(1, 1) }; var graphics = new GraphicsComponent(foodEntity) { TexturePath = TextureAtlas.SoupPath, Dimensions = new Point((int)(radius * 2), (int)(radius * 2)), Color = color }; var colourComp = new VisibleColourComponent(foodEntity) { RealR = 0.9f, RealB = 0.05f, RealG = 0.05f, }; var energy = new EnergyComponent(foodEntity) { Energy = 3 }; var edible = new EdibleComponent(foodEntity) { }; var collider = new CircleColliderComponent(foodEntity) { Radius = radius, }; foodEntity.AddComponents(transform, graphics, energy, edible, collider, colourComp); return(foodEntity); }
private void LoadEntities() { throw new NotImplementedException(); int entitesCount = _savedComponents.Positions.Length; int?firstEntityIndex = null; _context.ReplacePlayerEntity(_savedComponents.PlayerEntityId); for (int i = 0; i < entitesCount; i++) { GameEntity entity = _context.CreateEntity(); if (!firstEntityIndex.HasValue) { firstEntityIndex = entity.creationIndex; } int currentEntityIndex = entity.creationIndex; int componentIndex = currentEntityIndex - firstEntityIndex.Value; IdComponent savedId = _savedComponents.Ids[componentIndex]; entity.ReplaceId(savedId.Id); bool[] componentPresence = _savedComponents.EntityToHasComponent[savedId.Id]; PositionComponent savedPosition = _savedComponents.Positions[componentIndex]; if (componentPresence[GameComponentsLookup.Position]) { entity.AddPosition(savedPosition.Position); entity.AddPositionAfterLastTurn(default(Position)); } VisionComponent savedVision = _savedComponents.Visions[componentIndex]; if (componentPresence[GameComponentsLookup.Vision]) { entity.AddVision(savedVision.VisionRange, savedVision.PerceptionRange, savedVision.EntitiesNoticed ?? new HashSet <Guid>()); } RecipeeComponent savedRecipee = _savedComponents.Recipees[componentIndex]; if (componentPresence[GameComponentsLookup.Recipee]) { entity.AddRecipee(savedRecipee.RecipeeName); } EnergyComponent savedEnergy = _savedComponents.Energies[componentIndex]; if (componentPresence[GameComponentsLookup.Energy]) { entity.AddEnergy(savedEnergy.EnergyGainPerSegment, savedEnergy.Energy); } IntegrityComponent savedIntegrity = _savedComponents.Integrities[componentIndex]; if (componentPresence[GameComponentsLookup.Integrity]) { entity.AddIntegrity(savedIntegrity.Integrity, savedIntegrity.MaxIntegrity); } SkillsComponent savedSkill = _savedComponents.Skills[componentIndex]; if (componentPresence[GameComponentsLookup.Skills]) { entity.AddSkills(savedSkill.Skills); } StomachComponent savedStomach = _savedComponents.Stomachs[componentIndex]; if (componentPresence[GameComponentsLookup.Stomach]) { entity.AddStomach(savedStomach.Satiation, savedStomach.MaxSatiation); } TeamComponent savedTeam = _savedComponents.Teams[componentIndex]; if (componentPresence[GameComponentsLookup.Team]) { entity.AddTeam(savedTeam.Team); } LooksComponent savedLooks = _savedComponents.Looks[componentIndex]; if (componentPresence[GameComponentsLookup.Looks]) { entity.AddLooks(savedLooks.BodySprite); } EdibleComponent savedEdible = _savedComponents.Edibles[componentIndex]; if (componentPresence[GameComponentsLookup.Edible]) { entity.AddEdible(savedEdible.Satiety); } if (componentPresence[GameComponentsLookup.BlockingPosition]) { entity.isBlockingPosition = true; } entity.isFinishedTurn = true; if (_context.playerEntity.Id == entity.id.Id) { entity.isPlayerControlled = true; } } }