示例#1
0
    public void InflictDamage(int value)
    {
        health -= value;
        if (health <= 0)
        {
            // move explosion to asteroid location and play
            asteroidExplosion.transform.position = transform.position;
            asteroidExplosion.GetComponent <ParticleSystem>().Play();

            explosionSound.Play();

            if (level++ < maxIterations)
            {
                // reset values of this current asteroid
                health      = maxHealth;
                rb.velocity = Random.insideUnitCircle * maxInitialSpeed;

                // get other asteroid and place it on current
                AsteroidBehaviour other = Pool.Pop().GetComponent <AsteroidBehaviour>();
                other.transform.position = transform.position;
                other.level = level;

                // shrink both
                other.transform.localScale = transform.localScale *= shrinkFactor;
            }
            else
            {
                // if asteroid has reached its final iteration and was destroyed, put it back in the pool
                Pool.Push(this);
            }
        }
    }
    protected virtual AsteroidBehaviour SpawnAsteroidFromPool(ObjectPool pool)
    {
        AsteroidBehaviour asteroid = pool.GetRecyclable <AsteroidBehaviour>();

        asteroid.Spawn();
        return(asteroid);
    }
示例#3
0
    public override void Shoot()
    {
        base.Shoot();

        // Ray
        gunLine.enabled = true;
        gunLine.SetPosition(0, transform.position);

        ray.origin    = transform.position;
        ray.direction = transform.forward;

        if (Physics.Raycast(ray, out rayHit, range, shootableMask))
        {
            AsteroidBehaviour asteroid = rayHit.collider.GetComponent <AsteroidBehaviour>();
            if (asteroid != null)
            {
                asteroid.HitEffect(rayHit.point);
                asteroid.TakeDamage(damage);
            }
            gunLine.SetPosition(1, rayHit.point);
        }
        else
        {
            gunLine.SetPosition(1, ray.origin + ray.direction * range);
        }
    }
    private void fireMissile(AsteroidBehaviour asteroidScript, GameObject asteroidInstance)
    {
        GameObject       instance      = Instantiate(missile, new Vector3(0, 0, 0), Quaternion.identity);
        MissileBehaviour missileScript = instance.GetComponent <MissileBehaviour>() as MissileBehaviour;

        missileScript.velocity = CalculateMissileVelocity(asteroidScript.mousePositionAtTakeoff, asteroidScript.velocity);
        missileScript.target   = asteroidInstance;
    }
 void Start()
 {
     m_ReceiveDamageEffect = GetComponent <ReceiveDamageEffect>();
     if (m_IsMain)
     {
         m_AsteroidBehaviour = m_Chunk.GetComponent <AsteroidBehaviour>();
     }
     m_ExplosionAudio = GetComponent <AudioSource>();
     m_CanExplode     = true;
 }
示例#6
0
    public void Spawn(Transform playerLocation)
    {
        int objNum;

        //Choose a numner for the game object
        objNum = Random.Range(0, spawnItems.Length);
        //Create the object
        AsteroidBehaviour asteroid = Instantiate(spawnItems[objNum], transform.position, Quaternion.identity) as AsteroidBehaviour;

        asteroid.Target = playerLocation;
    }
示例#7
0
 // Update is called once per frame
 void Update()
 {
     age += Time.deltaTime;
     if (age >= fireRate)
     {
         GameObject        Bob;
         AsteroidBehaviour Greg = Meteor.GetComponent <AsteroidBehaviour>();
         Greg.MovingSpeed = daddySpeed;
         Greg.isMoving    = true;
         Greg.isExplody   = daddyIsExplody;
         Bob = (Instantiate(Meteor, transform.position, transform.rotation));
         age = 0;
     }
 }
 // LateUpdate so AsteroidBehaviour has updated first
 void LateUpdate()
 {
     if (Input.GetMouseButtonUp(0))
     {
         spawning = GameObject.FindGameObjectsWithTag("Spawning");
         // TODO: fix the assumption here
         GameObject        instance       = spawning[0];
         AsteroidBehaviour asteroidScript = instance.GetComponent <AsteroidBehaviour>() as AsteroidBehaviour;
         if (TrajectoryWithinSafetyZone(asteroidScript.mousePositionAtTakeoff, asteroidScript.velocity))
         {
             fireMissile(asteroidScript, instance);
         }
         instance.tag = "Untagged";
     }
 }
示例#9
0
    private void Awake() 
	{
        m_rigidbody2D = GetComponent<Rigidbody2D>();
        m_velocity = Vector2.zero;
        m_objOn = null;

        if (m_target == null)
        {
            asteroidBh = transform.root.GetComponent<AsteroidBehaviour>();
            return;
        }

        m_startPos = transform.position;
        m_endPos = m_target.position;
        m_curTarget = m_endPos;
        
	}
    public void DestroyAsteroid(GameObject obj, int playerId = -1)
    {
        Debug.Log("destroy asteroid");

        if (_asteroids.Remove(obj))
        {
            //create new to replace old one
            Debug.Log("Creating a new asteroid to replace old");
            CreateAsteroid();
        }
        else
        {
            Debug.LogWarning("Destroying asteroid that's not on the list!");
        }

        AsteroidBehaviour behaviour = obj.GetComponent <AsteroidBehaviour> ();

        behaviour.DestroyMe(playerId);
    }
