public static GameObject InstantiateWithPriority(Prefabrication prefab, State state)
        {
            GameObject newObject = CloneGameObject.Clone(prefab);

            gameStates[state].AddGameObjectWithPriority(newObject);
            return(newObject);
        }
        public static GameObject Instantiate(Prefabrication prefab)
        {
            GameObject newObject = CloneGameObject.Clone(prefab);

            currentState.AddGameObject(newObject);
            return(newObject);
        }
Ejemplo n.º 3
0
        public override void Initialize(GameObject owner)
        {
            base.Initialize(owner);

            transform          = (Transform)GetComponent <Transform>();
            transform.Position = new Vector2(360, 300);

            renderer = (SpriteRenderer)GetComponent <SpriteRenderer>();

            velocity = (Velocity)GetComponent <Velocity>();

            var playerObj = GameManager.GetObjectByTag("Player");

            player             = (Transform)playerObj.GetComponent <Transform>();
            playerCenter       = ((SpriteRenderer)playerObj.GetComponent <SpriteRenderer>()).Sprite.GetCenter();
            phaseOneProjectile = GameManager.GetPrefab("GreenProjectile");
            phaseTwoProjectile = GameManager.GetPrefab("PinkSquareProjectile");

            phaseOneProjectile.Tag = "Enemy" + phaseOneProjectile.Tag;

            centerPosition = new Vector2(360, 360) - renderer.Sprite.GetCenter();

            bulletFanProjectile         = GameManager.GetPrefab("WhiteDiamondProjectile");
            bulletFanProjectileRenderer = (SpriteRenderer)bulletFanProjectile.GetComponent <SpriteRenderer>();

            phaseOneCoordinates = new Vector2[]
            {
                new Vector2(360, 84) - renderer.Sprite.GetCenter(),
                new Vector2(248, 432) - renderer.Sprite.GetCenter(),
                new Vector2(541, 215) - renderer.Sprite.GetCenter(),
                new Vector2(178, 215) - renderer.Sprite.GetCenter(),
                new Vector2(471, 432) - renderer.Sprite.GetCenter()
            };

            bossOutline = new Vector2[]
            {
                new Vector2(128, 10) * renderer.Sprite.Scale,
                new Vector2(96, 102) * renderer.Sprite.Scale,
                new Vector2(1, 101) * renderer.Sprite.Scale,
                new Vector2(77, 159) * renderer.Sprite.Scale,
                new Vector2(46, 246) * renderer.Sprite.Scale,
                new Vector2(128, 188) * renderer.Sprite.Scale,
                new Vector2(210, 246) * renderer.Sprite.Scale,
                new Vector2(180, 159) * renderer.Sprite.Scale,
                new Vector2(255, 101) * renderer.Sprite.Scale,
                new Vector2(160, 102) * renderer.Sprite.Scale
            };

            starPoints = new Vector2[]
            {
                new Vector2(128, 10) * renderer.Sprite.Scale,
                new Vector2(1, 101) * renderer.Sprite.Scale,
                new Vector2(46, 246) * renderer.Sprite.Scale,
                new Vector2(210, 246) * renderer.Sprite.Scale,
                new Vector2(255, 101) * renderer.Sprite.Scale,
            };

            health       = totalHealth = 2;
            midbossState = MidbossState.TransitionPhase1;
        }
        private static void AddJSONArgs(Prefabrication prefab, dynamic args)
        {
            switch (args.Name)
            {
            case "Tag":
                prefab.Tag = (string)args.Value; break;

            case "Scale":
                SetScale(prefab, args.Value); break;

            case "Sprite":
                AddSpriteArgs(prefab, args.Value); break;

            case "Text":
                AddTextArgs(prefab, args.Value); break;

            case "Velocity":
                AddVelocityArgs(prefab, args.Value); break;

            case "Animations":
                AddAnimationArgs(prefab, args.Value); break;

            case "Scripts":
                AddScripts(prefab, args.Value); break;

            case "Position":
                ChangePosition(prefab, args.Value); break;

            case "Collision":
                AddCollisionArgs(prefab, args.Value); break;

            case "Spawns":
                AddWave(prefab, args.Value); break;
            }
        }
        private static void AddVelocityArgs(Prefabrication prefab, dynamic args)
        {
            var newVelocity = (Velocity)prefab.AddComponent <Velocity>();

            newVelocity.Speed        = args.Speed;
            newVelocity.Acceleration = args.Acceleration;
        }
        private static void AddSpriteArgs(Prefabrication prefab, dynamic args)
        {
            var newRenderer = (SpriteRenderer)prefab.AddComponent <SpriteRenderer>();

            newRenderer.Sprite = new Sprite(TextureManager.LoadTexture((string)args.Path),
                                            new Rectangle(0, 0, (int)args.Width, (int)args.Height),
                                            (float)args.Scale, (bool)args.Rotatable, (float)args.Depth);
        }
        public static GameObject Instantiate(Prefabrication prefab, Vector2 origin, State state)
        {
            GameObject newObject = CloneGameObject.Clone(prefab);

            ((Transform)newObject.GetComponent <Transform>()).Position = origin;
            gameStates[state].AddGameObject(newObject);
            return(newObject);
        }
        private static void AddTextArgs(Prefabrication prefab, dynamic args)
        {
            var newTextRenderer = (TextRenderer)prefab.AddComponent <TextRenderer>();

            newTextRenderer.Font      = TextureManager.LoadFont((string)args.Font);
            newTextRenderer.Text      = args.Text;
            newTextRenderer.TextColor = args.TextColor;
        }
        private static void AddAnimationArgs(Prefabrication prefab, dynamic args)
        {
            var animator = (Animator)prefab.AddComponent <Animator>();

            foreach (dynamic animation in args)
            {
                animator.AddAnimation((string)animation.Name,
                                      new Animation((int)animation.NumFrames, (float)animation.Delay, (int)animation.YOffset));
            }
        }
