/// <summary>
 /// script that sets color of sprite, depending on number of colliding objects
 /// </summary>
 /// <param name="ctx"></param>
 void BallColorSetScript(ScriptContext ctx)
 {
     var sc = ctx.Entity.GetComponent<SphereShapeComp>();
     var dc = ctx.Entity.GetComponent<DrawComp>();
     float c = Math.Max(1f - sc.Colliders.Count * 0.2f, 0f);
     dc.DrawColor = new Color(c,c,c);
 }
 public Vector2 Value(ScriptContext ctx)
 {
     // scaling logic towards target
     if (Speed > 0)
     {
         Vector2 v = Target - CurrentValue;
         if (v.LengthSquared() > 0)
         {
             Vector2 vm = v; // copy; vm is movement vector to apply
             vm.Normalize();
             vm *= (float)(Speed * ctx.Dt);
             if (vm.LengthSquared() > v.LengthSquared())
             {
                 // target reached
                 CurrentValue = Target;
             }
             else
             {
                 // Apply motion towards target
                 CurrentValue += vm;
             }
         }
     }
     return CurrentValue;
 }
 void CirclingPositionScript2(ScriptContext ctx)
 {
     const float R = 30f;
     const double F = 0.14;
     double t = ctx.SimTime;
     ctx.Entity.GetComponent<PositionComp>().Position =
         new Vector2((float)(R * Math.Sin(MathHelper.TwoPi * F * t)),
                     (float)(R * Math.Cos(MathHelper.TwoPi * F * t)));
 }
Esempio n. 4
0
 /// <summary>
 /// Implements IScript
 /// </summary>
 /// <param name="ctx"></param>
 public void OnUpdate(ScriptContext ctx)
 {
     double v;
     if (Function == null)
         v = ctx.SimTime;
     else
         v = Function.Value(ctx.SimTime);
     ScriptCode(ctx,v);
 }
        public void OnDraw(ScriptContext ctx)
        {
            timer.CountUp();
            int frameRateAvg = 0;
            double timeTotal = ctx.Entity.GetComponent<ScriptComp>().SimTime;

            if (timer.TimeTotal > 0)
                frameRateAvg = (int)( (double)timer.CountTotal / timeTotal );
            string msg = string.Format("{0,4} FPS [{1,4}] Tupd={2,5:N1}ms Tdrw={3,5:N1}ms", timer.Count, frameRateAvg,
                Math.Round(1000.0 * TTGame.Instance.TimerUpdate.TimePerCount),
                Math.Round(1000.0 * TTGame.Instance.TimerDraw.TimePerCount)
            );
            textComp.Text = msg;
        }
        /// <summary>
        /// pixel modification code is here, called every update cycle
        /// </summary>
        /// <param name="context"></param>
        void ChangePixelsRandomlyScript(ScriptContext context)
        {
            // pick a random pixel
            var sc = context.Entity.GetComponent<SpriteComp>();
            int x = RandomMath.RandomIntBetween(0, (int)sc.Width);
            int y = RandomMath.RandomIntBetween(0, (int)sc.Height);
            Color c = sc.GetPixel(x, y);

            // change its color
            Color cNew = new Color((int)c.R - RandomMath.RandomIntBetween(95, 153),
                                    (int)c.G + RandomMath.RandomIntBetween(0, 2),
                                    (int)c.B + RandomMath.RandomIntBetween(98, 212), c.A);
            sc.SetPixel(x, y, cNew);
        }