示例#11
0
    // Spawn asteroids for this level.
    IEnumerator LevelStart()
    {
        Debug.Log("LEVEL STARTING");
        m_UIText.text = "Level " + m_Level;

        // Disable ship controls (currently ship is inactive in Start, but may change).
        m_Ship.SetActive(true);
        //m_Ship.GetComponent<ShipMovement>().enabled = false;
        //m_Ship.GetComponent<ShipShooter>().enabled = false;

        // Reset ship position/velocity.
        //m_Ship.GetComponent<Rigidbody>().velocity = Vector3.zero;
        //m_Ship.GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
        //m_Ship.transform.position = Vector3.zero;


        yield return(new WaitForSeconds(2f));


        // Spawn some asteroids.
        Poolable asteroid;

        for (int i = 0; i < m_AsteroidCount; i++)
        {
            if (i < m_AsteroidCount / 2)
            {
                asteroid = m_AsteroidBigPool.Pop();
            }
            else
            {
                asteroid = m_AsteroidSmallPool.Pop();
            }

            AsteroidBehaviour behaviour = asteroid.GetComponent <AsteroidBehaviour>();
            asteroid.gameObject.SetActive(true);
            behaviour.SpawnRandomPosition();
            behaviour.SetRandomForces();
        }
    }
    // Called when hit by a bullet trigger collider.
    void OnTriggerEnter(Collider other)
    {
        // other = Bullet. Inactivate it until it repools itself.
        other.gameObject.SetActive(false);

        if (gameObject.CompareTag("AsteroidBig"))
        {
            // Split the big asteroid into 2 smaller ones.
            for (int i = 0; i < 2; i++)
            {
                //GameObject a1 = Instantiate(m_SmallAsteroidPrefab);
                Poolable          small     = GameManager.instance.m_AsteroidSmallPool.Pop();
                AsteroidBehaviour behaviour = small.GetComponent <AsteroidBehaviour>();
                small.transform.position = gameObject.transform.position;
                small.gameObject.SetActive(true);
                behaviour.SetRandomForces();
            }

            // Recycle this (big) asteroid.
            GameManager.instance.m_AsteroidBigPool.Push(m_Poolable);
        }
        else // "AsteroidSmall"
        {
            // Recycle this (small) asteroid.
            GameManager.instance.m_AsteroidSmallPool.Push(m_Poolable);
        }

        // Play the explosion sound clip via SM (because object will be destroyed).
        // Could also use  AudioSource.PlayClipAtPoint()
        //SoundManager.instance.PlaySingle(m_ExplosionClip);

        // Activate an explosion.
        SpawnExplosion();
        //Poolable explosion = GameManager.instance.m_ExplosionPool.Pop();
        //explosion.transform.position = transform.position;
        //explosion.transform.Rotate(new Vector3(0f, 0f, 360f * Random.value));
        //explosion.gameObject.SetActive(true);
    }
示例#13
0
    // Pop all asteroids out of their pools. (also sets position/forces)
    void PopAllAsteroids()
    {
        int count = m_AsteroidParent.childCount;

        for (int i = 0; i < count; i++)
        {
            GameObject asteroid = m_AsteroidParent.GetChild(i).gameObject;

            if (asteroid.CompareTag("AsteroidBig"))
            {
                m_AsteroidBigPool.Pop();
            }
            else
            {
                m_AsteroidSmallPool.Pop();
            }

            AsteroidBehaviour behaviour = asteroid.GetComponent <AsteroidBehaviour>();
            asteroid.SetActive(true);
            behaviour.SpawnRandomPosition();
            behaviour.SetRandomForces();
        }
    }
示例#14
0
 public static void SpawnSmallAsteroid(Vector3 position)
 {
     AsteroidBehaviour asteroid = instance.smallAsteroidPool.GetRecyclable<AsteroidBehaviour>();
     asteroid.SpawnAt(position);
 }
示例#15
0
 public void Despawn(AsteroidBehaviour asteroidBehaviour)
 {
     _spawnedAsteroids.Remove(asteroidBehaviour);
     _asteroidsPool.Despawn(asteroidBehaviour);
     AsteroidDespawned?.Invoke(asteroidBehaviour.Asteroid);
 }
示例#16
0
 void Awake()
 {
     astroBehaviour = GetComponent <AsteroidBehaviour>();
     rigidbody      = GetComponent <Rigidbody>();
 }