Ejemplo n.º 10
0
        private static void AddWave(Prefabrication prefab, dynamic args)
        {
            var wave = (Wave)prefab.AddComponent <Wave>();

            foreach (var spawn in args)
            {
                Spawn newSpawn = new Spawn((string)spawn.Name, new Vector2((float)spawn.X, (float)spawn.Y), (float)spawn.Time);
                wave.AddSpawn(newSpawn);
            }
        }
Ejemplo n.º 11
0
 private static void AddScripts(Prefabrication prefab, dynamic args)
 {
     foreach (dynamic script in args)
     {
         Type newScript = Type.GetType("Take3.ECS.Scripts." + (string)script);
         if (newScript != null)
         {
             prefab.AddComponent((Component)Activator.CreateInstance(newScript));
         }
     }
 }
        public override void Initialize(GameObject owner)
        {
            base.Initialize(owner);
            projectile = GameManager.GetPrefab("PurpleDiamondProjectile");

            transform          = (Transform)GetComponent <Transform>();
            renderer           = (SpriteRenderer)GetComponent <Renderer>();
            projectileRenderer = (SpriteRenderer)projectile.GetComponent <SpriteRenderer>();

            health = 4;
        }
 public static void AddPrefabrication(string name, Prefabrication prefab)
 {
     try
     {
         prefabrications.Add(name, prefab);
     }
     catch (ArgumentException)
     {
         throw;
     }
 }
        public override void Initialize(GameObject owner)
        {
            base.Initialize(owner);
            transform = (Transform)GetComponent <Transform>();
            renderer  = (SpriteRenderer)GetComponent <SpriteRenderer>();

            player = (Transform)GameManager.GetObjectByTag("Player").GetComponent <Transform>();

            projectile = GameManager.GetPrefab("PinkSquareProjectile");

            health = 5;
        }
        public override void Initialize(GameObject owner)
        {
            base.Initialize(owner);
            projectile = GameManager.GetPrefab("GreySquareProjectile");

            transform          = (Transform)GetComponent <Transform>();
            renderer           = (SpriteRenderer)GetComponent <SpriteRenderer>();
            projectileRenderer = (SpriteRenderer)projectile.GetComponent <SpriteRenderer>();

            range = new Vector2(135, 225);

            health = 2;
        }
