public Entity BuildEntity(Entity et1, EntityWorld world , params object[] args)
 {
     et1.AddComponent(new Power());
     et1.GetComponent<Power>().POWER = 100;
     et1.Refresh();
     return et1;
 }
Example #2
0
        private IEnumerable Intro(Story story, EntityWorld world)
        {
            var bgGenerator = ServiceLocator.Instance.GetService<SpaceBackgroundGeneratorService>();
            bgGenerator.GenerateBackground(world, 12345);

            var entity = world.CreateStoryOverlay(Properties.Resources.String_ActOne_Intro01);

            yield return Coroutine.WaitFor(TimeSpan.FromSeconds(2));
            entity.FadeGuiElement(TimeSpan.FromSeconds(1.5), 0)
                .OnDone = () => entity.Delete();
            yield return Coroutine.WaitFor(TimeSpan.FromSeconds(2));

            var variant = new ShipVariant
            {
                HullId = "Jormugand",
                TrimDecalColor = Color.Cyan,
                BaseDecalColor = new Color(212, 113, 108),
            };
            _playerEntity = world.CreateShip(variant, new Vector2(500,0),0, physics:true);
            _playerEntity.Tag = "PlayerShip";
            _playerEntity.Refresh();
            var cameraControl = world.SystemManager.GetSystem<Systems.CameraControlSystem>();
            cameraControl.Mode = Systems.CameraMode.FollowEntity;
            cameraControl.FollowedEntity = _playerEntity;

            var test = world.CreateShip("mobius", new Vector2(0, 0), MathHelper.Pi * 1.5f, physics:true);
            test.GetComponent<ShipModelComponent>().BaseDecalColor = Color.Khaki;

            story.State.Fire(Story.Triggers.NextScene);
            yield return null;
        }
        public Entity BuildEntity(Entity e, params object[] args)
        {
            string text = (string)args[0];
            Vector2 position = (Vector2)args[1];
            float time = 0.9f;

            e.AddComponent<FadingText>(new FadingText(text, time, position));

            e.Refresh();
            return e;
        }
Example #4
0
 /// <summary>
 /// Add a Modifier script to an Entity, based on a code block (delegate) and a VectorFunction
 /// </summary>
 /// <param name="e">Entity to add modifier script to</param>
 /// <param name="scriptCode">Code block (delegate) that is the script</param>
 /// <param name="func">Function whose value will be passed in ScriptContext.FunctionValue to script</param>
 /// <returns></returns>
 public static VectorModifierScript AddModifier(Entity e, VectorModifierDelegate scriptCode, IVectorFunction func)
 {
     if (!e.HasComponent<ScriptComp>())
     {
         e.AddComponent(new ScriptComp());
         e.Refresh();
     }
     var sc = e.GetComponent<ScriptComp>();
     var script = new VectorModifierScript(scriptCode, func);
     sc.Add(script);
     return script;
 }
