Example #1
0
        private void Spawn(
            Vector2 origin, Vector2 direction, List <DmlObject> speeds,
            string[] paramNames, DmlObject[] values,
            DmlBullet parent, DmlBulletFactory factory, DmlSystem system)
        {
            bool local = parent != null;

            double    speed;
            DmlObject newObj;
            DmlBullet newBullet;

            foreach (DmlObject s in speeds)
            {
                speed = (double)(s.Value);

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

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

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

                if (local)
                {
                    parent.Children.Add(newBullet);
                }
                system.AddBullet(newBullet);
            }
        }
Example #2
0
        private void Spawn(
            List <DmlObject> origins, List <DmlObject> directions, List <DmlObject> speeds,
            string[] paramNames, DmlObject[] values,
            DmlBullet parent, DmlBulletFactory factory, DmlSystem system)
        {
            if (origins.Count != directions.Count || origins.Count != speeds.Count || directions.Count != speeds.Count)
            {
                throw new BehaviourException("Origins, Directions and Speeds must all have the same number of elements.");
            }

            bool local = parent != null;

            Vector2   origin, direction;
            double    speed;
            DmlObject newObj;
            DmlBullet newBullet;

            for (int i = 0; i < origins.Count; i++)
            {
                origin    = (Vector2)(origins[i].Value);
                direction = (Vector2)(directions[i].Value);
                speed     = (double)(speeds[i].Value);

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

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

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

                if (local)
                {
                    parent.Children.Add(newBullet);
                }
                system.AddBullet(newBullet);
            }
        }
Example #3
0
        private void Spawn(
            Vector2 origin, Vector2 direction, double speed,
            string[] paramNames, DmlObject[] values,
            DmlBullet parent, DmlBulletFactory factory, DmlSystem system)
        {
            DmlObject newObj    = factory.Instantiate(origin, system);
            DmlBullet newBullet = (DmlBullet)newObj.Value;

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

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

            if (parent != null)
            {
                parent.Children.Add(newBullet);
            }
            system.AddBullet(newBullet);
        }
Example #4
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);
        }
Example #5
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;
            }
        }
Example #6
0
        private void Spawn(
        	Vector2 origin, Vector2 direction, List<DmlObject> speeds, 
        	string[] paramNames, DmlObject[] values,
        	DmlBullet parent, DmlBulletFactory factory, DmlSystem system)
        {
            bool local = parent != null;

            double speed;
            DmlObject newObj;
            DmlBullet newBullet;

            foreach (DmlObject s in speeds)
            {
                speed = (double)(s.Value);

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

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

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

                if (local)
                    parent.Children.Add(newBullet);
                system.AddBullet(newBullet);
            }
        }
Example #7
0
        private void Spawn(
        	List<DmlObject> origins, List<DmlObject> directions, List<DmlObject> speeds, 
        	string[] paramNames, DmlObject[] values,
        	DmlBullet parent, DmlBulletFactory factory, DmlSystem system)
        {
            if (origins.Count != directions.Count || origins.Count != speeds.Count || directions.Count != speeds.Count)
                throw new BehaviourException("Origins, Directions and Speeds must all have the same number of elements.");

            bool local = parent != null;

            Vector2 origin, direction;
            double speed;
            DmlObject newObj;
            DmlBullet newBullet;

            for (int i = 0; i < origins.Count; i++)
            {
                origin = (Vector2)(origins[i].Value);
                direction = (Vector2)(directions[i].Value);
                speed = (double)(speeds[i].Value);

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

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

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

                if (local)
                    parent.Children.Add(newBullet);
                system.AddBullet(newBullet);
            }
        }
Example #8
0
        private void Spawn(
        	Vector2 origin, Vector2 direction, double speed,
        	string[] paramNames, DmlObject[] values,
        	DmlBullet parent, DmlBulletFactory factory, DmlSystem system)
        {
            DmlObject newObj = factory.Instantiate(origin, system);
            DmlBullet newBullet = (DmlBullet)newObj.Value;
            newBullet.Direction = direction;
            newBullet.Speed = speed;

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

            if (parent != null)
                parent.Children.Add(newBullet);
            system.AddBullet(newBullet);
        }
Example #9
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);
            }
        }
Example #10
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);
            }
        }
Example #11
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);
        }
Example #12
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;
            }
        }