Ejemplo n.º 16
0
 public static void AddCollisionArgs(Prefabrication prefab, dynamic args)
 {
     if ((string)args.Shape == "Circle")
     {
         var circleCollider = (CircleCollider)prefab.AddComponent <CircleCollider>();
         circleCollider.Buffer = (float)args.Buffer;
     }
     else
     {
         var collider = (Collider)prefab.AddComponent <BoxCollider>();
         collider.Buffer = (float)args.Buffer;
     }
 }
Ejemplo n.º 17
0
        public override void Initialize(GameObject owner)
        {
            base.Initialize(owner);

            transform          = (Transform)GetComponent <Transform>();
            transform.Position = new Vector2(360, 300);

            renderer = (SpriteRenderer)GetComponent <SpriteRenderer>();

            velocity = (Velocity)GetComponent <Velocity>();

            player     = (Transform)GameManager.GetObjectByTag("Player").GetComponent <Transform>();
            projectile = GameManager.GetPrefab("GreenProjectile");

            projectile.Tag = "Enemy" + projectile.Tag;

            phaseOneCoordinates = new Vector2[]
            {
                new Vector2(360, 84) - renderer.Sprite.GetCenter(),
                new Vector2(248, 432) - renderer.Sprite.GetCenter(),
                new Vector2(541, 215) - renderer.Sprite.GetCenter(),
                new Vector2(178, 215) - renderer.Sprite.GetCenter(),
                new Vector2(471, 432) - renderer.Sprite.GetCenter()
            };

            bossOutline = new Vector2[]
            {
                new Vector2(128, 10) * renderer.Sprite.Scale,
                new Vector2(96, 102) * renderer.Sprite.Scale,
                new Vector2(1, 101) * renderer.Sprite.Scale,
                new Vector2(77, 159) * renderer.Sprite.Scale,
                new Vector2(46, 246) * renderer.Sprite.Scale,
                new Vector2(128, 188) * renderer.Sprite.Scale,
                new Vector2(210, 246) * renderer.Sprite.Scale,
                new Vector2(180, 159) * renderer.Sprite.Scale,
                new Vector2(255, 101) * renderer.Sprite.Scale,
                new Vector2(160, 102) * renderer.Sprite.Scale
            };

            starPoints = new Vector2[]
            {
                new Vector2(128, 10) * renderer.Sprite.Scale,
                new Vector2(1, 101) * renderer.Sprite.Scale,
                new Vector2(46, 246) * renderer.Sprite.Scale,
                new Vector2(210, 246) * renderer.Sprite.Scale,
                new Vector2(255, 101) * renderer.Sprite.Scale,
            };

            health       = 10;
            midbossState = MidbossState.Phase2;
        }
Ejemplo n.º 18
0
        public static void LoadJSONObjects(string path)
        {
            var json = new StreamReader(path).ReadToEnd();

            dynamic data = JsonConvert.DeserializeObject(json);

            foreach (dynamic obj in data)
            {
                Prefabrication prefab = new Prefabrication();
                GameManager.AddPrefabrication(obj.Name, prefab);

                foreach (dynamic args in obj.Value)
                {
                    AddJSONArgs(prefab, args);
                }
            }
        }
        public static GameObject Clone(Prefabrication original)
        {
            GameObject copy = new GameObject();

            copy.Tag = original.Tag;

            foreach (Component c in original.Components)
            {
                switch (c)
                {
                case Transform t:
                    CloneTransform(copy, t); break;

                case Animator a:
                    CloneAnimator(copy, a); break;

                case CircleCollider cc:
                    CloneCircleCollider(copy, cc); break;

                case BoxCollider bc:
                    CloneBoxCollider(copy, bc); break;

                case LinearProjectile lp:
                    CloneLinearProjectile(copy, lp); break;

                case SpriteRenderer sr:
                    CloneSpriteRenderer(copy, sr); break;

                case TextRenderer tr:
                    CloneTextRenderer(copy, tr); break;

                case Velocity v:
                    CloneVelocity(copy, v); break;

                case Script s:
                    CloneScript(copy, s); break;

                default:
                    break;
                }
            }
            return(copy);
        }
