public void Perform(
     CodeBlock block,
     Stack<DmlObject> stack,
     Dictionary<string, DmlObject> locals,
     DmlObject bullet, DmlSystem system)
 {
     switch (property)
     {
         case DmlTokens.INTRINSIC_DIRECTION:
             ((DmlBullet)bullet.Value).Direction = (Vector2)(stack.Pop().Value);
             break;
         case DmlTokens.INTRINSIC_SPEED:
             ((DmlBullet)bullet.Value).Speed = (double)(stack.Pop().Value);
             break;
         case DmlTokens.INTRINSIC_COLOUR:
             ((DmlBullet)bullet.Value).Colour = (Color)(stack.Pop().Value);
             break;
         case DmlTokens.INTRINSIC_SPRITE:
             string name = (string)(stack.Pop().Value);
             ((DmlBullet)bullet.Value).SetSprite(name.Substring(1, name.Length - 2));
             break;
         default:
             throw new DmlSyntaxError(String.Format("Unknown intrinsic property \"{0}\"", property));
     }
 }
 public void Perform(
     CodeBlock block,
     Stack<DmlObject> stack,
     Dictionary<string, DmlObject> locals,
     DmlObject bullet, DmlSystem system)
 {
     switch (property)
     {
         case DmlTokens.INTRINSIC_ORIGIN:
             stack.Push(new DmlObject(DmlType.Vector, ((DmlBullet)bullet.Value).Origin));
             break;
         case DmlTokens.INTRINSIC_POSITION:
             stack.Push(new DmlObject(DmlType.Vector, ((DmlBullet)bullet.Value).Position));
             break;
         case DmlTokens.INTRINSIC_DIRECTION:
             stack.Push(new DmlObject(DmlType.Vector, ((DmlBullet)bullet.Value).Direction));
             break;
         case DmlTokens.INTRINSIC_SPEED:
             stack.Push(new DmlObject(DmlType.Vector, ((DmlBullet)bullet.Value).Speed));
             break;
         case DmlTokens.INTRINSIC_COLOUR:
             stack.Push(new DmlObject(DmlType.Colour, ((DmlBullet)bullet.Value).Colour));
             break;
         case DmlTokens.INTRINSIC_TIME:
             stack.Push(new DmlObject(DmlType.Number, ((DmlBullet)bullet.Value).LocalTime));
             break;
         case DmlTokens.INTRINSIC_VELOCITY:
             DmlBullet b = (DmlBullet)bullet.Value;
             stack.Push(new DmlObject(DmlType.Vector, b.Direction * (float)b.Speed));
             break;
         default:
             throw new DmlSyntaxError(String.Format("Unknown bullet property \"{0}\"", property));
     }
 }
Ejemplo n.º 3
0
 public void Perform(
     CodeBlock block,
     Stack<DmlObject> stack, 
     Dictionary<string, DmlObject> locals,
     DmlObject bullet, DmlSystem system)
 {
 }
Ejemplo n.º 4
0
        public override DmlObject CallDynamic(int argCount, Stack<DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            var time = (DmlObject)(stack.Pop());
            var period = (DmlObject)(stack.Pop());
            var start = (DmlObject)(stack.Pop());
            var max = (DmlObject)(stack.Pop());
            var min = (DmlObject)(stack.Pop());

            if (min.Type != DmlType.Number)
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, min.Type);

            if (max.Type != DmlType.Number)
                throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, max.Type);

            if (start.Type != DmlType.Number)
                throw DmlSyntaxError.BadArgumentType(Name, 3, DmlType.Number, start.Type);

            if (period.Type != DmlType.Number)
                throw DmlSyntaxError.BadArgumentType(Name, 4, DmlType.Number, period.Type);

            if (time.Type != DmlType.Number)
                throw DmlSyntaxError.BadArgumentType(Name, 5, DmlType.Number, time.Type);

            return new DmlObject(DmlType.Number, _squareWave(
                (double)(min.Value),
                (double)(max.Value),
                (double)(start.Value),
                (double)(period.Value),
                (double)(time.Value)
                ));
        }
Ejemplo n.º 5
0
 public override DmlObject CallDynamic(int argCount, Stack<DmlObject> stack, DmlObject bullet, DmlSystem system)
 {
     var list = new List<DmlObject>();
     for (int i = 0; i < argCount; i++)
         list.Add(stack.Pop());
     list.Reverse(); // We have to reverse it since we pop the objects from the stack in reverse order.
     return new DmlObject(DmlType.List, list);
 }
Ejemplo n.º 6
0
 public void Perform(
     CodeBlock block,
     Stack<DmlObject> stack, 
     Dictionary<string, DmlObject> locals, 
     DmlObject bullet, DmlSystem system)
 {
     system.GlobalVars.Add(name, stack.Pop());
 }
Ejemplo n.º 7
0
 public void Perform(
     CodeBlock block,
     Stack<DmlObject> stack,
     Dictionary<string, DmlObject> locals,
     DmlObject bullet, DmlSystem system)
 {
     stack.Push(system.GlobalVars[name]);
 }
Ejemplo n.º 8
0
 public void Perform(
     CodeBlock block,
     Stack<DmlObject> stack,
     Dictionary<string, DmlObject> locals,
     DmlObject bullet, DmlSystem system)
 {
     ((DmlBullet)bullet.Value).Dead = true;
 }
