Exemplo n.º 1
0
    IEnumerator AsteroidMake(int countNum = 1)
    {
        int typeObj = Random.Range(1, _asteroidMaxCount);

        for (int i = 0; i < countNum; i++)
        {
            string     typeName = "Asteroid_" + typeObj.ToString("000");
            GameObject asteroid = Managers.Resource.Instantiate($"Creatures/Other/{typeName}");
            asteroid.name = $"Asteroid_{typeName}";

            Vector3 pos = new Vector3()
            {
                x = Random.Range(ScreenMaxRight + 2, 12),
                y = Random.Range(-4, 4)
            };
            AsteroidController ac = asteroid.GetComponent <AsteroidController>();
            ac.transform.position = pos;
            ac.Type = typeObj;

            Managers.Object.Add(asteroid);
        }

        yield return(new WaitForSeconds(3.0f));

        _coAsteroidTime = null;
        _isAsteroid     = false;
    }
Exemplo n.º 2
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.tag == "Asteroid" || collision.collider.gameObject.tag == "CrystalAsteroid")
        {
            AsteroidController asteroid = collision.gameObject.GetComponent <AsteroidController>();

            if (!dead)
            {
                dead = true;
                asteroid.damageAsteroid(this.damage);
                Debug.Log("DETROYING PROJECTILE ASTEROID");
                DestoryProjectile();
                return;
            }
        }
        else if (collision.gameObject.tag == "Player")
        {
            if (ship.canBeDamaged())
            {
                ship.changeHealth(-damage / 2);
                DestoryProjectile();
                return;
            }
        }
        this.gameObject.layer = 12;
    }
Exemplo n.º 3
0
 static public void AddAsteroid(AsteroidController asteroid)
 {
     if (ASTEROIDS.IndexOf(asteroid) == -1)
     {
         ASTEROIDS.Add(asteroid);
     }
 }
Exemplo n.º 4
0
 static public void RemoveAsteroid(AsteroidController asteroid)
 {
     if (ASTEROIDS.IndexOf(asteroid) != -1)
     {
         ASTEROIDS.Remove(asteroid);
     }
 }
Exemplo n.º 5
0
    public static AsteroidController SpawnAsteroid()
    {
        AsteroidController asteroidPrefab = AsteraX.AsteroidsSO.GetRandomModel();
        AsteroidController asteroid       = Instantiate(asteroidPrefab);

        return(asteroid);
    }
    //	Called everytime our object collides with a trigger collider
    void OnTriggerEnter2D(Collider2D collider)
    {
        //	We try to identify the object that collided with us as a projectile (laser beam).
        Projectile         missile  = collider.gameObject.GetComponent <Projectile>();
        AsteroidController asteroid = collider.gameObject.GetComponent <AsteroidController>();

        //	If our ship collided with a laser beam, we decrease our ship's health in the amount
        //	of damage set by the projectile.  If the ship's health is zero or less, then we destroy
        //	our ship.
        if (missile)
        {
            health -= missile.getDamage();
            missile.Hit();          // The missile is destroyed upon collision with our ship.
            if (health <= 0)
            {
                Die();
            }
        }
        else if (asteroid)
        {
            health -= asteroid.getDamage();
            asteroid.Crash();
            if (health <= 0)
            {
                Die();
            }
        }
        hpText.text = "HP : " + health;
    }
Exemplo n.º 7
0
    protected virtual void AsteroidCollision(Collision2D collision) //vid en kollision som sker med ett objekt med taggen "asteroid" förstörs asteroiden som kolliderades med och lasern som kolliderade
    {
        AsteroidController asteroid = collision.gameObject.GetComponent <AsteroidController>();

        asteroid.DestroyAsteroid(true);
        DestroyLazer();
    }
Exemplo n.º 8
0
 void OnTriggerEnter2D(Collider2D collider)
 {
     if (collider.gameObject.tag == "asteroid")
     {
         AsteroidController asteroidController = collider.gameObject.GetComponent <AsteroidController> ();
         if (asteroidController != null)
         {
             asteroidController.Damage(1);
         }
         hit();
     }
     else if (collider.gameObject.tag == "enemy")
     {
         EnemyController enemyController = collider.gameObject.GetComponent <EnemyController> ();
         if (enemyController != null)
         {
             enemyController.Destroy();
         }
         hit();
     }
     else if (collider.gameObject.tag == "enemy_bullet")
     {
         EnemyBulletController enemyBulletController = collider.gameObject.GetComponent <EnemyBulletController> ();
         if (enemyBulletController != null)
         {
             enemyBulletController.Destroy();
         }
         hit();
     }
 }
