예제 #1
0
 public bool destroy_asteroid()
 {
     if (has_collided)
     {
         return(false);
     }
     score_keeper.add(points);
     if (spawned_debris != null)
     {
         for (int space_rock = 0; space_rock < 2; ++space_rock)
         {
             PlanetariaGameObject game_object = PlanetariaGameObject.Instantiate(spawned_debris, planetaria_transform.position, planetaria_transform.direction);
             Debris debris = game_object.GetComponent <Debris>();
             debris.speed = this.speed;
             DebrisNoirs.live(game_object);
             // while asteroid revenge velocity (targetting satellite) is an interesting idea,
             // I don't think it's necessary (or would fully work as intended for that matter - it might be exploitable).
             // The game will probably be hard enough head/joystick controls
             // (and pros will still make mistakes eventually, even if its because of sleep deprivation)
         }
     }
     DebrisNoirs.die(this.gameObject);
     PlanetariaGameObject.Destroy(this.gameObject);
     return(true);
 }
예제 #2
0
 public static void heat_death()
 {
     foreach (PlanetariaGameObject game_object in debris)
     {
         PlanetariaGameObject.Destroy(game_object);
     }
     debris.Clear();
 }
예제 #3
0
 public void die()
 {
     foreach (Projectile projectile in projectiles_on_screen)
     {
         PlanetariaGameObject.Destroy(projectile.gameObject, 1f);
     }
     projectiles_on_screen.Clear();
     next_projectile_to_reuse = 0;
 }
예제 #4
0
        private void Update()
        {
            Vector3 rail_position    = turret.forward;
            Vector3 bullet_direction = turret.up;

            if (DebrisNoirsInput.firing() && satellite.alive()) // if firing and not dead
            {
                PlanetariaGameObject.Instantiate(projectile, rail_position, bullet_direction);
            }
        }
예제 #5
0
        public static void expand(int capacity) // TODO: CONSIDER: For future versions, deleting an object and creating two for every object pool increment may get around the draw call dynamic batching "bug" (might be intended behaviour) -- where ~120 draw calls become ~20 (behaviour I personally expected) for the same number of objects but only after several destruction and instantiation calls.
        {
            int large_rocks_to_spawn = Mathf.Max(0, capacity - object_pool.Count);

            for (int spawned_root_node = 0; spawned_root_node < large_rocks_to_spawn; spawned_root_node += 1)
            {
                // Yeah, this is hardcoded boilerplate, but it gets the job done (rather than coding a recursive function for levels 1,2,3)

                // Large

                PlanetariaGameObject game_object = PlanetariaGameObject.Instantiate(DebrisSpawner.self().large_debris, Vector3.forward, Vector3.up);
                Debris large = game_object.GetComponent <Debris>();
                object_pool.Add(large); // add the root node only

                // Medium

                game_object = PlanetariaGameObject.Instantiate(DebrisSpawner.self().medium_debris, Vector3.forward, Vector3.up);
                Debris medium1 = game_object.GetComponent <Debris>();
                large.left_debris = medium1;

                game_object = PlanetariaGameObject.Instantiate(DebrisSpawner.self().medium_debris, Vector3.forward, Vector3.up);
                Debris medium2 = game_object.GetComponent <Debris>();
                large.right_debris = medium2;

                // Small

                game_object = PlanetariaGameObject.Instantiate(DebrisSpawner.self().small_debris, Vector3.forward, Vector3.up);
                Debris small1 = game_object.GetComponent <Debris>();
                medium1.left_debris = small1;

                game_object = PlanetariaGameObject.Instantiate(DebrisSpawner.self().small_debris, Vector3.forward, Vector3.up);
                Debris small2 = game_object.GetComponent <Debris>();
                medium1.right_debris = small2;

                game_object = PlanetariaGameObject.Instantiate(DebrisSpawner.self().small_debris, Vector3.forward, Vector3.up);
                Debris small3 = game_object.GetComponent <Debris>();
                medium2.left_debris = small3;

                game_object = PlanetariaGameObject.Instantiate(DebrisSpawner.self().small_debris, Vector3.forward, Vector3.up);
                Debris small4 = game_object.GetComponent <Debris>();
                medium2.right_debris = small4;

                // Disable game objects until they are needed

                large.gameObject.SetActive(false);
                medium1.gameObject.SetActive(false);
                medium2.gameObject.SetActive(false);
                small1.gameObject.SetActive(false);
                small2.gameObject.SetActive(false);
                small3.gameObject.SetActive(false);
                small4.gameObject.SetActive(false);
            }
        }