Ejemplo n.º 9
0
 public void Perform(
     CodeBlock block,
     Stack<DmlObject> stack, 
     Dictionary<string, DmlObject> locals, 
     DmlObject bullet, DmlSystem system)
 {
     bullet.BoundVars[name] = stack.Pop();
 }
Ejemplo n.º 10
0
 public override DmlObject CallDynamic(int argCount, Stack<DmlObject> stack, DmlObject bullet, DmlSystem system)
 {
     DmlObject top = stack.Pop();
     if (top.Type != DmlType.Vector)
         throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Vector, top.Type);
     Vector2 vec = (Vector2)(top.Value);
     return new DmlObject(DmlType.Number, Math.Atan2(vec.Y, vec.X));
 }
Ejemplo n.º 11
0
        public void Perform(
            CodeBlock block,
            Stack<DmlObject> stack,
            Dictionary<string, DmlObject> locals,
            DmlObject bullet, DmlSystem system)
        {
            var paramNames = new string[paramCount];
            var values = new DmlObject[paramCount];

            DmlObject top;
            List<DmlObject> param;

            for (int i = 0; i < paramCount; i++)
            {
                top = stack.Pop();
                param = (List<DmlObject>)top.Value;
                paramNames[i] = (string)(param[0].Value);
                values[i] = param[1];
            }

            var currentAngle = 0d;
            if (hasAngleOffset)
                currentAngle = (double)(stack.Pop().Value);
            if (hasAngleOffsetD)
                currentAngle = Math.PI / 180 * (double)(stack.Pop().Value);

            var speed = (double)(stack.Pop().Value);
            var streams = (int)(double)(stack.Pop().Value);
            var factory = (DmlBulletFactory)(stack.Pop().Value);
            var oldBullet = (DmlBullet)(bullet.Value);

            var angleIncrement = 2*Math.PI/streams;

            DmlObject newBulletObj;
            DmlBullet newBullet;
            Vector2 direction;

            bool local = bullet != null;

            for (int i = 0; i < streams; i++)
            {
                newBulletObj = factory.Instantiate(oldBullet.Origin, system);
                newBullet = (DmlBullet)(newBulletObj.Value);
                direction = new Vector2((float)Math.Cos(currentAngle), (float)Math.Sin(currentAngle));

                newBullet.Direction = direction;
                newBullet.Speed = speed;

                for (int j = 0; j < paramCount; j++)
                    newBulletObj.SetVar(paramNames[j], values[j]);

                if (local)
                    oldBullet.Children.Add(newBullet);
                system.AddBullet(newBullet);

                currentAngle += angleIncrement;
            }
        }
Ejemplo n.º 12
0
 public override DmlObject CallDynamic(int argCount, Stack<DmlObject> stack, DmlObject bullet, DmlSystem system)
 {
     DmlObject timeObj = stack.Pop();
     if (timeObj.Type != DmlType.Number)
         throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, timeObj.Type);
     double time = (double)(timeObj.Value);
     double ltime = ((DmlBullet)bullet.Value).LocalTime;
     return new DmlObject(DmlType.Bool, ltime >= time);
 }
Ejemplo n.º 13
0
 public override void Update(DmlBullet bullet, DmlSystem system)
 {
     bullet.RelativePosition += posIncrement * (float)(Globals.deltaTime);
     if (bullet.LocalTime >= endTime)
     {
         Dead = true;
         bullet.RelativePosition = endPos;
     }
 }
Ejemplo n.º 14
0
 public void Perform(
     CodeBlock block,
     Stack<DmlObject> stack, 
     Dictionary<string, DmlObject> locals,
     DmlObject bullet, DmlSystem system)
 {
     if (!(bool)(stack.Pop().Value))
         block.currentPosition = position;
 }
Ejemplo n.º 15
0
        public void Perform(
            CodeBlock block,
            Stack<DmlObject> stack,
            Dictionary<string, DmlObject> locals,
            DmlObject bullet, DmlSystem system)
        {
            var local = bullet != null;
            DmlBullet parent = null;
            Vector2 origin = Vector2.Zero;
            if (local)
            {
                parent = (DmlBullet)(bullet.Value);
                origin = parent.Position;
            }
            if (hasOrigin)
                origin = (Vector2)(stack.Pop().Value);

            double angleMin = 0, angleMax = 2 * Math.PI, speedMin, speedMax;
            if (hasAngleRange)
            {
                var angleRange = (List<DmlObject>)(stack.Pop().Value);
                angleMin = (double)angleRange[0].Value;
                angleMax = (double)angleRange[1].Value;
                if (degrees)
                {
                    angleMin *= Math.PI / 180;
                    angleMax *= Math.PI / 180;
                }
            }
            var speedRange = (List<DmlObject>)(stack.Pop().Value);
            speedMin = (double)speedRange[0].Value;
            speedMax = (double)speedRange[1].Value;

            var count = (double)(stack.Pop().Value);
            var factory = (DmlBulletFactory)(stack.Pop().Value);

            double crntAngle, crntSpeed;
            Vector2 direction;
            DmlObject newObj;
            DmlBullet newBullet;

            for (int i = 0; i < count; i++)
            {
                crntAngle = (angleMax - angleMin) * Globals.randGen.NextDouble() + angleMin;
                crntSpeed = (speedMax - speedMin) * Globals.randGen.NextDouble() + speedMin;
                direction = new Vector2((float)Math.Cos(crntAngle), (float)Math.Sin(crntAngle));

                newObj = factory.Instantiate(origin, system);
                newBullet = (DmlBullet)(newObj.Value);
                newBullet.Direction = direction;
                newBullet.Speed = crntSpeed;

                if (local)
                    parent.Children.Add(newBullet);
                system.AddBullet(newBullet);
            }
        }
