public override void Process(Entity e) { Damage d = e.GetComponent<Damage>(); Health h = e.GetComponent<Health>(); if (d.Seconds <= 0) { e.RemoveComponent<Damage>(d); e.Refresh(); return; } d.Seconds -= (float)world.Delta / 1000; h.SetHealth(e, h.CurrentHealth - d.DamagePerSecond * (world.Delta / 1000)); Sprite s = e.GetComponent<Sprite>(); Vector2 offset; if (!e.Tag.Contains("Boss")) { double mes = Math.Sqrt(s.CurrentRectangle.Width * s.CurrentRectangle.Height / 4); offset = new Vector2((float)((r.NextDouble() * 2 - 1) * mes), (float)((r.NextDouble() * 2 - 1) * mes)); } else { offset = new Vector2((float)((r.NextDouble() * 2 - 1) * s.CurrentRectangle.Width / 2), (float)((r.NextDouble() * 2 - 1) * s.CurrentRectangle.Height / 2)); } world.CreateEntity("GREENFAIRY", e, ConvertUnits.ToSimUnits(offset)).Refresh(); }
public void Process(Entity toProcess, GameTime gameTime) { if (!IsApplicableTo(toProcess)) { return; } // TODO pass this in so it can be controlled Random rand = new Random(); RandomPositionOffsetComponent offset = (RandomPositionOffsetComponent)toProcess.components[typeof(RandomPositionOffsetComponent)]; int minX = (int)Math.Min(offset.Maximum.X, offset.Minimum.X); int maxX = (int)Math.Max(offset.Maximum.X, offset.Minimum.X); int minY = (int)Math.Min(offset.Maximum.Y, offset.Minimum.Y); int maxY = (int)Math.Max(offset.Maximum.Y, offset.Minimum.Y); int x = rand.Next(minX, maxX); int y = rand.Next(minY, maxY); PositionDeltaComponent delta = new PositionDeltaComponent(); if (toProcess.components.ContainsKey(typeof(PositionDeltaComponent))) { delta = (PositionDeltaComponent)toProcess.components[typeof(PositionDeltaComponent)]; delta.Delta += new Vector2(x, y); } else { delta.Delta = new Vector2(x, y); toProcess.AddComponent(delta); } toProcess.RemoveComponent(offset); }
public override void Process(Entity e) { if (!e.HasComponent<Animation>()) return; Sprite sprite = e.GetComponent<Sprite>(); Animation anim = e.GetComponent<Animation>(); if (anim.Type != AnimationType.None) { anim._Tick += world.Delta; if (anim._Tick >= anim.FrameRate) { anim._Tick -= anim.FrameRate; switch (anim.Type) { case AnimationType.Loop: sprite.FrameIndex++; //Console.WriteLine("Animation happened"); break; case AnimationType.ReverseLoop: sprite.FrameIndex--; break; case AnimationType.Increment: sprite.FrameIndex++; anim.Type = AnimationType.None; break; case AnimationType.Decrement: sprite.FrameIndex--; anim.Type = AnimationType.None; break; case AnimationType.Bounce: sprite.FrameIndex += anim.FrameInc; if (sprite.FrameIndex == sprite.Source.Count() - 1) anim.FrameInc = -1; if (sprite.FrameIndex == 0) anim.FrameInc = 1; break; case AnimationType.Once: if (sprite.FrameIndex < sprite.Source.Count() - 1) sprite.FrameIndex++; else anim.Type = AnimationType.None; break; } e.RemoveComponent<Sprite>(e.GetComponent<Sprite>()); e.AddComponent<Sprite>(sprite); } } }
public override void Process(Entity e) { Slow slow = slowMapper.Get(e); if (slow != null && slow != Slow.None) //If particle is slowing { slow.Elapsed--; if (slow.Elapsed <= 0) { e.RemoveComponent<Slow>(slow); IDamping d = dampingMapper.Get(e); d.LinearDamping = 0; d.AngularDamping = 0; if (e.HasComponent<AI>()) { AI a = e.GetComponent<AI>(); e.RemoveComponent<AI>(e.GetComponent<AI>()); a.Calculated = false; e.AddComponent<AI>(a); } e.Refresh(); return; } IVelocity velocity = velocityMapper.Get(e); IDamping damping = dampingMapper.Get(e); //Slow particle angular speed if (velocity.AngularVelocity > slow.AngularTargetVelocity || damping.AngularDamping != slow.AngularSlowRate) damping.AngularDamping = slow.AngularSlowRate; else damping.AngularDamping = 0; //Slow particle linear speed if (velocity.LinearVelocity.Length() - slow.LinearTargetVelocity.Length() > 1 || damping.LinearDamping != slow.LinearSlowRate) damping.LinearDamping = slow.LinearSlowRate; else damping.LinearDamping = 0; SpawnFrostEffect(e); } }
public void Process(Entity toProcess, GameTime gameTime) { if (!IsApplicableTo(toProcess)) { return; } //Get the components out of the entity PositionComponent pos = (PositionComponent)toProcess.components[typeof(PositionComponent)]; PositionDeltaComponent delta = (PositionDeltaComponent)toProcess.components[typeof(PositionDeltaComponent)]; //Update the entity's position pos.Position = pos.Position + delta.Delta; pos.Rotation = pos.Rotation + delta.RotationDelta; //This unit no longer needs to move toProcess.RemoveComponent(delta); }
public Entity Process(EntityManagerManager manager, Entity toProcess, GameTime gameTime) { if (!IsApplicableTo(toProcess)) { return null; } //Get the component SpawnEntityComponent spawner = (SpawnEntityComponent)toProcess.components[typeof(SpawnEntityComponent)]; //Construct a copy of the entity to be spawned Entity toSpawn = spawner.Factory.CreateEntity(toProcess, new Entity()); //Remove the offending component so we don't get more spawns toProcess.RemoveComponent(spawner); //Spawn that entity by adding it to the list of entities to be updated by systems return toSpawn; }
public override void Process(Entity e) { Body b = bodyMapper.Get(e); #region UserMovement if (WasMoving) //Stops movement { b.LinearDamping = (float)Math.Pow(_Velocity, _Velocity*4); WasMoving = false; } else b.LinearDamping = 0; Vector2 target = Vector2.Zero; if (Keyboard.GetState().IsKeyDown(Keys.D)){ //Right target += Vector2.UnitX; } else if (Keyboard.GetState().IsKeyDown(Keys.A)){ //Left target += -Vector2.UnitX; } if (Keyboard.GetState().IsKeyDown(Keys.S)){ //Down target += Vector2.UnitY; } else if (Keyboard.GetState().IsKeyDown(Keys.W)){ //Up? target += -Vector2.UnitY; } if (target != Vector2.Zero) //If being moved by player { WasMoving = true; b.LinearDamping = _Velocity*2; } //Rotation if (b.LinearVelocity != Vector2.Zero) //b.Rotation = MathHelper.SmoothStep(b.Rotation, (float)Math.Atan2(b.LinearVelocity.Y, b.LinearVelocity.X) + (float)Math.PI/2f, 0.1f); b.Rotation = (float)Math.Atan2(b.LinearVelocity.Y, b.LinearVelocity.X) + (float)Math.PI / 2f; //update position b.ApplyLinearImpulse((target)*new Vector2(_Velocity)); #endregion #region Animation if (target != Vector2.Zero && b.LinearVelocity.Length() != 0 && (int)(5/Math.Pow(b.LinearVelocity.Length(), 1 / 2)) != 0) { //if player is being moved. if (world.StepCount % (int)(5 / Math.Pow(b.LinearVelocity.Length(), 1 / 2)) == 0) { AnimationHeight += 30; AnimationHeight %= 90; //Max height on spritesheet. } } else AnimationHeight = 30; Sprite s = e.GetComponent<Sprite>(); s = new Sprite(s.SpriteSheet.Texture, new Rectangle(15, AnimationHeight, 50, 30), s.Origin, s.Scale, s.Color, s.Layer); e.RemoveComponent(ComponentTypeManager.GetTypeFor<Sprite>()); e.AddComponent<Sprite>(s); #endregion }
public Entity BuildEntity(Entity e, params object[] args) { int tier = 1; if (spawned > 2) tier = 2; if (spawned > 5) tier = 3; #region Sprite string spriteKey = ""; int type = spawned; spriteKey = bosses[type].SpriteKey; #endregion Sprite #region Body Body bitch = e.AddComponent<Body>(new Body(_World, e)); FixtureFactory.AttachEllipse(ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Width / 2), ConvertUnits.ToSimUnits(_SpriteSheet[spriteKey][0].Height / 2), 20, 1f, bitch); Sprite s = e.AddComponent<Sprite>(new Sprite(_SpriteSheet, spriteKey, bitch, 1f, Color.White, spriteKey != "bigredblobboss" ? 0.5f + (float)type / 10000f : 0.55f)); bitch.BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Dynamic; bitch.CollisionCategories = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat2; bitch.CollidesWith = GameLibrary.Dependencies.Physics.Dynamics.Category.Cat1 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat3 | GameLibrary.Dependencies.Physics.Dynamics.Category.Cat6; bitch.OnCollision += LambdaComplex.BossCollision(); ++bitch.Mass; Vector2 pos = new Vector2(0, -1); pos.Normalize(); pos *= ScreenHelper.Viewport.Height / 1.5f; pos = ConvertUnits.ToSimUnits(pos); bitch.Position = pos; bitch.SleepingAllowed = false; #endregion Body #region Animation Animation a = null; if (s.Source.Count() > 1) { a = new Animation(AnimationType.None, 10); e.AddComponent<Animation>(a); } #endregion Animation #region AI/Health e.AddComponent<HealthRender>(new HealthRender()); if (spriteKey == "flamer") e.AddComponent<AI>(new AI((args[0] as Body), AI.CreateFlamer(e, 0.5f, bitch, s, _World), "Base")); else if (spriteKey == "bigredblobboss") e.AddComponent<AI>(new AI(null, AI.CreateWarMachine(e, 0.5f, bitch, 10f, 0.7f, s, _World))); else if (spriteKey == "killerhead") e.AddComponent<AI>(new AI(null, AI.CreateKiller(e, 0.5f, 20f, _World))); else if (spriteKey == "greenbossship") e.AddComponent<AI>(new AI(null, AI.CreateBigGreen(e, 0.5f, 10f, 2f, 0.05f, 3.5f, s, _World))); else e.AddComponent<AI>(new AI((args[0] as Body), AI.CreateFollow(e, 1, false), "Base", false)); int points = 0; int health = 0; switch (tier) { case 1: points = 300; health = 150; break; case 2: points = 500; health = 175; break; case 3: points = 1000; health = 200; break; } Health h = new Health(health); h.OnDeath += LambdaComplex.BossDeath(type, _World, e, s, tier, points, bosses[type].BossName); if (type == 1) { h.OnDeath += ex => { Console.WriteLine("DEad"); }; } if (a != null) { h.OnDamage += ent => { if (h.IsAlive && a.Type == AnimationType.None) { e.RemoveComponent<Sprite>(s); double healthFraction = (h.CurrentHealth / h.MaxHealth); int frame = 0; int frames = s.Source.Length; frame = (int)(frames - (frames * healthFraction)); if (frame != s.FrameIndex) { int splodeSound = rbitch.Next(1, 5); SoundManager.Play("Explosion" + splodeSound.ToString()); Vector2 poss = e.GetComponent<ITransform>().Position; _World.CreateEntityGroup("BigExplosion", "Explosions", poss, 15, e, e.GetComponent<IVelocity>().LinearVelocity); } s.FrameIndex = frame; e.AddComponent<Sprite>(s); } }; } if (spriteKey.Equals("flamer")) { h.OnDamage += ent => { //Fire flame from random spot int range = s.CurrentRectangle.Width / 2; float posx = rbitch.Next(-range, range); Vector2 pos1 = bitch.Position + ConvertUnits.ToSimUnits(new Vector2(posx, 0)); float x = posx / range; float y = 1; Vector2 velocity = new Vector2(x, y); velocity.Normalize(); velocity *= 7; _World.CreateEntity("Fire", pos1, velocity).Refresh(); }; } e.AddComponent<Health>(h); #endregion AI/Health e.Tag = "Boss" + spawned.ToString(); e.Group = "Enemies"; ++spawned; #region Special Cases if (spriteKey == "smasher") { _World.CreateEntity("SmasherBall", e).Refresh(); } if (spriteKey == "brain") { Vector2 offset = new Vector2(2, 0); Vector2 position = bitch.Position + offset; _World.CreateEntity("Cannon", position, e).Refresh(); position = bitch.Position - offset; _World.CreateEntity("Cannon", position, e).Refresh(); } if (spriteKey == "massivebluemissile") { _World.enemySpawnSystem.ThugSprite = "bluemissile"; _World.enemySpawnSystem.SpawnRate = 0; _World.enemySpawnSystem.ThugSpawnRate = 3; } if (spriteKey == "killerhead") { List<Entity> children = new List<Entity>(); Vector2 offset = new Vector2(2.85f, -0.6f); Vector2 position = bitch.Position + offset; Entity x; x = _World.CreateEntity("KillerGun", position, e, "killerrightgun", offset, e); x.Refresh(); children.Add(x); offset.X = -3.15f; position = bitch.Position + offset; x = _World.CreateEntity("KillerGun", position, e, "killerleftgun", offset); x.Refresh(); children.Add(x); e.AddComponent<Children>(new Children(children)); } if (spriteKey == "eye") { _World.enemySpawnSystem.MookSprite = "eyeshot"; _World.enemySpawnSystem.SpawnRate = 0; _World.enemySpawnSystem.MookSpawnRate = 2; } if (spriteKey == "clawbossthing") { _World.enemySpawnSystem.MookSprite = "8prongbrownthingwithfangs"; _World.enemySpawnSystem.ThugSprite = "minibrownclawboss"; _World.enemySpawnSystem.SpawnRate = 0; _World.enemySpawnSystem.MookSpawnRate = 2; _World.enemySpawnSystem.ThugSpawnRate = 2; } if (spriteKey == "flamer") { _World.enemySpawnSystem.SpawnRate = 0; } #endregion Special Cases return e; }
private static void handleSlow(Entity ent, EntityWorld _World) { (_World as SpaceWorld).slowSystem.SpawnFrostEffect(ent); Slow slow = ent.GetComponent<Slow>(); slow.Elapsed--; if (slow.Elapsed <= 0) { ent.RemoveComponent<Slow>(slow); } }
/// <summary> /// Refresh the surface mesh /// </summary> /// <param name="surface">The hololens surface information</param> /// <param name="surfaceEntity">The entity to update</param> protected override void RefreshModel(SpatialMappingSurface surface, Entity surfaceEntity) { if (!surfaceEntity.IsDisposed) { surfaceEntity.RemoveComponent<Model>() .RemoveComponent<ModelRenderer>() .AddComponent(Model.CreateFromMesh(surface.Mesh)); if (this.IsVisible && !string.IsNullOrEmpty(this.MaterialPath)) { surfaceEntity.AddComponent(new ModelRenderer()); } } }
/// <summary> /// Refresh the collider of a surface entity /// </summary> /// <param name="surfaceEntity">The entity to update</param> protected override void RefreshCollider(Entity surfaceEntity) { if (!surfaceEntity.IsDisposed) { surfaceEntity.RemoveComponent<MeshCollider3D>(); surfaceEntity.RemoveComponent<RigidBody3D>(); if (this.GenerateColliders) { surfaceEntity.AddComponent(new MeshCollider3D()); surfaceEntity.AddComponent(new RigidBody3D() { IsKinematic = true }); surfaceEntity.RefreshDependencies(); } } }
public bool AddEntity(Entity user, Entity inventory, Entity toAdd, InventoryLocation location = InventoryLocation.Any) { var comHands = inventory.GetComponent<HumanHandsComponent>(ComponentFamily.Hands); var comEquip = inventory.GetComponent<EquipmentComponent>(ComponentFamily.Equipment); var comInv = inventory.GetComponent<InventoryComponent>(ComponentFamily.Inventory); if ((location == InventoryLocation.Inventory) && comInv != null) { if (comInv.AddEntity(user, toAdd)) { //Do sprite stuff and attaching return true; } } else if ((location == InventoryLocation.HandLeft || location == InventoryLocation.HandRight) && comHands != null) { if (comHands.AddEntity(user, toAdd, location)) { //Do sprite stuff and attaching toAdd.RemoveComponent(ComponentFamily.Mover); toAdd.AddComponent(ComponentFamily.Mover, EntityManager.ComponentFactory.GetComponent<SlaveMoverComponent>()); toAdd.GetComponent<SlaveMoverComponent>(ComponentFamily.Mover).Attach(inventory); if (toAdd.HasComponent(ComponentFamily.Renderable) && inventory.HasComponent(ComponentFamily.Renderable)) { toAdd.GetComponent<IRenderableComponent>(ComponentFamily.Renderable).SetMaster(inventory); } toAdd.GetComponent<BasicItemComponent>(ComponentFamily.Item).HandlePickedUp(inventory, location); return true; } } else if ((location == InventoryLocation.Equipment || location == InventoryLocation.Any) && comEquip != null) { if (comEquip.AddEntity(user, toAdd)) { EquippableComponent eqCompo = toAdd.GetComponent<EquippableComponent>(ComponentFamily.Equippable); eqCompo.currentWearer = user; //Do sprite stuff and attaching. return true; } } else if (location == InventoryLocation.Any) { //Do sprite stuff and attaching. bool done = false; if (comInv != null) done = comInv.AddEntity(user, toAdd); if (comEquip != null && !done) done = comEquip.AddEntity(user, toAdd); if (comHands != null && !done) done = comHands.AddEntity(user, toAdd, location); return done; } return false; }
public bool RemoveEntity(Entity user, Entity inventory, Entity toRemove, InventoryLocation location = InventoryLocation.Any) { var comHands = inventory.GetComponent<HumanHandsComponent>(ComponentFamily.Hands); var comEquip = inventory.GetComponent<EquipmentComponent>(ComponentFamily.Equipment); var comInv = inventory.GetComponent<InventoryComponent>(ComponentFamily.Inventory); if ((location == InventoryLocation.Inventory) && comInv != null) { if (comInv.RemoveEntity(user, toRemove)) { //Do sprite stuff and detaching return true; } } else if ((location == InventoryLocation.HandLeft || location == InventoryLocation.HandRight) && comHands != null) { if (comHands.RemoveEntity(user, toRemove)) { //Do sprite stuff and attaching var toRemoveSlaveMover = toRemove.GetComponent<SlaveMoverComponent>(ComponentFamily.Mover); if(toRemoveSlaveMover != null) { toRemoveSlaveMover.Detach(); } if (toRemove.HasComponent(ComponentFamily.Renderable)) { toRemove.GetComponent<IRenderableComponent>(ComponentFamily.Renderable).UnsetMaster(); } toRemove.RemoveComponent(ComponentFamily.Mover); toRemove.AddComponent(ComponentFamily.Mover, EntityManager.ComponentFactory.GetComponent<BasicMoverComponent>()); toRemove.GetComponent<BasicItemComponent>(ComponentFamily.Item).HandleDropped(); return true; } } else if ((location == InventoryLocation.Equipment || location == InventoryLocation.Any) && comEquip != null) { if (comEquip.RemoveEntity(user, toRemove)) { //Do sprite stuff and detaching EquippableComponent eqCompo = toRemove.GetComponent<EquippableComponent>(ComponentFamily.Equippable); if(eqCompo != null) eqCompo.currentWearer = null; return true; } } else if (location == InventoryLocation.Any) { //Do sprite stuff and detaching bool done = false; if (comInv != null) done = comInv.RemoveEntity(user, toRemove); if (comEquip != null && !done) done = comEquip.RemoveEntity(user, toRemove); if (comHands != null && !done) done = comHands.RemoveEntity(user, toRemove); return done; } return false; }
public static void DrawComponent(bool[] unfoldedComponents, Entity entity, int index, IComponent component) { var componentType = component.GetType(); var componentName = componentType.Name.RemoveComponentSuffix(); if(componentName.ToLower().Contains(_componentNameSearchTerm.ToLower())) { var boxStyle = getColoredBoxStyle(entity.totalComponents, index); EntitasEditorLayout.BeginVerticalBox(boxStyle); { var memberInfos = componentType.GetPublicMemberInfos(); EntitasEditorLayout.BeginHorizontal(); { if(memberInfos.Count == 0) { EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel); } else { unfoldedComponents[index] = EntitasEditorLayout.Foldout(unfoldedComponents[index], componentName, _foldoutStyle); } if(GUILayout.Button("-", GUILayout.Width(19), GUILayout.Height(14))) { entity.RemoveComponent(index); } } EntitasEditorLayout.EndHorizontal(); if(unfoldedComponents[index]) { var componentDrawer = getComponentDrawer(componentType); if(componentDrawer != null) { var newComponent = entity.CreateComponent(index, componentType); component.CopyPublicMemberValues(newComponent); EditorGUI.BeginChangeCheck(); { componentDrawer.DrawComponent(newComponent); } var changed = EditorGUI.EndChangeCheck(); if(changed) { entity.ReplaceComponent(index, newComponent); } else { entity.GetComponentPool(index).Push(newComponent); } } else { foreach(var info in memberInfos) { DrawAndSetElement(info.type, info.name, info.GetValue(component), entity, index, component, info.SetValue); } } } } EntitasEditorLayout.EndVertical(); } }