Example #5
0
        public override void Process(Entity e)
        {
            if (!e.HasComponent<AI>())
                return;

            AI ai = e.GetComponent<AI>();

            bool behavior;

            if (ai.Target != null)
            {
                if (World.EntityManager.GetEntity((ai.Target.UserData as Entity).Id) == null)
                    ai.Target = null;
                else if (!(!ai.Recalculate && ai.Calculated) && ai.Target != null && (ai.Target.UserData as Entity) != null && !(behavior = ai.Behavior(ai.Target))) //Run ai behavior, if behavior returns true look for new target.
                {
                    ai.Calculated = true;

                    if (ai.Target == null && e.Group != "Players" && e.Group != "Structures" && !e.Tag.Contains("Cannon"))
                    {
                        if (e.HasComponent<Health>())
                            e.GetComponent<Health>().SetHealth(null, 0);
                        else
                            e.Delete();
                    }

                    return;
                }
            }

            ai.Calculated = true;
            ai.Target = _FindNewTarget(ai, e.GetComponent<Body>());

            if (ai.Target == null && e.Group != "Players" && e.Group != "Structures" && !e.Tag.Contains("Boss"))
            {
                if (e.HasComponent<Health>())
                    e.GetComponent<Health>().SetHealth(null, 0);
                else
                    e.Delete();
            }
            else if (ai.Target == null && e.Group == "Players")
                ai.Behavior(null);

            e.Refresh();
        }
        /// <summary>
        /// Builds the crystal at a specified position and a color.
        /// </summary>
        /// <param name="e"></param>
        /// <param name="args">[0] = position; [1] = color; [2] amount</param>
        /// <returns></returns>
        public Entity BuildEntity(Entity e, params object[] args)
        {
            Vector2 pos = (Vector2)args[0];
            Color color = (Color)args[1];
            string source = "redcrystal";

            e.AddComponent<Components.Timer>(new Components.Timer(10));

            if (color == Color.Red)
                source = "redcrystal";
            if (color == Color.Blue)
                source = "bluecrystal";
            if (color == Color.Yellow)
                source = "yellowcrystal";
            if (color == Color.Green)
                source = "greencrystal";
            if (color == Color.Gray)
                source = "graycrystal";

            Sprite s = e.AddComponent<Sprite>(new Sprite(_SpriteSheet, source, 0.2f + (float)crystals / 10000f));
            Body b = e.AddComponent<Body>(new Body(_World, e));
            b.IsBullet = true;
            FixtureFactory.AttachEllipse((float)ConvertUnits.ToSimUnits(s.CurrentRectangle.Width / 1.5), (float)ConvertUnits.ToSimUnits(s.CurrentRectangle.Height / 1.5), 3, 1f, b);

            b.Position = pos;
            b.BodyType = GameLibrary.Dependencies.Physics.Dynamics.BodyType.Dynamic;

            e.GetComponent<Body>().OnCollision += LambdaComplex.CrystalCollision();

            if (args.Length > 4)
            {
                e.AddComponent<Crystal>(new Crystal(color, (int)args[2], true));
                e.AddComponent<AI>(new AI((args[3] as Entity).GetComponent<Body>(), AI.CreateFollow(e, 5f, false)));
            }
            else if (args.Length > 3)
            {
                e.AddComponent<Crystal>(new Crystal(color, (int)args[2]));
                e.AddComponent<AI>(new AI((args[3] as Entity).GetComponent<Body>(), AI.CreateFollow(e, 5f, false)));
            }

            else
            {
                e.AddComponent<Crystal>(new Crystal(color, (int)args[2]));
            }
            e.Group = "Crystals";

            e.AddComponent<AI>(new AI((args[3] as Entity).GetComponent<Body>(), //AI was severely lagging the game.
                (target) =>
                {
                    if ((target.UserData as Entity).HasComponent<Health>() && (target.UserData as Entity).GetComponent<Health>().IsAlive && target.Position != b.Position && (target.UserData as Entity).Group == "Players")
                    {
                        Vector2 distance = target.Position - b.Position;
                        distance.Normalize();
                        b.LinearVelocity = distance * new Vector2(14);
                        return false;
                    }
                    else
                    {
                        e.Delete();
                        return false;
                    }
                }));

            e.Refresh();
            return e;
        }
        /// <summary>
        /// Builds all of the entities in the SpaceWorld.
        /// </summary>
        /// <param name="Content"></param>
        /// <param name="args">{0-4} Player indices in use.</param>
        protected override void BuildEntities(ContentManager Content, params object[] args)
        {
            Indices.Clear();
            //Set up player(s)
            PlayerIndex[] index = args[0] as PlayerIndex[];
            DirectorSystem.PlayerIndicies = index;

            for (int i = 0;  i < 4; ++i)
            {
                if (i < index.Length)
                {
                    Entity e = CreateEntity("Player", index[i]);
                    Body bitch = e.GetComponent<Body>();

                    e.Refresh();
                    e.GetComponent<Inventory>().YELLOW = 50;
                    Player.Add(e);
                    Indices.Add(index[i]);
                    ++Players;
                }
                else
                {
                    Entity e = CreateEntity("Player", (PlayerIndex)(i), true);
                    Body bitch = e.GetComponent<Body>();

                    e.Refresh();
                    e.GetComponent<Inventory>().YELLOW = 50;
                    Player.Add(e);
                    ++Players;
                }
            }

            CreateEntityGroup("StarField", "Stars");

            //Set up base.
            Base = this.CreateEntity("Base");
            Base.Refresh();

            SpawnState[] states = args[2] as SpawnState[];
            enemySpawnSystem.LoadContent(Base, Player.ToArray(), level, states);
        }
Example #8
0
        private void AddEditorComponentsToPartEntity(Entity entity)
        {
            entity.AddComponent(new EditorComponent());

            var select = new BoundingBoxSelectorComponent() { IsEnabled = false };
            entity.AddComponent(select);

            var drawbounds = new DrawBoundingBoxComponent();
            drawbounds.IsEnabled = false;
            entity.AddComponent(drawbounds);
            select.SelectedChanged += (s, e) =>
            {
                drawbounds.IsEnabled = select.IsSelected;
                if (!select.IsSelected)
                    entity.RemoveComponent<MouseControlledTransformComponent>();
            };

            entity.AddComponent(entity.GetComponent<IShipPartComponent>().Part.Transform);
            if (entity.HasComponent<DummyPartComponent>())
            {
                entity.AddComponent(new GenericDrawableComponent((a, b, e) => {
                    var xform = e.GetComponent<Transform>();
                    b.DrawCircle(xform.Position, 9, 15, Color.Cyan);
                    b.DrawLine(xform.Position.X - 10, xform.Position.Y, xform.Position.X + 10, xform.Position.Y, Color.LightCyan);
                    b.DrawLine(xform.Position.X, xform.Position.Y - 10, xform.Position.X, xform.Position.Y + 10, Color.LightCyan);
                }));
            }
            entity.Refresh();
        }
Example #9
0
 /// <summary>
 /// Add a script to an Entity, based on a function (delegate)
 /// </summary>
 /// <param name="e">The Entity to add script to</param>
 /// <param name="scriptCode">Script to run</param>
 /// <returns>IScript object created from the function</returns>
 public static BasicScript AddScript(Entity e, ScriptDelegate scriptCode)
 {
     if (!e.HasComponent<ScriptComp>())
     {
         e.AddComponent(new ScriptComp());
         e.Refresh();
     }
     var sc = e.GetComponent<ScriptComp>();
     var script = new BasicScript(scriptCode);
     sc.Add(script);
     return script;
 }
Example #10
0
 public override void Process(Entity entity)
 {
     if (!entity.HasComponent<TimeStamp>())
     {
         Int32 unixTimestamp = (Int32)(DateTime.Now.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
         entity.AddComponent(new TimeStamp(unixTimestamp));
         entity.Refresh();
     }
 }