Ejemplo n.º 16
0
 public override DmlObject CallTypeSafe(int argCount, Stack<DmlObject> stack, DmlObject bullet, DmlSystem system)
 {
     var time = (double)(stack.Pop().Value);
     var period = (double)(stack.Pop().Value);
     var start = (double)(stack.Pop().Value);
     var max = (double)(stack.Pop().Value);
     var min = (double)(stack.Pop().Value);
     return new DmlObject(DmlType.Number, _squareWave(min, max, start, period, time));
 }
Ejemplo n.º 17
0
 public void Perform(
     CodeBlock block,
     Stack<DmlObject> stack,
     Dictionary<string, DmlObject> locals,
     DmlObject bullet, DmlSystem system)
 {
     var b = (DmlBullet)(bullet.Value);
     b.Direction = GeometryUtils.RotateVector(b.Direction, (double)(stack.Pop().Value), degrees: degrees);
 }
Ejemplo n.º 18
0
 public override void Update(DmlBullet bullet, DmlSystem system)
 {
     bullet.Speed += speedIncrement * Globals.deltaTime;
     if (bullet.LocalTime >= endTime)
     {
         Dead = true;
         bullet.Speed = finalSpeed;
     }
 }
Ejemplo n.º 19
0
 public void Perform(
     CodeBlock block,
     Stack<DmlObject> stack,
     Dictionary<string, DmlObject> locals,
     DmlObject bullet, DmlSystem system)
 {
     DmlObject second = stack.Pop();
     DmlObject first = stack.Pop();
     // Add the two objects together ya dingus!
 }
Ejemplo n.º 20
0
 public void Perform(
     CodeBlock block,
     Stack<DmlObject> stack,
     Dictionary<string, DmlObject> locals,
     DmlObject bullet, DmlSystem system)
 {
     var duration = (double)(stack.Pop().Value);
     var endSpeed = (double)(stack.Pop().Value);
     var b = (DmlBullet)bullet.Value;
     b.Components.Add(new TransitionSpeedComponent(b.Speed, endSpeed, b.LocalTime, duration));
 }
Ejemplo n.º 21
0
 public void Perform(
     CodeBlock block,
     Stack<DmlObject> stack, 
     Dictionary<string, DmlObject> locals,
     DmlObject bullet, DmlSystem system)
 {
     double second = (double)(stack.Pop().Value);
     double first = (double)(stack.Pop().Value);
     if (first <= second)
         block.currentPosition = position;
 }
Ejemplo n.º 22
0
 public void Perform(
     CodeBlock block,
     Stack<DmlObject> stack,
     Dictionary<string, DmlObject> locals,
     DmlObject bullet, DmlSystem system)
 {
     var weight = (float)(double)(stack.Pop().Value);
     var direction = (Vector2)(stack.Pop().Value);
     var b = (DmlBullet)(bullet.Value);
     b.Direction += weight * direction / 100f;
 }
Ejemplo n.º 23
0
 public void Perform(
     CodeBlock block,
     Stack<DmlObject> stack,
     Dictionary<string, DmlObject> locals,
     DmlObject bullet, DmlSystem system)
 {
     DmlObject top = stack.Pop();
     if (top.Type != DmlType.Function)
         throw new DmlSyntaxError("Error: attempt to call uncallable object.");
     DmlFunction func = (DmlFunction)(top.Value);
     stack.Push(func.CallDynamic(argCount, stack, bullet, system));
 }
Ejemplo n.º 24
0
 public void Perform(
     CodeBlock block,
     Stack<DmlObject> stack,
     Dictionary<string, DmlObject> locals,
     DmlObject bullet, DmlSystem system)
 {
     DmlObject top = stack.Pop();
     if (top.Type == DmlType.Number)
         stack.Push(new DmlObject(DmlType.Number, Math.Abs((double)top.Value)));
     else
         throw DmlSyntaxError.BadUnaryOperandType("~", top.Type);
 }
Ejemplo n.º 25
0
 public void Perform(
     CodeBlock block,
     Stack<DmlObject> stack,
     Dictionary<string, DmlObject> locals,
     DmlObject bullet, DmlSystem system)
 {
     DmlObject second = stack.Pop();
     DmlObject first = stack.Pop();
     if (first.Type != DmlType.Number || second.Type != DmlType.Number)
         throw DmlSyntaxError.BadBinaryOperandTypes("<", first.Type, second.Type);
     stack.Push(new DmlObject(DmlType.Bool, (double)(first.Value) < (double)(second.Value)));
 }