Exemplo n.º 9
0
 void OnTriggerEnter2D(Collider2D collider)
 {
     if (collider.gameObject.tag == "Player")
     {
         PlayerController controller = collider.gameObject.GetComponent <PlayerController> ();
         if (controller != null)
         {
             controller.hit();
             Destroy();
         }
         else
         {
             Debug.LogWarning("Hit something tagged as Player, but didn't have an PlayerController");
         }
     }
     else if (collider.gameObject.tag == "asteroid")
     {
         AsteroidController controller = collider.gameObject.GetComponent <AsteroidController> ();
         if (controller != null)
         {
             controller.Damage(1);
             Destroy();
         }
         else
         {
             Debug.LogWarning("Hit something tagged as Asteroid, but didn't have an AsteroidController");
         }
     }
 }
Exemplo n.º 10
0
    // Use this for initialization
    void Start()
    {
        _shipController     = FindObjectOfType <ShipController>();
        _asteroidController = FindObjectOfType <AsteroidController>();

        _Initialize();
    }
Exemplo n.º 11
0
    void Start()
    {
        List <AsteroidController> array = new List <AsteroidController>();

        for (int k = 0; k < groupCount; k++)
        {
            Vector3 groupPosition = Random.insideUnitCircle * areaRadius;
            for (int i = 0; i < Random.Range(groupSize / 4, groupSize); i++)
            {
                Vector3 shift    = Random.insideUnitCircle * groupRadius;
                Vector3 position = groupPosition + shift;
                if (position.magnitude > minRadius)
                {
                    AsteroidController asteroid = (Instantiate(prefab, position, Quaternion.identity) as GameObject).GetComponent <AsteroidController>();
                    asteroid.minerals = Random.Range(10, 200);
                    array.Add(asteroid);
                }
            }
        }

        float totalObtrained = 0.0f;

        foreach (AsteroidController asteroid in array)
        {
            totalObtrained += asteroid.minerals;
        }
        //Debug.Log("Minerals: " + totalObtrained);
        float koef = totalMinerals / totalObtrained;

        foreach (AsteroidController asteroid in array)
        {
            asteroid.minerals *= koef;
        }
    }
    void Start()
    {
        if (useTestSeed == true)
        {
            Random.InitState(testSeed);
        }


        rend        = GetComponent <MeshRenderer>();//grab render
        asteroidC   = GetComponent <AsteroidController>();
        planMapping = GetComponent <PlanetTextureMapping>();

        InitPlanet();

        asteroidC.StartAstoridProcess();


        int v = Random.Range(0, 101);

        Debug.Log("Has Civilisation chance value " + v);
        if (v <= civilisationChance)
        {
            hasCivilisation = true;
        }

        InitSpace();
    }
Exemplo n.º 13
0
    public void DoSpawnAsteroid(AsteroidController prefab, float low, float high)
    {
        Vector2 orbit = new Vector2(0, Random.Range(low, high)).Rotate(Random.Range(0, 359));
        Vector2 trace = new Vector2(orbit.y, -orbit.x).normalized *300;

        prefab.PrefabInstantiate(Planet, (Vector2)Planet.transform.position + orbit, (Vector2)Planet.transform.position + trace);
    }
Exemplo n.º 14
0
 public void Initialize(AsteroidController inController, float inPointVal, int inLevelIndex, BoxCollider inPlayBounds)
 {
     controller = inController;
     pointVal   = inPointVal;
     levelIndex = inLevelIndex;
     playBounds = inPlayBounds;
 }
Exemplo n.º 15
0
    public void _07_AsteroidSplitCountCanBeChanged()
    {
        ClearScene();
        AsteroidController asteroid = Object.Instantiate(asteroidPrefab, Vector3.zero, Quaternion.identity).GetComponent <AsteroidController>();

        asteroid.SetSplitCount(2);
        Assert.IsTrue(asteroid.GetSplitCount() == 2);
    }
