当前位置: 首页>>代码示例>>C#>>正文


C# DirectionType.Normalize方法代码示例

本文整理汇总了C#中DirectionType.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# DirectionType.Normalize方法的具体用法?C# DirectionType.Normalize怎么用?C# DirectionType.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DirectionType的用法示例。


在下文中一共展示了DirectionType.Normalize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Perform

        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);
        }
开发者ID:roflwaffl,项目名称:Phosphaze,代码行数:65,代码来源:Spawn.cs


注:本文中的DirectionType.Normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。