Ejemplo n.º 26
0
 public void Perform(
     CodeBlock block,
     Stack<DmlObject> stack,
     Dictionary<string, DmlObject> locals,
     DmlObject bullet, DmlSystem system)
 {
     DmlObject second = stack.Pop();
     DmlObject first = stack.Pop();
     switch (first.Type)
     {
         case DmlType.Number:
             switch (second.Type)
             {
                 case DmlType.Number:
                     stack.Push(new DmlObject(DmlType.Number, (double)first.Value * (double)second.Value));
                     break;
                 case DmlType.Vector:
                     stack.Push(new DmlObject(DmlType.Vector, (float)(double)first.Value * (Vector2)second.Value));
                     break;
                 case DmlType.Colour:
                     stack.Push(new DmlObject(DmlType.Colour, (Color)second.Value * (float)(double)first.Value));
                     break;
                 default:
                     throw DmlSyntaxError.BadBinaryOperandTypes("*", first.Type, second.Type);
             }
             break;
         case DmlType.Vector:
             switch (second.Type)
             {
                 case DmlType.Number:
                     stack.Push(new DmlObject(DmlType.Vector, (Vector2)first.Value * (float)(double)second.Value));
                     break;
                 case DmlType.Vector:
                     stack.Push(new DmlObject(DmlType.Number, Vector2.Dot((Vector2)first.Value, (Vector2)second.Value)));
                     break;
                 default:
                     throw DmlSyntaxError.BadBinaryOperandTypes("*", first.Type, second.Type);
             }
             break;
         case DmlType.Colour:
             switch (second.Type)
             {
                 case DmlType.Number:
                     stack.Push(new DmlObject(DmlType.Colour, (Color)first.Value * (float)(double)second.Value));
                     break;
                 default:
                     throw DmlSyntaxError.BadBinaryOperandTypes("*", first.Type, second.Type);
             }
             break;
         default:
             throw DmlSyntaxError.BadBinaryOperandTypes("*", first.Type, second.Type);
     }
 }
Ejemplo n.º 27
0
        public void Execute(DmlObject bullet, DmlSystem system)
        {
            // The command stack.
            Stack<DmlObject> stack = new Stack<DmlObject>();

            // The variables local to this code block.
            Dictionary<string, DmlObject> locals = new Dictionary<string, DmlObject>();

            while (currentPosition < Instructions.Length)
                Instructions[currentPosition++].Perform(this, stack, locals, bullet, system);
            currentPosition = 0;
        }
Ejemplo n.º 28
0
 public void Perform(
     CodeBlock block,
     Stack<DmlObject> stack, 
     Dictionary<string, DmlObject> locals, 
     DmlObject bullet, DmlSystem system)
 {
     DmlObject second = stack.Pop();
     DmlObject first = stack.Pop();
     if (first.Type == DmlType.Number && second.Type == DmlType.Number)
         stack.Push(new DmlObject(DmlType.Number, (double)first.Value % (double)second.Value));
     else
         throw DmlSyntaxError.BadBinaryOperandTypes("%", first.Type, second.Type);
 }
Ejemplo n.º 29
0
        public DmlObject Evaluate(DmlObject bullet, DmlSystem system)
        {
            // The command stack.
            Stack<DmlObject> stack = new Stack<DmlObject>();

            // The variables local to this code block.
            Dictionary<string, DmlObject> locals = new Dictionary<string, DmlObject>();

            while (currentPosition < Instructions.Length)
                Instructions[currentPosition++].Perform(this, stack, locals, bullet, system);
            currentPosition = 0;
            return stack.Count == 0 ? null : stack.Pop();
        }
Ejemplo n.º 30
0
 public void Perform(
     CodeBlock block,
     Stack<DmlObject> stack, 
     Dictionary<string, DmlObject> locals, 
     DmlObject bullet, DmlSystem system)
 {
     DmlObject second = stack.Pop();
     DmlObject first = stack.Pop();
     switch (first.Type)
     {
         case DmlType.Number:
             switch (second.Type)
             {
                 case DmlType.Number:
                     stack.Push(new DmlObject(DmlType.Number, (double)first.Value - (double)second.Value));
                     break;
                 default:
                     throw DmlSyntaxError.BadBinaryOperandTypes("-", first.Type, second.Type);
             }
             break;
         case DmlType.Vector:
             switch (second.Type)
             {
                 case DmlType.Vector:
                     stack.Push(new DmlObject(DmlType.Vector, (Vector2)first.Value - (Vector2)second.Value));
                     break;
                 default:
                     throw DmlSyntaxError.BadBinaryOperandTypes("-", first.Type, second.Type);
             }
             break;
         case DmlType.Colour:
             switch (second.Type)
             {
                 case DmlType.Colour:
                     Color c1 = (Color)first.Value;
                     Color c2 = (Color)second.Value;
                     stack.Push(new DmlObject(DmlType.Colour, new Color(
                         c1.R - c2.R,
                         c1.G - c2.G,
                         c1.B - c2.B,
                         c1.A - c2.A)
                         ));
                     break;
                 default:
                     throw DmlSyntaxError.BadBinaryOperandTypes("-", first.Type, second.Type);
             }
             break;
         default:
             throw DmlSyntaxError.BadBinaryOperandTypes("-", first.Type, second.Type);
     }
 }
Ejemplo n.º 31
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject endObj   = stack.Pop();
            DmlObject startObj = stack.Pop();

            if (startObj.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, startObj.Type);
            }

            if (endObj.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, endObj.Type);
            }

            double end   = (double)(endObj.Value);
            double start = (double)(startObj.Value);
            double ltime = system.GlobalTime;

            return(new DmlObject(DmlType.Bool, start >= ltime && ltime > end));
        }
