Beispiel #1
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);
        }
Beispiel #2
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];
            }

            DmlObject originObj = null, directionObj = null, speedObj = null;

            if (speedParam != ParamState.None)
            {
                speedObj = stack.Pop();
            }
            if (directionParam != ParamState.None)
            {
                directionObj = stack.Pop();
            }
            if (originParam != ParamState.None)
            {
                originObj = stack.Pop();
            }

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

            if (multi)
            {
                Vector2?         origin = null, direction = null;
                double           speed = 0;
                List <DmlObject> origins = null, directions = null, speeds = null;

                if (originParam == ParamState.None)
                {
                    origin = ((DmlBullet)bullet.Value).Position;
                }
                else if (originParam == ParamState.Single)
                {
                    origin = (Vector2)(originObj.Value);
                }
                else
                {
                    origins = (List <DmlObject>)(originObj.Value);
                }

                if (directionParam == ParamState.None)
                {
                    direction = new Vector2(0, 1);
                }
                else if (directionParam == ParamState.Single)
                {
                    direction = (Vector2)(directionObj.Value);
                }
                else
                {
                    directions = (List <DmlObject>)(directionObj.Value);
                }

                if (speedParam == ParamState.None)
                {
                    speed = 0;
                }
                else if (speedParam == ParamState.Single)
                {
                    speed = (double)(speedObj.Value);
                }
                else
                {
                    speeds = (List <DmlObject>)(speedObj.Value);
                }

                DmlBullet parent = null;
                if (bullet != null)
                {
                    parent = (DmlBullet)(bullet.Value);
                }

                if (origins == null)
                {
                    if (directions == null)
                    {
                        if (speeds == null)
                        {
                            Spawn(origin.Value, direction.Value, speed, paramNames, values, parent, factory, system);
                        }
                        else
                        {
                            Spawn(origin.Value, direction.Value, speeds, paramNames, values, parent, factory, system);
                        }
                    }
                    else
                    {
                        if (speeds == null)
                        {
                            Spawn(origin.Value, directions, speed, paramNames, values, parent, factory, system);
                        }
                        else
                        {
                            Spawn(origin.Value, directions, speeds, paramNames, values, parent, factory, system);
                        }
                    }
                }
                else
                {
                    if (directions == null)
                    {
                        if (speeds == null)
                        {
                            Spawn(origins, direction.Value, speed, paramNames, values, parent, factory, system);
                        }
                        else
                        {
                            Spawn(origins, direction.Value, speeds, paramNames, values, parent, factory, system);
                        }
                    }
                    else
                    {
                        if (speeds == null)
                        {
                            Spawn(origins, directions, speed, paramNames, values, parent, factory, system);
                        }
                        else
                        {
                            Spawn(origins, directions, speeds, paramNames, values, parent, factory, system);
                        }
                    }
                }
            }
            else
            {
                Vector2 origin;
                if (originParam == ParamState.None)
                {
                    origin = ((DmlBullet)bullet.Value).Origin;
                }
                else
                {
                    origin = (Vector2)(originObj.Value);
                }

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

                if (directionParam != ParamState.None)
                {
                    newBullet.Direction = (Vector2)(directionObj.Value);
                }

                if (speedParam != ParamState.None)
                {
                    newBullet.Speed = (double)(speedObj.Value);
                }

                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);
                }
            }
        }
Beispiel #3
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);
        }