Esempio n. 1
0
        public static float EvalAngular(float a, float b, float x, TweenType tween)
        {
            if (x < 0f)
            {
                x = 0f;
            }
            if (x > 1f)
            {
                x = 1f;
            }
            var diff = Mathx.AngleSubtract(b, a);

            switch (tween)
            {
            case (TweenType.Linear):
                return(a + diff * x);

            case (TweenType.Accelerate):
                //n = (x * x) * (1f - x);
                //return a + diff * (n * n * n + x * x);
                return(a + diff * (-(x * x * x) + 2 * x * x));

            case (TweenType.Decelerate):
                return(a + diff * (x * x - x * x * x + x));

            case (TweenType.Smooth):
                if (x > 0.5f)
                {
                    return(a + diff * Eval(0.5f, 1f, (x - 0.5f) * 2f, TweenType.Decelerate));
                }
                return(a + diff * Eval(0f, 0.5f, x * 2f, TweenType.Accelerate));
            }
            return(0f);
        }
Esempio n. 2
0
 public static Value Rand(Interpreter interpreter, SourceRef location, Value[] args, int argCount)
 {
     if (argCount > 1)
     {
         return(Mathx.GetRandom(args[0].VerifyType(Value.ValueType.Number, location).Number, args[1].VerifyType(Value.ValueType.Number, location).Number));
     }
     return(Mathx.GetRandom(0.0, args[0].VerifyType(Value.ValueType.Number, location).Number));
 }
Esempio n. 3
0
            public static Value SetGlow(Interpreter interpreter, SourceRef location, Value[] args, int argCount)
            {
                var obj = interpreter.DynamicLocalConstants["this"].Object as Entity;

                obj.Glow = (byte)Mathx.Clamp(
                    args[0].VerifyType(Value.ValueType.Number, location).Number,
                    0.0,
                    255.0
                    );
                return(Value.Nil);
            }
Esempio n. 4
0
        public void Fire()
        {
            if (Parent == null || Parent.Deleted || BulletDefinition == null || Count1 <= 0 || Count2 <= 0)
            {
                return;
            }

            switch (PatternType)
            {
            case (PatternType.Normal):
                var angTotal = (float)(Count1 - 1) * (Angle2 / (float)Count1);
                var angAdd   = angTotal / (float)(Count1 - 1);
                var speedAdd = (Speed2 - Speed1) / (float)(Math.Max(1, Count2 - 1));
                var ang      = Angle1 - angTotal / 2f;
                for (var column = 0; column < Count1; column++)
                {
                    var speed    = Speed1;
                    var shootPos = Position + Parent.Position + new Vector2(
                        Mathx.DCos(ang) * Radius,
                        Mathx.DSin(ang) * Radius
                        );

                    for (var bullet = 0; bullet < Count2; bullet++)
                    {
                        if (PlayerTeam)
                        {
                            Bullet.PlayerBullet(shootPos, speed, ang + Angle3, BulletDefinition, Function);
                        }
                        else
                        {
                            new Bullet(shootPos, speed, ang + Angle3, BulletDefinition, Function);
                        }
                        speed += speedAdd;
                    }
                    ang += angAdd;
                }
                break;
            }
        }
Esempio n. 5
0
            public static Value Choose(Interpreter interpreter, SourceRef location, Value[] args, int argCount)
            {
                var arr = args[0].VerifyType(Value.ValueType.Array, location).Array;

                return(arr[Mathx.GetRandom(arr.Count)]);
            }