Ejemplo n.º 32
0
        public override DmlObject CallTypeSafe(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            double time  = (double)(stack.Pop().Value);
            double ltime = ((DmlBullet)bullet.Value).LocalTime;

            return(new DmlObject(DmlType.Bool, time <= ltime && ltime < time + Globals.deltaTime));
        }
Ejemplo n.º 33
0
 public override DmlObject CallTypeSafe(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
 {
     return(new DmlObject(DmlType.Number, func((double)(stack.Pop().Value))));
 }
Ejemplo n.º 34
0
        public void Perform(
            CodeBlock block,
            Stack <DmlObject> stack,
            Dictionary <string, DmlObject> locals,
            DmlObject bullet, DmlSystem system)
        {
            var       local  = bullet != null;
            DmlBullet parent = null;
            Vector2   origin = Vector2.Zero;

            if (local)
            {
                parent = (DmlBullet)(bullet.Value);
                origin = parent.Position;
            }
            if (hasOrigin)
            {
                origin = (Vector2)(stack.Pop().Value);
            }


            double angleMin = 0, angleMax = 2 * Math.PI, speedMin, speedMax;

            if (hasAngleRange)
            {
                var angleRange = (List <DmlObject>)(stack.Pop().Value);
                angleMin = (double)angleRange[0].Value;
                angleMax = (double)angleRange[1].Value;
                if (degrees)
                {
                    angleMin *= Math.PI / 180;
                    angleMax *= Math.PI / 180;
                }
            }
            var speedRange = (List <DmlObject>)(stack.Pop().Value);

            speedMin = (double)speedRange[0].Value;
            speedMax = (double)speedRange[1].Value;

            var count   = (double)(stack.Pop().Value);
            var factory = (DmlBulletFactory)(stack.Pop().Value);

            double    crntAngle, crntSpeed;
            Vector2   direction;
            DmlObject newObj;
            DmlBullet newBullet;

            for (int i = 0; i < count; i++)
            {
                crntAngle = (angleMax - angleMin) * Globals.randGen.NextDouble() + angleMin;
                crntSpeed = (speedMax - speedMin) * Globals.randGen.NextDouble() + speedMin;
                direction = new Vector2((float)Math.Cos(crntAngle), (float)Math.Sin(crntAngle));

                newObj              = factory.Instantiate(origin, system);
                newBullet           = (DmlBullet)(newObj.Value);
                newBullet.Direction = direction;
                newBullet.Speed     = crntSpeed;

                if (local)
                {
                    parent.Children.Add(newBullet);
                }
                system.AddBullet(newBullet);
            }
        }
Ejemplo n.º 35
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            var time   = (DmlObject)(stack.Pop());
            var period = (DmlObject)(stack.Pop());
            var start  = (DmlObject)(stack.Pop());
            var max    = (DmlObject)(stack.Pop());
            var min    = (DmlObject)(stack.Pop());

            if (min.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, min.Type);
            }

            if (max.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, max.Type);
            }

            if (start.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 3, DmlType.Number, start.Type);
            }

            if (period.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 4, DmlType.Number, period.Type);
            }

            if (time.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 5, DmlType.Number, time.Type);
            }

            return(new DmlObject(DmlType.Number, _squareWave(
                                     (double)(min.Value),
                                     (double)(max.Value),
                                     (double)(start.Value),
                                     (double)(period.Value),
                                     (double)(time.Value)
                                     )));
        }
Ejemplo n.º 36
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject intervalObj;
            double    start, end, interval, ltime;

            switch (argCount)
            {
            case 1:
                intervalObj = stack.Pop();

                if (intervalObj.Type != DmlType.Number)
                {
                    throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, intervalObj.Type);
                }

                interval = (double)(stack.Pop().Value);
                ltime    = system.GlobalTime;
                return(new DmlObject(DmlType.Bool, (ltime % (2 * interval)) < interval));

            case 3:
                DmlObject endObj   = stack.Pop();
                DmlObject startObj = stack.Pop();
                intervalObj = stack.Pop();

                if (intervalObj.Type != DmlType.Number)
                {
                    throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, intervalObj.Type);
                }

                if (startObj.Type != DmlType.Number)
                {
                    throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, startObj.Type);
                }

                if (endObj.Type != DmlType.Number)
                {
                    throw DmlSyntaxError.BadArgumentType(Name, 3, DmlType.Number, endObj.Type);
                }

                end      = (double)(stack.Pop().Value);
                start    = (double)(stack.Pop().Value);
                interval = (double)(stack.Pop().Value);
                ltime    = system.GlobalTime;
                double t2 = ltime - start;
                return(new DmlObject(DmlType.Bool,
                                     (t2 >= 0 && ltime <= end) && (t2 % (2 * interval)) < interval));

            default:
                return(null);    // Should never get here.
            }
        }
Ejemplo n.º 37
0
        public override DmlObject CallTypeSafe(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            double z = (double)(stack.Pop().Value);
            int    n = (int)(double)(stack.Pop().Value);

            return(new DmlObject(DmlType.Number, SpecialFunctions.YN(n, z)));
        }
