Ejemplo n.º 1
0
        public SceneAction Duplicate()
        {
            var result = new SceneAction {
                Delay                 = Delay,
                CrowdDelay            = CrowdDelay,
                Angle                 = Angle,
                Speed                 = Speed,
                AngleOffset           = AngleOffset,
                SpeedOffset           = SpeedOffset,
                EnemyColor            = EnemyColor,
                Acted                 = Acted,
                EnterPosition         = new Vector2(EnterPosition.x, EnterPosition.y),
                ActionTime            = ActionTime,
                ActionHealthThreshold = ActionHealthThreshold,
                NextAction            = NextAction == null ? null : NextAction.Duplicate(),
                Patterns              = new List <BulletPattern>(),
                Health                = Health,
                ItemType              = ItemType,
                DropRate              = DropRate,
                ShooterPrefabName     = ShooterPrefabName,
                Children              = new List <SceneAction>(),
                RandomEnterPosition   = RandomEnterPosition,
                RandomColor           = RandomColor,
                RandXRange            = new Vector2(RandXRange.x, RandXRange.y),
                RandYRange            = new Vector2(RandYRange.x, RandYRange.y),
                ShootProbability      = ShootProbability,
                Shoots                = Shoots
            };

            foreach (var pattern in Patterns)
            {
                result.Patterns.Add(pattern.Duplicate());
            }

            foreach (var action in Children)
            {
                result.Children.Add(action.Duplicate());
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static void AddSequence(Scene scene, SceneAction action, int interval = 15, int number = 20, Vector2?intervalRange = null)
        {
            var startFrame = action.Delay;

            for (int i = 0; i < number; i++)
            {
                var newAction = action.Duplicate();
                newAction.Delay = startFrame;
                if (newAction.RandomEnterPosition)
                {
                    var xRange = newAction.RandXRange;
                    var yRange = newAction.RandYRange;
                    var randx  = Math.Abs(xRange.x - xRange.y) < 0.01 ? xRange.x :Random.Range(xRange.x, xRange.y);
                    var randy  = Math.Abs(yRange.x - yRange.y) < 0.01 ? yRange.x : Random.Range(yRange.x, yRange.y);
                    newAction.EnterPosition = new Vector2(randx, randy);
                }

                if (newAction.RandomColor)
                {
                    newAction.EnemyColor = _colors[Random.Range(0, 3)];
                }

                newAction.Shoots = Random.Range(0.0f, 1.0f) <= newAction.ShootProbability;

                scene.AddAction(newAction);
                if (intervalRange != null)
                {
                    var range = (Vector2)intervalRange;
                    startFrame += Random.Range((int)range.x, (int)range.y);
                }
                else
                {
                    startFrame += interval;
                }
            }
        }
Ejemplo n.º 3
0
 public SceneActionBuilder AddChild(SceneAction action)
 {
     _action.Children.Add(action);
     return(this);
 }
Ejemplo n.º 4
0
 private SceneActionBuilder(SceneActionBuilder parent)
 {
     _action         = new SceneAction();
     _parent         = parent;
     _patternManager = BulletPatternBuilder.GetInstance();
 }
Ejemplo n.º 5
0
 public void AddAction(SceneAction action)
 {
     _actions.Add(action);
 }
Ejemplo n.º 6
0
        private Shooter AddShooter(SceneAction action, Shooter parent = null)
        {
            GameObject go = Object.Instantiate(Resources.Load <GameObject>(action.ShooterPrefabName));
            var        s  = go.AddComponent <Shooter>();

            var color = action.EnemyColor;

            if (color.Equals("magenta"))
            {
                go.GetComponent <SpriteRenderer>().color = Color.magenta;
                s.Color = "Magenta";
            }
            else if (color.Equals("cyan"))
            {
                go.GetComponent <SpriteRenderer>().color = Color.cyan;
                s.Color = "Cyan";
            }
            else if (color.Equals("yellow"))
            {
                go.GetComponent <SpriteRenderer>().color = Color.yellow;
                s.Color = "Yellow";
            }
            s.gameObject.layer = 10;

            s.transform.position = new Vector3(action.EnterPosition.x, action.EnterPosition.y);
//                    s.BulletPattern = action.Pattern.Duplicate();

            var a  = s.Action;
            var sa = action;

            s.Health        = sa.Health;
            s.FullHealth    = sa.Health;
            s.DropItemType  = sa.ItemType;
            s.DropRate      = sa.DropRate;
            s.ParentShooter = parent;

            a.Angle                 = sa.Angle;
            a.AngleOffset           = sa.AngleOffset;
            a.CurrentAngle          = sa.Angle;
            a.Speed                 = sa.Speed;
            a.SpeedOffset           = sa.SpeedOffset;
            a.CurrentSpeed          = sa.Speed;
            a.ActionTime            = sa.ActionTime;
            a.ActionHealthThreshold = sa.ActionHealthThreshold;
            a.BulletPatterns        = new List <BulletPattern>();
            foreach (var saPattern in sa.Patterns)
            {
                a.BulletPatterns.Add(saPattern.Duplicate());
            }

            while (sa.NextAction != null)
            {
                sa           = sa.NextAction;
                a.NextAction = new Action();
                a            = a.NextAction;

                a.Angle                 = sa.Angle;
                a.AngleOffset           = sa.AngleOffset;
                a.CurrentAngle          = sa.Angle;
                a.Speed                 = sa.Speed;
                a.SpeedOffset           = sa.SpeedOffset;
                a.CurrentSpeed          = sa.Speed;
                a.ActionTime            = sa.ActionTime;
                a.ActionHealthThreshold = sa.ActionHealthThreshold;
                a.BulletPatterns        = new List <BulletPattern>();
                foreach (var saPattern in sa.Patterns)
                {
                    a.BulletPatterns.Add(saPattern.Duplicate());
                }
            }


            Parent.AddShooter(s);

            foreach (var actionChild in action.Children)
            {
                s.Children.Add(AddShooter(actionChild, s));
            }

            return(s);
        }