Ejemplo n.º 20
0
        public void SwitchCurrentDisplay(Prefabrication prefab)
        {
            if (currentOnDisplay != null)
            {
                currentOnDisplay.Die();
            }
            currentOnDisplay = GameManager.Instantiate(prefab, displayWindow);
            var currentOnDisplayRenderer = (SpriteRenderer)currentOnDisplay.GetComponent <SpriteRenderer>();

            currentOnDisplayRenderer.Sprite.LayerDepth = 0.2f;

            var scale = (currentOnDisplayRenderer.Sprite.SpriteRectangle.Width > currentOnDisplayRenderer.Sprite.SpriteRectangle.Height) ?
                        size / currentOnDisplayRenderer.Sprite.SpriteRectangle.Width :
                        size / currentOnDisplayRenderer.Sprite.SpriteRectangle.Height;

            var windowCenter = new Vector2(displayWindow.X + size / 2, displayWindow.Y + size / 2);
            var currentOnDisplayTransform = (Transform)currentOnDisplay.GetComponent <Transform>();

            currentOnDisplayTransform.Position = windowCenter - currentOnDisplayRenderer.Sprite.GetCenter();
        }
Ejemplo n.º 21
0
        public void SetObject(Prefabrication prefab)
        {
            var transform = (Transform)GetComponent <Transform>();
            var renderer  = (SpriteRenderer)GetComponent <SpriteRenderer>();

            var center = transform.Position + renderer.Sprite.GetCenter();

            var prefabRenderer = (SpriteRenderer)prefab.GetComponent <SpriteRenderer>();

            galleryButtonIcon = new Prefabrication();
            galleryButtonIcon.AddComponent(prefabRenderer);
            if (prefab.HasComponent <Animator>())
            {
                galleryButtonIcon.AddComponent(prefab.GetComponent <Animator>());
            }


            var xOffset = (renderer.Sprite.SpriteRectangle.Width - size) / 2;
            var yOffset = (renderer.Sprite.SpriteRectangle.Height - size) / 2;

            var offset = new Vector2(xOffset, yOffset);

            var buttonIcon = GameManager.Instantiate(galleryButtonIcon, State.Gallery);

            buttonIcon.Tag = "GallerySprite";
            var buttonIconRenderer = (SpriteRenderer)buttonIcon.GetComponent <SpriteRenderer>();

            buttonIconRenderer.Sprite.LayerDepth = 0.2f;
            var scale = (buttonIconRenderer.Sprite.SpriteRectangle.Width > buttonIconRenderer.Sprite.SpriteRectangle.Height) ?
                        size / buttonIconRenderer.Sprite.SpriteRectangle.Width :
                        size / buttonIconRenderer.Sprite.SpriteRectangle.Height;

            if (scale < buttonIconRenderer.Sprite.Scale)
            {
                buttonIconRenderer.Sprite.Scale = scale;
            }

            var buttonIconTransform = (Transform)buttonIcon.GetComponent <Transform>();

            buttonIconTransform.Position = center - buttonIconRenderer.Sprite.GetCenter();
        }
Ejemplo n.º 22
0
        public override void Initialize(GameObject owner)
        {
            base.Initialize(owner);

            transform = (Transform)GetComponent <Transform>();
            renderer  = (SpriteRenderer)GetComponent <SpriteRenderer>();

            bossOutline = new Vector2[]
            {
                new Vector2(3, 43) * renderer.Sprite.Scale,
                new Vector2(128, 255) * renderer.Sprite.Scale,
                new Vector2(253, 43) * renderer.Sprite.Scale
            };

            phaseOneProjectile   = GameManager.GetPrefab("BlueProjectile");
            flipScreenAttack     = GameManager.GetPrefab("FlipGameScreen");
            bulletRainProjectile = GameManager.GetPrefab("PurpleDiamondProjectile");
            bulletFanProjectile  = GameManager.GetPrefab("GreySquareProjectile");


            health = totalHealth = 10;

            finalBossState = FinalBossState.TransitionPhase1;
        }
Ejemplo n.º 23
0
        private static void SetScale(Prefabrication prefab, dynamic args)
        {
            var transform = (Transform)prefab.GetComponent <Transform>();

            transform.Scale = (float)args.Value;
        }
Ejemplo n.º 24
0
        private static void ChangePosition(Prefabrication prefab, dynamic args)
        {
            var transform = (Transform)prefab.GetComponent <Transform>();

            transform.Position = new Vector2((float)args.X, (float)args.Y);
        }