Esempio n. 1
0
        public void addLasers()
        {
            if (voidKnight == null)
            {
                return;
            }

            laserSpawn = new GameObject("redwingLaserSpawner", typeof(redwing_laser_spawner_behavior),
                                        typeof(AudioSource));
            Vector3 laserSpawnPos = voidKnight.GetComponent <BoxCollider2D>().bounds.center;

            laserSpawn.transform.position = laserSpawnPos;
            // Why? Because layers 20, 9, 26, and 31 are explicitly ignored by the game
            // and layers above 31 don't exist
            laserSpawn.layer = 31;

            float rotationMod = (float)(redwing_flame_gen.rng.NextDouble() * ROTATION_AMOUNT);

            for (int i = 0; i < 16; i++)
            {
                lasers[i] = new GameObject("redwingLaser" + i, typeof(SpriteRenderer), typeof(Rigidbody2D),
                                           typeof(BoxCollider2D), typeof(redwing_laser_behavior));
                lasers[i].transform.parent        = laserSpawn.transform;
                lasers[i].transform.localPosition = Vector3.zero;

                lasers[i].layer = 0;
                lasers[i].transform.localScale = new Vector3(1f, 8f, 1f);
                Rigidbody2D laserPhysics = lasers[i].GetComponent <Rigidbody2D>();
                laserPhysics.isKinematic = true;

                Rect           r = new Rect(0, 0, redwing_flame_gen.LASERTEXTURE_WIDTH, redwing_flame_gen.LASERTEXTURE_HEIGHT);
                SpriteRenderer s = lasers[i].GetComponent <SpriteRenderer>();
                s.sprite  = Sprite.Create(fireLasers[i], r, new Vector2(0.5f, 0f), 50);
                s.enabled = true;
                s.color   = new Color(1f, 1f, 1f, 0f);

                redwing_laser_behavior shootEm = lasers[i].GetComponent <redwing_laser_behavior>();
                shootEm.drawEm           = s;
                shootEm.spriteUsed       = fireLasers[i];
                shootEm.enteredColliders = new List <Collider2D>();

                BoxCollider2D laserPassthrough = lasers[i].GetComponent <BoxCollider2D>();
                laserPassthrough.isTrigger = true;
                laserPassthrough.size      = s.size;
                laserPassthrough.offset    = new Vector2(0, 0);


                lasers[i].transform.Rotate(0f, 0f, ROTATION_AMOUNT * i + rotationMod);
            }
        }
Esempio n. 2
0
        public static void addSingleLaser(float angel)
        {
            GameObject laserSpawnObj = new GameObject("redwingLaserSpawner", typeof(redwing_laser_spawner_behavior),
                                                      typeof(AudioSource));
            Vector3 laserSpawnPos = voidKnight.GetComponent <BoxCollider2D>().bounds.center;

            laserSpawnPos.y += 0.2f;
            laserSpawnObj.transform.position = laserSpawnPos;
            laserSpawnObj.layer = 31;

            GameObject laser = new GameObject("redwingLaserSolo", typeof(SpriteRenderer), typeof(Rigidbody2D),
                                              typeof(BoxCollider2D), typeof(redwing_laser_behavior));

            laser.transform.parent        = laserSpawnObj.transform;
            laser.transform.localPosition = Vector3.zero;
            int randomTexture = redwing_flame_gen.rng.Next(0, fireLasers.Length);
            redwing_laser_behavior shootEm = laser.GetComponent <redwing_laser_behavior>();
            Rect           r = new Rect(0, 0, redwing_flame_gen.LASERTEXTURE_WIDTH, redwing_flame_gen.LASERTEXTURE_HEIGHT);
            SpriteRenderer s = laser.GetComponent <SpriteRenderer>();

            s.sprite  = Sprite.Create(fireLasers[randomTexture], r, new Vector2(0.5f, 0.5f), 50);
            s.enabled = true;
            s.color   = new Color(1f, 1f, 1f, 0f);

            shootEm.drawEm           = s;
            shootEm.spriteUsed       = fireLasers[randomTexture];
            shootEm.soloLaser        = true;
            shootEm.enteredColliders = new List <Collider2D>();


            laser.layer = 0;
            laser.transform.localScale = new Vector3(1f, 8f, 1f);
            Rigidbody2D laserPhysics = laser.GetComponent <Rigidbody2D>();

            laserPhysics.isKinematic = true;


            BoxCollider2D laserPassthrough = laser.GetComponent <BoxCollider2D>();

            laserPassthrough.isTrigger = true;
            laserPassthrough.size      = s.size;
            laserPassthrough.offset    = new Vector2(0, 0);

            laser.transform.Rotate(0f, 0f, angel);

            laser.SetActive(true);

            //Modding.Logger.Log("[Redwing] temp made solo laser ");
        }