Exemplo n.º 16
0
 public void AsteroidDestroyed(AsteroidController asteroid, GameObject destroyer)
 {
     CreateExplosionEffect(asteroid.transform.position); // Asteroid chunks.
     score         += 10;
     textScore.text = score.ToString("000");
     Destroy(asteroid.gameObject); // Asteroid gets deleted.
     Destroy(destroyer);           // Bullet(?) gets deleted.
 }
Exemplo n.º 17
0
    /// <summary>
    /// Spawn the asteroid, and set its direction and velocity
    /// </summary>
    private void SpawnAsteroid()
    {
        GameObject         asteroid            = Instantiate(_asteroid_to_spawn, this.transform.position, Quaternion.identity);
        AsteroidController asteroid_controller = asteroid.GetComponent <AsteroidController>();

        asteroid_controller.Direction = _asteroid_direction;
        asteroid_controller.Velocity  = _asteroid_velocity;
    }
Exemplo n.º 18
0
 public AGameController()
 {
     controllers.Add(statisticsController     = new StatisticsController());
     controllers.Add(playerController         = new PlayerController());
     controllers.Add(asteroidController       = new AsteroidController(statisticsController));
     controllers.Add(screenWrappingController = new ScreenWrappingController(
                         asteroidController.asteroidsPools, playerController.controlledPlayer));
 }
Exemplo n.º 19
0
    public void _12_AsteroidCanMove()
    {
        ClearScene();
        AsteroidController asteroid = Object.Instantiate(asteroidPrefab, Vector3.zero, Quaternion.identity).GetComponent <AsteroidController>();

        asteroid.Move();
        Assert.IsTrue(asteroid.transform.position != Vector3.zero);
    }
Exemplo n.º 20
0
    public void _13_AsteroidDirectionCanBeChanged()
    {
        ClearScene();
        AsteroidController asteroid = Object.Instantiate(asteroidPrefab, Vector3.zero, Quaternion.identity).GetComponent <AsteroidController>();

        asteroid.SetDirection(Vector2.up);
        Assert.IsTrue(asteroid.GetDirection() == Vector2.up);
    }
 private void OnKill(AsteroidController obj)
 {
     _killed++;
     if (_killed == 10)
     {
         StopMission();
     }
 }
Exemplo n.º 22
0
    public IEnumerator _15_AsteroidIsDestroyedWhenOffscreen()
    {
        ClearScene();
        AsteroidController asteroid = Object.Instantiate(asteroidPrefab, Vector3.right * 100, Quaternion.identity).GetComponent <AsteroidController>();

        yield return(null);

        Assert.IsTrue(asteroid == null, "Asteroid was not destroyed when off screen");
    }
Exemplo n.º 23
0
    public AsteroidController PrefabInstantiate(PlanetController planet, Vector2 orbit, Vector2 position)
    {
        AsteroidController a   = ((GameObject)GameObject.Instantiate(gameObject)).GetComponent <AsteroidController>();
        FlyController      fly = a.GetComponent <FlyController>();

        a.transform.position = position;
        a.planet             = planet;
        fly.PrepareFly(orbit, planet);
        return(a);
    }
Exemplo n.º 24
0
    static public GameObject Spawn(GameObject asteroidParent, Vector3 position, Quaternion rotation, int size,
                                   float speed = -1, int life = -1, int pointsValue = -1)
    {
        GameObject         asteroid = Instantiate(asteroidParent, position, rotation);
        AsteroidController astCtrl  = asteroid.GetComponent <AsteroidController> ();

        astCtrl._size       = size;
        astCtrl._speedBurst = true;

        return(asteroid);
    }
Exemplo n.º 25
0
 public AsteroidFactory(Vector3 position)
 {
     View = GameObject.Instantiate(
         Refs.Instance.AsteroidViewPrefab,
         position,
         Quaternion.identity,
         Refs.Instance.Gameplay
         );
     Model      = new AsteroidModel();
     Controller = new AsteroidController(Model, View);
 }
Exemplo n.º 26
0
 private void OnKill(AsteroidController obj)
 {
     if (_controller.IsSuicide)
     {
         GameEvents.current.HP_CHANGE(-_controller.Damage);
     }
     else
     {
         GameEvents.current.SCORE_CHANGE(_controller.Score);
     }
 }