Esempio n. 6
0
        public override void Update()
        {
            base.Update();

            if (Position.X < -Frame.Size.X / 2f + 2f)
            {
                Position = new Vector2(-Frame.Size.X / 2f + 2f, Position.Y);
            }
            if (Position.X > Frame.Size.X / 2f - 2f)
            {
                Position = new Vector2(Frame.Size.X / 2f - 2f, Position.Y);
            }
            if (Position.Y < 2f)
            {
                Position = new Vector2(Position.X, 2f);
            }
            if (Position.Y >= Frame.Size.Y - 2f)
            {
                Position = new Vector2(Position.X, Frame.Size.Y - 2f);
            }

            if (!Alive)
            {
                if (Engine.Time >= LastDeathTime + ReviveTime)
                {
                    Alive = true;
                    Script.InvokeEntityEventTask(Object, "onPlayerRevive");
                }
                ShouldShoot = false;
            }
            else
            {
                ShouldShoot = Input.GetKeyPressed(Keys.Z);
            }

            if (ShouldShoot)
            {
                if (!LastShouldShoot)
                {
                    Console.WriteLine("start shooting");
                    ShootTask = Script.InvokeEntityEventTask(this, "onPlayerShoot");
                }
            }
            else
            {
                if (LastShouldShoot)
                {
                    Console.WriteLine("stop shooting ");
                    if (ShootTask != null)
                    {
                        ShootTask.Stop();
                    }
                }
            }


            Slow = !Input.GetKeyPressed(Keys.LeftShift);

            var moveX = (Input.GetKeyPressed(Keys.Right) ? 1f : 0f) - (Input.GetKeyPressed(Keys.Left) ? 1f : 0f);
            var moveY = (Input.GetKeyPressed(Keys.Down) ? 1f : 0f) - (Input.GetKeyPressed(Keys.Up) ? 1f : 0f);

            if (moveX != 0f || moveY != 0f)
            {
                Angle = Mathx.DAtan2(moveY, moveX);
                Speed = (Slow ? MoveSpeed : MoveSpeedSlow);
            }
            else
            {
                Speed = 0f;
            }

            if (moveX != 0f)
            {
                TurnAmount = Mathx.Clamp(TurnAmount + (double)Math.Sign(moveX) / TurnTimePlayer, -1.0, 1.0);
            }
            else
            {
                TurnAmount = Math.Max(
                    0.0,
                    Math.Abs(TurnAmount) - 1.0 / TurnTimePlayer
                    ) * (double)Math.Sign(TurnAmount);
            }

            if (Alive)
            {
                foreach (var ent in Layer.Bullets.Entities)
                {
                    if (ent.Destroyed)
                    {
                        continue;
                    }
                    var diffX          = ent.Position.X - Position.X;
                    var diffY          = ent.Position.Y - Position.Y;
                    var hitboxCombined = ent.HitboxRadius + HitboxRadiusPlayer;

                    if (diffX * diffX + diffY * diffY < hitboxCombined * hitboxCombined)
                    {
                        LastDeathTime = Engine.Time;
                        Alive         = false;

                        Script.InvokeEntityEventTask(this, "onPlayerDie");
                        break;
                    }
                }
            }

            LastShouldShoot = ShouldShoot;
        }
Esempio n. 7
0
        public void GenerateRing(float radius, float thickness, float startAngle, float endAngle, int steps)
        {
            Begin();
            var angAdd       = (endAngle - startAngle) / (float)steps;
            var cos          = Mathx.DCos(startAngle);
            var sin          = Mathx.DSin(startAngle);
            var lastPosOuter = new Vector3(
                cos * (radius + thickness / 2f),
                sin * (radius + thickness / 2f),
                0f
                );
            var lastPosInner = new Vector3(
                cos * (radius - thickness / 2f),
                sin * (radius - thickness / 2f),
                0f
                );
            var     lastU = 0f;
            float   u, angle;
            Vector3 posOuter, posInner;

            for (angle = startAngle + angAdd; angle < endAngle; angle += angAdd)
            {
                cos      = Mathx.DCos(angle);
                sin      = Mathx.DSin(angle);
                u        = (angle - startAngle) / (endAngle - startAngle);
                posOuter = new Vector3(
                    cos * (radius + thickness / 2f),
                    sin * (radius + thickness / 2f),
                    0f
                    );
                posInner = new Vector3(
                    cos * (radius - thickness / 2f),
                    sin * (radius - thickness / 2f),
                    0f
                    );

                AddVertex(lastPosOuter, Color.White, new Vector2(lastU, 0f));
                AddVertex(posOuter, Color.White, new Vector2(u, 0f));
                AddVertex(lastPosInner, Color.White, new Vector2(lastU, 1f));

                AddVertex(lastPosInner, Color.White, new Vector2(lastU, 1f));
                AddVertex(posOuter, Color.White, new Vector2(u, 0f));
                AddVertex(posInner, Color.White, new Vector2(u, 1f));

                lastPosOuter = posOuter;
                lastPosInner = posInner;
                lastU        = u;
            }
            angle    = endAngle;
            cos      = Mathx.DCos(angle);
            sin      = Mathx.DSin(angle);
            u        = 1f;
            posOuter = new Vector3(
                cos * (radius + thickness / 2f),
                sin * (radius + thickness / 2f),
                0f
                );
            posInner = new Vector3(
                cos * (radius - thickness / 2f),
                sin * (radius - thickness / 2f),
                0f
                );

            AddVertex(lastPosOuter, Color.White, new Vector2(lastU, 0f));
            AddVertex(posOuter, Color.White, new Vector2(u, 0f));
            AddVertex(lastPosInner, Color.White, new Vector2(lastU, 1f));

            AddVertex(lastPosInner, Color.White, new Vector2(lastU, 1f));
            AddVertex(posOuter, Color.White, new Vector2(u, 0f));
            AddVertex(posInner, Color.White, new Vector2(u, 1f));
            End();
        }