Esempio n. 7
0
        void ScriptMoveByGamepad(ScriptContext ctx)
        {
            var e = ctx.Entity;
            var vc = e.GetComponent<VelocityComp>();
            float spd = (float)(195 * ctx.Dt);

            var dir = e.GetComponent<PlayerInputComp>();

            if (dir.Direction.Y < 0f)
                vc.Y -= spd;
            else if (dir.Direction.Y > 0f)
                vc.Y += spd;
            else if (dir.Direction.X < 0f )
                vc.X -= spd;
            else if (dir.Direction.X > 0f )
                vc.X += spd;
        }
        public void OnUpdate(ScriptContext p)
        {
            if (q.Count == 0)
                return;

            // clean up q - items that should be removed
            List<QueuedText> toRemove = new List<QueuedText>();
            foreach (QueuedText t in q)
            {
                if (!t.Text.IsActive)
                    toRemove.Add(t);
            }
            foreach (QueuedText t in toRemove)
            {
                q.Remove(t);
            }

            // check which item should be displayed
            // the highest priority one which is earliest in queue
            int highestPri = -32000;
            QueuedText winnerItem = null;
            foreach (QueuedText t in q)
            {
                // by default, text is not active. Only the winning text will be.
                t.Text.IsEnabled = false;
                if (t.Priority > highestPri /*&& t.Text.StartTime <= SimTime */ )
                {
                    highestPri = t.Priority;
                    winnerItem = t;
                }
            }

            // activate only the winning item
            if (winnerItem != null )
            {
                currentItem = winnerItem;
                currentItem.Text.IsEnabled = true;
            }
        }
 public void OnDraw(ScriptContext ctx)
 {
 }
Esempio n. 10
0
        public void OnUpdate(ScriptContext ctx)
        {
            LevelKeyControl(ctx);
            /*
            base.OnUpdate(ref p);

            // important: reflect the global viewpos (for sprites to use)
            Thing.ViewPos = Background.Position;

            // do some level tasks
            if (isBackgroundScrollingOn)
                ScrollBackground(ref p);
            */
        }
Esempio n. 11
0
        /// check keys specific for level
        protected virtual void LevelKeyControl(ScriptContext ctx)
        {
            KeyboardState st = Keyboard.GetState();
            if (st.IsKeyDown(Keys.Escape))
            {
                timeEscDown += ctx.Dt;
                //MotionB.ScaleTarget = 1.5f*DEFAULT_SCALE;
                //MotionB.ScaleSpeed = 0.0004f;
                //Motion.RotateModifier = timeEscDown * 0.05f;
            }
            else
            {
                timeEscDown = 0f;
                //MotionB.ScaleTarget = DEFAULT_SCALE; // TODO
            }
            if (timeEscDown > 1.0f)
            {
                PXGame.Instance.Exit();
            }

            /*
            // FIXME remove debug keys
            if (st.IsKeyDown(Keys.PageUp) && Motion.Zoom == Motion.ZoomTarget)
            {
                Motion.ZoomTarget *= 2.0f;
                Motion.ZoomSpeed = 0.02f;
            }

            if (st.IsKeyDown(Keys.PageDown) && Motion.Zoom == Motion.ZoomTarget)
            {
                Motion.ZoomTarget *= 0.5f;
                Motion.ZoomSpeed = 0.02f;
            }

            if (st.IsKeyDown(Keys.RightControl))
                pixie.IsCollisionFree = true;
            else
                pixie.IsCollisionFree = false;

             */
        }
Esempio n. 12
0
 public void OnUpdate(ScriptContext ctx)
 {
     rp.Time = ctx.SimTime; // gameTime.ElapsedGameTime.TotalSeconds;
     MusicEngine.GetInstance().Render(soundScript, rp);
 }
 /// <summary>
 /// Implements IScript
 /// </summary>
 /// <param name="ctx"></param>
 public void OnUpdate(ScriptContext ctx)
 {
     var v = Function.Value(ctx);
     ScriptCode(ctx,v);
 }
Esempio n. 14
0
 public void OnUpdate(ScriptContext ctx)
 {
     timer.Update();
 }
Esempio n. 15
0
 public void RotateModifierScript(ScriptContext ctx, double value)
 {
     ctx.Entity.GetComponent<DrawComp>().DrawRotation = (float)value;
 }
Esempio n. 16
0
 public void OnUpdate(ScriptContext ctx)
 {
     scriptCode(ctx);
 }
Esempio n. 17
0
 public void OnUpdate(ScriptContext p)
 {
     SimTime = p.SimTime;
     rp.Time = SimTime;
     MusicEngine.GetInstance().Render(soundScript, rp);
 }
Esempio n. 18
0
 public void OnDraw(ScriptContext p)
 {
 }