예제 #6
0
        // while I do like the idea of raycasting in update, that would require PlanetariaColliders or hacking my current raycast implementation, so true-to-original it is
        // Also, raycasting would be broken with relative projectile velocities

        public void OnTriggerEnter(Collider collider)
        {
            if (!has_collided) // make sure one projectile doesn't collide with 2+ debris.
            {
                Debris debris = collider.GetComponent <Debris>();
                if (debris.destroy_asteroid()) // make sure two projectiles don't collide with the same debris (wasting one of them).
                {
                    PlanetariaGameObject.Destroy(this.gameObject);
                    has_collided = true;
                }
            }
        }
예제 #7
0
        private void spawn_debris()
        {
            Vector3 satellite_position = satellite.position;

            for (int debris = 0; debris < debris_to_spawn; debris += 1)
            {
                Vector3 random_position = UnityEngine.Random.onUnitSphere;
                if (Vector3.Dot(random_position, satellite_position) > 0)
                {
                    random_position *= -1;
                }
                DebrisNoirs.live(PlanetariaGameObject.Instantiate(large_debris, random_position));
            }
        }
예제 #8
0
 public static void heat_death()
 {
     foreach (Debris debris in object_pool)
     {
         PlanetariaGameObject.Destroy(debris
                                      .
                                      left_debris
                                      .
                                      left_debris
                                      .
                                      gameObject);
         PlanetariaGameObject.Destroy(debris
                                      .
                                      left_debris
                                      .
                                      right_debris
                                      .
                                      gameObject);
         PlanetariaGameObject.Destroy(debris
                                      .
                                      left_debris
                                      .
                                      gameObject);
         PlanetariaGameObject.Destroy(debris
                                      .
                                      right_debris
                                      .
                                      left_debris
                                      .
                                      gameObject);
         PlanetariaGameObject.Destroy(debris
                                      .
                                      right_debris
                                      .
                                      right_debris
                                      .
                                      gameObject);
         PlanetariaGameObject.Destroy(debris
                                      .
                                      right_debris
                                      .
                                      gameObject);
         PlanetariaGameObject.Destroy(debris
                                      .
                                      gameObject);
     }
     object_pool.Clear(); // The object pool stores the root objects (and medium/small debris implicitly)
     debris.Clear();      // Debris stores active debris on-screen
 }
예제 #9
0
        private void Update()
        {
            Vector3 rail_position    = turret.forward;
            Vector3 bullet_direction = turret.up;

            if (DebrisNoirsInput.firing() && satellite.alive()) // if firing and not dead
            {
                if (projectiles_on_screen.Count < 14)           // FIXME: MAGIC NUMBER - number of bullets spawned per second
                {
                    PlanetariaGameObject spawned_projectile = PlanetariaGameObject.Instantiate(projectile, rail_position, bullet_direction);
                    projectiles_on_screen.Add(spawned_projectile.internal_game_object.GetComponent <Projectile>());
                }
                else
                {
                    projectiles_on_screen[next_projectile_to_reuse].respawn(rail_position, bullet_direction);
                    next_projectile_to_reuse += 1;
                    if (next_projectile_to_reuse >= 14)
                    {
                        next_projectile_to_reuse -= 14;
                    }
                }
            }
        }
예제 #10
0
 void Start()
 {
     satellite = PlanetariaGameObject.Find("Satellite").transform;
     spawn();
 }
예제 #11
0
 public static void live(PlanetariaGameObject game_object)
 {
     debris.Add(game_object);
 }
예제 #12
0
 public static void die(PlanetariaGameObject game_object)
 {
     debris.Remove(game_object);
 }
예제 #13
0
 void Start()
 {
     // set velocity
     planetaria_rigidbody.relative_velocity = new Vector2(0, speed);
     PlanetariaGameObject.Destroy(this.gameObject, lifetime);
 }