Ejemplo n.º 38
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject second = stack.Pop();
            DmlObject first  = stack.Pop();

            switch (first.Type)
            {
            case DmlType.Number:
                switch (second.Type)
                {
                case DmlType.Number:
                    return(new DmlObject(DmlType.Number, SpecialFunctions.YN((int)(double)first.Value, (double)second.Value)));

                default:
                    // throw new syntax error.
                    throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, second.Type);
                }

            default:
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, first.Type);
            }
        }
Ejemplo n.º 39
0
        public override DmlObject CallTypeSafe(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            double second = (double)(stack.Pop().Value);
            double first  = (double)(stack.Pop().Value);

            return(new DmlObject(DmlType.Number, 180 / Math.PI * Math.Atan2(first, second)));
        }
Ejemplo n.º 40
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject second = stack.Pop();
            DmlObject first  = stack.Pop();

            switch (first.Type)
            {
            case DmlType.Number:
                switch (second.Type)
                {
                case DmlType.Number:
                    return(new DmlObject(DmlType.Number, 180 / Math.PI * Math.Atan2((double)first.Value, (double)second.Value)));

                default:
                    throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, second.Type);
                }

            default:
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, first.Type);
            }
        }
Ejemplo n.º 41
0
        public override DmlObject CallTypeSafe(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            double top       = (double)(stack.Pop().Value);
            int    factorial = 1;

            for (int i = 2; i < top; i++)
            {
                factorial *= i;
            }
            return(new DmlObject(DmlType.Number, factorial));
        }
Ejemplo n.º 42
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject top = stack.Pop();

            switch (top.Type)
            {
            case DmlType.Number:
                double p   = (double)top.Value;
                double val = (int)p;
                if (val != Math.Floor(p))
                {
                    throw new DmlSyntaxError(
                              "Invalid syntax; `Factorial` requires that argument one be an integer."
                              );
                }
                int factorial = 1;
                for (int i = 2; i < val; i++)
                {
                    factorial *= i;
                }
                top.Value = val;
                return(top);

            default:
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, top.Type);
            }
        }
Ejemplo n.º 43
0
        public override DmlObject CallTypeSafe(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            double  angle  = Math.PI / 180 * (double)(stack.Pop().Value);
            Vector2 vec    = (Vector2)(stack.Pop().Value);
            float   x      = vec.X;
            float   y      = vec.Y;
            float   cos    = (float)Math.Cos(angle);
            float   sin    = (float)Math.Sin(angle);
            var     newVec = new Vector2(x * cos - y * sin, x * sin + y * cos);

            newVec.Normalize(); // This avoids rounding errors that cause the bullets to eventually speed up.
            return(new DmlObject(DmlType.Vector, newVec));
        }
Ejemplo n.º 44
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject timeObj = stack.Pop();

            if (timeObj.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, timeObj.Type);
            }
            double time  = (double)(timeObj.Value);
            double ltime = system.GlobalTime;

            return(new DmlObject(DmlType.Bool, ltime >= time));
        }
Ejemplo n.º 45
0
        public override DmlObject CallTypeSafe(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            double time  = (double)(stack.Pop().Value);
            double ltime = system.GlobalTime;

            return(new DmlObject(DmlType.Bool, ltime >= time));
        }
Ejemplo n.º 46
0
            public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
            {
                var       option = new DmlObject(DmlType.Option, null);
                DmlObject nextArg;

                for (int i = 0; i < argCount; i++)
                {
                    nextArg = stack.Pop();
                    option.BoundVars[Parameters[i]] = nextArg;
                }
                return(option);
            }
Ejemplo n.º 47
0
        public override DmlObject CallTypeSafe(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            var time   = (double)(stack.Pop().Value);
            var period = (double)(stack.Pop().Value);
            var start  = (double)(stack.Pop().Value);
            var max    = (double)(stack.Pop().Value);
            var min    = (double)(stack.Pop().Value);

            return(new DmlObject(DmlType.Number, _squareWave(min, max, start, period, time)));
        }
Ejemplo n.º 48
0
        public void Perform(
            CodeBlock block,
            Stack <DmlObject> stack,
            Dictionary <string, DmlObject> locals,
            DmlObject bullet, DmlSystem system)
        {
            string[]    paramNames = new string[paramCount];
            DmlObject[] values     = new DmlObject[paramCount];

            DmlObject        top;
            List <DmlObject> param;

            for (int i = 0; i < paramCount; i++)
            {
                top           = stack.Pop();
                param         = (List <DmlObject>)top.Value;
                paramNames[i] = (string)(param[0].Value);
                values[i]     = param[1];
            }

            var     speed     = 0d;
            var     direction = new Vector2(0, 1);
            Vector2 origin;

            if (hasSpeed)
            {
                speed = (double)(stack.Pop().Value);
            }

            switch (this.direction)
            {
            case DirectionType.Direction:
                direction = (Vector2)(stack.Pop().Value);
                direction.Normalize();
                break;

            case DirectionType.Angle:
                double angle = (double)(stack.Pop().Value);
                direction = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
                break;

            default:
                break;
            }

            if (hasOrigin)
            {
                origin = (Vector2)(stack.Pop().Value);
            }
            else
            {
                origin = ((DmlBullet)bullet.Value).Position;
            }

            var type = (DmlBulletFactory)(stack.Pop().Value);

            DmlObject newObj    = type.Instantiate(origin, system);
            DmlBullet newBullet = (DmlBullet)newObj.Value;

            if (this.direction != DirectionType.None)
            {
                newBullet.Direction = direction;
            }
            if (hasSpeed)
            {
                newBullet.Speed = speed;
            }

            for (int i = 0; i < paramCount; i++)
            {
                newObj.SetVar(paramNames[i], values[i]);
            }

            if (bullet != null)
            {
                // We have to check if bullet is null because Spawn is one of the few behaviours
                // that can be used in a Timeline. When the Timeline's code is executed, `null`
                // is sent in for `bullet`.
                ((DmlBullet)bullet.Value).Children.Add(newBullet);
            }
            system.AddBullet(newBullet);
        }