Exemplo n.º 27
0
    public IEnumerator _18_AsteroidStartsWithARandomRotation()
    {
        ClearScene();
        AsteroidController asteroid1 = Object.Instantiate(asteroidPrefab, Vector3.zero, Quaternion.identity).GetComponent <AsteroidController>();
        AsteroidController asteroid2 = Object.Instantiate(asteroidPrefab, Vector3.zero, Quaternion.identity).GetComponent <AsteroidController>();
        AsteroidController asteroid3 = Object.Instantiate(asteroidPrefab, Vector3.zero, Quaternion.identity).GetComponent <AsteroidController>();

        yield return(null);

        Assert.IsTrue(asteroid1.transform.rotation != asteroid2.transform.rotation && asteroid1.transform.rotation != asteroid3.transform.rotation && asteroid2.transform.rotation != asteroid3.transform.rotation);
    }
Exemplo n.º 28
0
    private AsteroidController CreateAsteroid(AsteroidController asteroid, Vector3 position, Quaternion rotation, Vector3 asteroidStartingForce)
    {
        var asteroidObject     = Spawner.Spawn(asteroid.gameObject, position, Random.rotation);
        var asteroidController = asteroidObject.GetComponent <AsteroidController>();

        asteroidController.Initialize(asteroidStartingForce, Spawner, Camera);
        asteroidController.OnDestruction += OnAsteroidDestruction;

        _currentAsteroids.Add(asteroidController);
        return(asteroidController);
    }
Exemplo n.º 29
0
    /// <summary>
    /// Split this asteroid into small asteroid
    /// based on size
    /// </summary>
    public void Split()
    {
        for (int i = 0; i < size; i++)
        {
            AsteroidController asteroid = manager.asteroidManager.GetSmallAsteroids().GetComponent <AsteroidController>();
            asteroid.instance.Activate(transform.position);
        }

        manager.asteroidCounter += size;
        Destroy();
    }
Exemplo n.º 30
0
    /// <summary>
    /// Returns true if the asteroid is beyond DESPAWN_DISTANCE_MAX in any direction.
    /// </summary>
    private bool AsteroidIsTooFar(AsteroidController asteroid)
    {
        var relativeDistanceToPlayer = GameManager.Instance.PlayerShip.GetRelativeDistance(
            asteroid.transform.position, true
            );

        return(
            relativeDistanceToPlayer.x >= DESPAWN_DISTANCE_MAX ||
            relativeDistanceToPlayer.y >= DESPAWN_DISTANCE_MAX ||
            relativeDistanceToPlayer.z >= DESPAWN_DISTANCE_MAX
            );
    }
Exemplo n.º 31
0
 public void Spawn(float _spin, Vector3 _pos, Vector3 _velocity, int _splits, AsteroidController _cont = null)
 {
     m_SpinRate = _spin;
     this.gameObject.transform.position = _pos;
     m_Velocity = _velocity;
     m_Splits = _splits;
     if (m_Splits == 0)
     {
         this.gameObject.transform.localScale = new Vector3(0.5f, 0.5f, 1.0f);
     }
     else if (m_Splits == 1)
     {
         this.gameObject.transform.localScale = new Vector3(0.25f, 0.25f, 1.0f);
     }
     else {
         this.gameObject.transform.localScale = new Vector3(0.125f, 0.125f, 1.0f);
     }
     if (_cont != null)
     {
         m_AsteroidController = _cont;
     }
 }
Exemplo n.º 32
0
    private void getAsteroidInfo()
    {
        asteroidController = asteroid.GetComponent<AsteroidController>();
            AsteroidController.Building b = asteroidController.getBuilding();

            if (b != null) {
                if (b.isBuilded()) {
                    gui.DrawBuildMine("Being built", false);
                } else if (b.isBuilt()) {
                    gui.DrawBuildMine("Already built", false);
                } else {
                    gui.DrawBuildMine("Build Mine", true);
                }
            } else {
                gui.DrawBuildMine("Build Mine", true);
            }
    }
Exemplo n.º 33
0
 public void handleBuilding(AsteroidController ac)
 {
     AsteroidController.Building bld = ac.getBuilding();
     if (bld != null)
     {
         if (bld.whoControlls() == AsteroidController.Master.Player)
         {
             players[0].setCredits(players[0].getCredits() + (creditsPerBuilding * this.timePassed));
         }
         else if (bld.whoControlls() == AsteroidController.Master.Enemy)
         {
             players[1].setCredits(players[1].getCredits() + (creditsPerBuilding * this.timePassed));
         }
     }
 }