Esempio n. 1
0
        /// <inheritdoc />
        protected sealed override void OnInitialize()
        {
            base.OnInitialize();
            int    m      = Random.Next(5);
            Sprite sprite = new Sprite(AssetManager.Get <SpriteTexture>(this, "floor"), Color.White)
            {
                LayerDepth = 0.1f,
            };

            AddComponent(sprite);

            Vector2         startPos = Transform.Position;
            AnimatedVector2 f        = new AnimatedVector2();
            Curve           c        = new Curve();

            c.Keys.Add(new CurveKey(0, 0));
            c.Keys.Add(new CurveKey(1, 200));
            c.Keys.Add(new CurveKey(2, 100));
            c.Keys.Add(new CurveKey(2.5f, 300));
            f.SetCurve(c, c);
            f.Attach(new Ref <Vector2>(i => Transform.Position = i + startPos));
            Animation aC = new Animation(f)
            {
                WrapMode = WrapMode.PingPong
            };

            AnimatedVector2 f2 = new AnimatedVector2();
            Curve           c2 = new Curve();

            c2.Keys.Add(new CurveKey(0, 100));
            c2.Keys.Add(new CurveKey(1, 400));
            c2.Keys.Add(new CurveKey(2, 150));
            c2.Keys.Add(new CurveKey(2.5f, 250));
            f2.SetCurve(c2, c2);
            f2.Attach(new Ref <Vector2>(i => Transform.Position = i + startPos));

            AnimatedColor col = new AnimatedColor();

            col.SetLerp(Color.White, new Color((byte)Random.Next(255), (byte)Random.Next(255), (byte)Random.Next(255), (byte)1.0f), 2.5f);
            col.Attach(new Ref <Color>(color => {
                List <Sprite> sprites = GetAllComponents <Sprite>();
                for (int i = 0; i < sprites.Count; i++)
                {
                    sprites[i].Color = color;
                }
            }));

            Animation aC2 = new Animation(f2);

            aC2.Add(col);
            aC2.WrapMode = WrapMode.PingPong;

            anim = new BasicAnimator();
            anim.AddAnimation("Anim", aC);
            anim.AddAnimation("Anim2", aC2);
            AddComponent(anim);
            anim.Play("Anim2");
        }
Esempio n. 2
0
        protected sealed override void OnInitialize()
        {
            myPhysics = GetComponent <PhysicsObject>();
            light     = GetComponent <LightComponent>();
            NetworkIdentity networkIdentity = GetComponent <NetworkIdentity>();
            Sprite          sprite          = GetComponent <Sprite>();

            if (Network.InstanceType == NetInstanceType.Server)
            {
                myPhysics.Body = Physics.CreateCircle(16, 1.0f, new Vector2(16), BodyType.Dynamic);
                myPhysics.Body.SetRestitution(0.5f);
                myPhysics.Body.SetFriction(0.0f);

                //myPhysics.Body.OnCollision += Body_OnCollision; // Test event code.
                SetV(new Vector2(Random.Next(256, 512), Random.Next(256, 512)));
                c = new Color(Random.Next(100, 255), Random.Next(100, 255), Random.Next(100, 255));
            }
            else
            {
                myPhysics.Enabled = false;
            }

            SpriteTexture tex = AssetManager.Get <SpriteTexture>(this, "circle");

            ParticleSystem system = GetComponent <ParticleSystem>();

            system.Texture    = AssetManager.Get <Texture2D>(this, "Smoke");
            system.SourceRect = tex.SourceRectangle;

            networkIdentity.OnSerializeNetworkState += () => {
                NetDataWriter writer = new NetDataWriter();
                writer.Put(sprite.Color.R);
                writer.Put(sprite.Color.G);
                writer.Put(sprite.Color.B);
                writer.Put(sprite.Color.A);
                return(writer.CopyData());
            };

            networkIdentity.OnRestoreNetworkState += reader => {
                c            = new Color(reader.GetByte(), reader.GetByte(), reader.GetByte(), reader.GetByte());
                sprite.Color = c;
                light.Color  = c;
            };

            sprite.SpriteTexture = tex;
            sprite.Origin        = new Vector2(16, 16);
            sprite.Color         = c;
            sprite.BlendMode     = BlendMode.Transparent;

            light.Size      = new Vector2(400, 400);
            light.Color     = c;
            light.Intensity = 1.0f;
            light.Enabled   = false;
            base.OnInitialize();
        }
Esempio n. 3
0
 public override void OnParticlesActivated(Span <int> particlesIndex)
 {
     for (int i = 0; i < particlesIndex.Length; i++)
     {
         int index = particlesIndex[i];
         startScales[index] = Emitter.Particles[index].Scale;
         if (IsRandom)
         {
             rand[index] = Random.Next(0.0f, 1.0f);
         }
     }
 }
Esempio n. 4
0
        public NetworkTestMenu() : base(Vector2.Zero)
        {
            if (Screen.IsFullHeadless)
            {
                return;
            }

            notConnectedMenu = new GameObject(Vector2.Zero, 0f, Vector2.One);
            Transform parentTransform = notConnectedMenu.Transform;

            parentTransform.SetParent(Transform);

            Button hostServer = EditorTheme.CreateButton(new Vector2(100, 100), new Point(200, 100),
                                                         "Start server", parentTransform, EditorTheme.ColorSet.Blue);

            spawnButton = EditorTheme.CreateButton(new Vector2(100, 100), new Point(200, 100),
                                                   "Spawn stuff", Transform, EditorTheme.ColorSet.Light);

            Button connect = EditorTheme.CreateButton(new Vector2(100, 400), new Point(200, 100),
                                                      "Connect", parentTransform, EditorTheme.ColorSet.Blue);

            TextInputField addressField = EditorTheme.CreateTextField(new Vector2(310, 100), new Point(200, 40), null, parentTransform);

            addressField.DefocusOnConfirm = false;
            addressField.ClearOnUnfocus   = false;
            addressField.SetValue("127.0.0.1");

            TextInputField portField = EditorTheme.CreateTextField(new Vector2(620, 100), new Point(100, 40), null, parentTransform);

            portField.DefocusOnConfirm = false;
            portField.ConfirmOnEnter   = false;
            portField.ClearOnUnfocus   = false;
            portField.SetValue(Random.Next(1, 25000).ToString());

            spawnButton.Disable();

            addressField.Confirmed += (sender, args) => Network.Connect(addressField.Input.Value, Convert.ToInt32(portField.Input.Value), 919);
            hostServer.Clicked     += (sender, args) => Network.StartServer(919, 920);
            spawnButton.Clicked    += (sender, args) => Game.SpawnStuff();
            connect.Clicked        += (sender, args) => Network.Connect(addressField.Input.Value, Convert.ToInt32(portField.Input.Value), 919);
        }