Ejemplo n.º 49
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            switch (argCount)
            {
            case 1:
                DmlObject top = stack.Pop();
                if (top.Type != DmlType.List)
                {
                    throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, top.Type);
                }
                double low = Double.PositiveInfinity;

                try {
                    double val;
                    foreach (DmlObject v in (DmlObject[])top.Value)
                    {
                        val = (double)v.Value;
                        if (val <= low)
                        {
                            low = val;
                        }
                    }
                }
                catch (InvalidCastException)
                {
                    throw new DmlSyntaxError(
                              "Invalid syntax; `Min` requires input array to be composed entirely of numbers."
                              );
                }
                return(new DmlObject(DmlType.Number, low));

            case 2:
                DmlObject second = stack.Pop();
                DmlObject first  = stack.Pop();

                if (first.Type != DmlType.Number)
                {
                    throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, first.Type);
                }

                else if (second.Type != DmlType.Number)
                {
                    throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, second.Type);
                }

                return(new DmlObject(
                           DmlType.Number,
                           (double)first.Value < (double)second.Value ? first.Value : second.Value
                           ));

            default:
                throw new DmlSyntaxError(
                          "Invalid syntax; `Min` requires either 1 or 2 arguments."
                          );
            }
        }
Ejemplo n.º 50
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject amtObj   = stack.Pop();
            DmlObject endObj   = stack.Pop();
            DmlObject startObj = stack.Pop();

            if (startObj.Type != DmlType.Vector)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Vector, startObj.Type);
            }

            if (endObj.Type != DmlType.Vector)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Vector, endObj.Type);
            }

            if (amtObj.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, amtObj.Type);
            }

            double  amt   = (double)(amtObj.Value);
            Vector2 end   = (Vector2)(endObj.Value);
            Vector2 start = (Vector2)(startObj.Value);

            return(new DmlObject(DmlType.Vector, Vector2.Lerp(start, end, (float)amt)));
        }
Ejemplo n.º 51
0
        public void Perform(
            CodeBlock block,
            Stack <DmlObject> stack,
            Dictionary <string, DmlObject> locals,
            DmlObject bullet, DmlSystem system)
        {
            DmlObject second = stack.Pop();
            DmlObject first  = stack.Pop();

            switch (first.Type)
            {
            case DmlType.Number:
                switch (second.Type)
                {
                case DmlType.Number:
                    stack.Push(new DmlObject(DmlType.Number, (double)first.Value * (double)second.Value));
                    break;

                case DmlType.Vector:
                    stack.Push(new DmlObject(DmlType.Vector, (float)(double)first.Value * (Vector2)second.Value));
                    break;

                case DmlType.Colour:
                    stack.Push(new DmlObject(DmlType.Colour, (Color)second.Value * (float)(double)first.Value));
                    break;

                default:
                    throw DmlSyntaxError.BadBinaryOperandTypes("*", first.Type, second.Type);
                }
                break;

            case DmlType.Vector:
                switch (second.Type)
                {
                case DmlType.Number:
                    stack.Push(new DmlObject(DmlType.Vector, (Vector2)first.Value * (float)(double)second.Value));
                    break;

                case DmlType.Vector:
                    stack.Push(new DmlObject(DmlType.Number, Vector2.Dot((Vector2)first.Value, (Vector2)second.Value)));
                    break;

                default:
                    throw DmlSyntaxError.BadBinaryOperandTypes("*", first.Type, second.Type);
                }
                break;

            case DmlType.Colour:
                switch (second.Type)
                {
                case DmlType.Number:
                    stack.Push(new DmlObject(DmlType.Colour, (Color)first.Value * (float)(double)second.Value));
                    break;

                default:
                    throw DmlSyntaxError.BadBinaryOperandTypes("*", first.Type, second.Type);
                }
                break;

            default:
                throw DmlSyntaxError.BadBinaryOperandTypes("*", first.Type, second.Type);
            }
        }
Ejemplo n.º 52
0
        public override DmlObject CallTypeSafe(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            double b = (double)(stack.Pop().Value);
            double x = (double)(stack.Pop().Value);

            return(new DmlObject(DmlType.Number, Math.Log(x, b)));
        }
Ejemplo n.º 53
0
        public void Perform(
            CodeBlock block,
            Stack <DmlObject> stack,
            Dictionary <string, DmlObject> locals,
            DmlObject bullet, DmlSystem system)
        {
            var paramNames = new string[paramCount];
            var values     = new DmlObject[paramCount];

            DmlObject        top;
            List <DmlObject> param;

            for (int i = 0; i < paramCount; i++)
            {
                top           = stack.Pop();
                param         = (List <DmlObject>)top.Value;
                paramNames[i] = (string)(param[0].Value);
                values[i]     = param[1];
            }

            var currentAngle = 0d;

            if (hasAngleOffset)
            {
                currentAngle = (double)(stack.Pop().Value);
            }
            if (hasAngleOffsetD)
            {
                currentAngle = Math.PI / 180 * (double)(stack.Pop().Value);
            }

            var speed     = (double)(stack.Pop().Value);
            var streams   = (int)(double)(stack.Pop().Value);
            var factory   = (DmlBulletFactory)(stack.Pop().Value);
            var oldBullet = (DmlBullet)(bullet.Value);

            var angleIncrement = 2 * Math.PI / streams;

            DmlObject newBulletObj;
            DmlBullet newBullet;
            Vector2   direction;

            bool local = bullet != null;

            for (int i = 0; i < streams; i++)
            {
                newBulletObj = factory.Instantiate(oldBullet.Origin, system);
                newBullet    = (DmlBullet)(newBulletObj.Value);
                direction    = new Vector2((float)Math.Cos(currentAngle), (float)Math.Sin(currentAngle));

                newBullet.Direction = direction;
                newBullet.Speed     = speed;

                for (int j = 0; j < paramCount; j++)
                {
                    newBulletObj.SetVar(paramNames[j], values[j]);
                }

                if (local)
                {
                    oldBullet.Children.Add(newBullet);
                }
                system.AddBullet(newBullet);

                currentAngle += angleIncrement;
            }
        }
Ejemplo n.º 54
0
        public override DmlObject CallTypeSafe(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            double end   = (double)(stack.Pop().Value);
            double start = (double)(stack.Pop().Value);
            double ltime = ((DmlBullet)bullet.Value).LocalTime;

            return(new DmlObject(DmlType.Bool, start >= ltime && ltime > end));
        }
Ejemplo n.º 55
0
        public override DmlObject CallTypeSafe(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            double  amt   = (double)(stack.Pop().Value);
            Vector2 end   = (Vector2)(stack.Pop().Value);
            Vector2 start = (Vector2)(stack.Pop().Value);

            return(new DmlObject(DmlType.Vector, Vector2.Lerp(start, end, (float)amt)));
        }
Ejemplo n.º 56
0
        public override DmlObject CallTypeSafe(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            double start, end, interval, ltime;

            switch (argCount)
            {
            case 1:
                interval = (double)(stack.Pop().Value);
                ltime    = ((DmlBullet)bullet.Value).LocalTime;

                return(new DmlObject(DmlType.Bool, (ltime % interval) < Globals.deltaTime));

            case 3:
                end      = (double)(stack.Pop().Value);
                start    = (double)(stack.Pop().Value);
                interval = (double)(stack.Pop().Value);

                ltime = ((DmlBullet)bullet.Value).LocalTime;
                double t2 = ltime - start;
                return(new DmlObject(DmlType.Bool,
                                     (t2 >= 0 && ltime <= end) && (t2 % interval) < Globals.deltaTime));

            default:
                return(null);    // Should never get here.
            }
        }
Ejemplo n.º 57
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject top = stack.Pop();

            switch (top.Type)
            {
            case DmlType.Number:
                top.Value = Math.Exp((double)top.Value);
                return(top);

            default:
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, top.Type);
            }
        }
Ejemplo n.º 58
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject second = stack.Pop();
            DmlObject first  = stack.Pop();

            switch (first.Type)
            {
            case DmlType.Number:
                switch (second.Type)
                {
                case DmlType.Number:
                    var max = (double)(second.Value);
                    var min = (double)(first.Value);
                    return(new DmlObject(DmlType.Number, (max - min) * Globals.randGen.NextDouble() + min));

                default:
                    // throw new syntax error.
                    throw DmlSyntaxError.BadArgumentType(Name, 2, DmlType.Number, second.Type);
                }

            default:
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, first.Type);
            }
        }
Ejemplo n.º 59
0
        public override DmlObject CallTypeSafe(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            double top = (double)(stack.Pop().Value);

            return(new DmlObject(DmlType.Number, top < 0 ? -1 : 1));
        }
Ejemplo n.º 60
0
        public override DmlObject CallDynamic(int argCount, Stack <DmlObject> stack, DmlObject bullet, DmlSystem system)
        {
            DmlObject second = stack.Pop();
            DmlObject first  = stack.Pop();

            if (first.Type != DmlType.Vector)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Vector, first.Type);
            }

            if (second.Type != DmlType.Number)
            {
                throw DmlSyntaxError.BadArgumentType(Name, 1, DmlType.Number, second.Type);
            }

            double  angle  = Math.PI / 180 * (double)(second.Value);
            Vector2 vec    = (Vector2)(first.Value);
            float   x      = vec.X;
            float   y      = vec.Y;
            float   cos    = (float)Math.Cos(angle);
            float   sin    = (float)Math.Sin(angle);
            var     newVec = new Vector2(x * cos - y * sin, x * sin + y * cos);

            newVec.Normalize(); // This avoids rounding errors that cause the bullets to eventually speed up.
            return(new DmlObject(DmlType.Vector, newVec));
        }