private void dies() { VersusWorldBehavior world = GameObject.Find("GameManager").GetComponent <VersusWorldBehavior>(); if (gameObject.name == "OrangeCity") { world.BaseDies(1); } else if (gameObject.name == "BlueCity") { world.BaseDies(2); } else if (gameObject.name == "ChartreuseCity") { world.BaseDies(3); } else if (gameObject.name == "PeriwinkleCity") { world.BaseDies(4); } GetComponent <CircleCollider2D>().center += new Vector2(100f, 100f); }
/* * * // Update is called once per frame * void Update () { #region Orb Spawner Logic * //Disabled for demo. * /* * if ( Input.GetKeyDown(KeyCode.F2)) { // Manual Spawner * SpawnOrbs(); * } */ // Automated spawner. Uses the metrics of time since last spawn and limits the number of orbs on the screen. /* * if ( Time.realtimeSinceStartup - mlastRamp > mRampInterval ) { * mlastRamp = Time.realtimeSinceStartup; * /*if ( mSpawnTime > mMinSpawnTime ) { * mSpawnTime -= mTimeInterval; * }*/ /* mSpawnMinSize += mMassInterval; * } * * if ( Time.realtimeSinceStartup - mLastSpawn > mSpawnTime && mCurOrbs < mMaxOrbs && !pause.GameIsPaused() ) { * SpawnOrbs(); * mLastSpawn = Time.realtimeSinceStartup; * //Added this to increase wave frequency. * //mSpawnTime = mSpawnTime - 2f; * * //if (mSpawnTime < 0f) { * // mSpawnTime = 0f; * //} * } #endregion * } * * /* #region Asteroid Spawner * * public int Orbs { * get { return mCurOrbs; } * set { mCurOrbs = value; } * } */ protected override void SpawnOrbs() { int topNum, botNum; // Number spawning from top/bottom VersusWorldBehavior world = GetComponent <VersusWorldBehavior>(); Vector2 spawnPoint, spawnDir; float spawnMass; for (int i = 0; i < mSpawnNum; ++i) { float spawnLoc = world.WorldMax.y + (i + 1) * mSpawnStagger; // Top spawnPoint = new Vector2(0f, spawnLoc); spawnDir = new Vector2(Random.Range(-mSpawnSpread, mSpawnSpread), -1f).normalized *mSpawnSpeed; spawnMass = Random.Range(mSpawnMinSize, mSpawnMaxSize); ThrowOrb(spawnPoint, spawnDir, spawnMass); // Left spawnPoint = new Vector2(-spawnLoc, 0f); spawnDir = new Vector2(1f, Random.Range(-mSpawnSpread, mSpawnSpread)).normalized *mSpawnSpeed; spawnMass = Random.Range(mSpawnMinSize, mSpawnMaxSize); ThrowOrb(spawnPoint, spawnDir, spawnMass); // Bot spawnPoint = new Vector2(0f, -spawnLoc); spawnDir = new Vector2(Random.Range(-mSpawnSpread, mSpawnSpread), 1f).normalized *mSpawnSpeed; spawnMass = Random.Range(mSpawnMinSize, mSpawnMaxSize); ThrowOrb(spawnPoint, spawnDir, spawnMass); // Right spawnPoint = new Vector2(spawnLoc, 0f); spawnDir = new Vector2(-1f, Random.Range(-mSpawnSpread, mSpawnSpread)).normalized *mSpawnSpeed; spawnMass = Random.Range(mSpawnMinSize, mSpawnMaxSize); ThrowOrb(spawnPoint, spawnDir, spawnMass); } //Added }
void Update() { if (pause.GameIsPaused()) { kSpeedBegin += Time.time; kGrowBegin += Time.time; mWaveBlastChargeTime += Time.time; } if (mSpeedUp == true) { if (speedupParticle != null) { speedupParticle.transform.position = transform.position; } if (Time.realtimeSinceStartup - kSpeedBegin > kSpeedEnd) { mSpeedUp = false; kHeroSpeed = kDefaultHeroSpeed; rigidbody2D.mass = kDefaultMass; kShotgunBlastSpawnInterval = kShotgunBlastDefaultSpawnInterval; kWaveBlastSpawnInterval = kWaveBlastDefaultSpawnInterval; Destroy(speedupParticle); } } if (mSpikeUp == true) { if (spikeupParticle != null) { spikeupParticle.transform.position = transform.position; } if (Time.realtimeSinceStartup - kSpikeBegin > kSpikeEnd) { mSpikeUp = false; } } if (mGrowUp == true) { if (growupParticle != null) { growupParticle.transform.position = transform.position; } if (Time.realtimeSinceStartup - kGrowBegin > kGrowEnd) { mGrowUp = false; kHeroSpeed = kDefaultHeroSpeed; transform.localScale -= new Vector3(mGrowScale, mGrowScale, 0.0f); Destroy(growupParticle); rigidbody2D.mass = kDefaultMass; } } //No longer necessary. Maybe. //DieCheck(); // Check if ship is dead VersusWorldBehavior world = GameObject.Find("GameManager").GetComponent <VersusWorldBehavior>(); world.ClampAtWorldBounds(this.gameObject, this.renderer.bounds); if (isController == false && !respawn.GameIsPaused() && !count.GetIsCounting()) { // Ship mouse aim mousedir = world.mMainCamera.ScreenToWorldPoint(Input.mousePosition) - transform.position; mousedir.Normalize(); transform.up = mousedir; if (Input.GetAxisRaw("Horizontal") > 0f || Input.GetAxisRaw("Horizontal") < 0f || Input.GetAxisRaw("Vertical") > 0f || Input.GetAxisRaw("Vertical") < 0f) { Vector2 move = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")); rigidbody2D.AddForce(move.normalized * kHeroSpeed); } /* * if (Input.GetAxis("Horizontal") > 0.1f || Input.GetAxis("Horizontal") < -0.1f || * Input.GetAxis("Vertical") > 0.1f || Input.GetAxis("Vertical") < -0.1f) { * Vector2 move = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")); * rigidbody2D.AddForce(move.normalized * kHeroSpeed); * } */ //Enable with GetAxisRaw instead of GetAxis for the movement for exact controls. /* * if (Input.GetAxisRaw("Horizontal") == 0f && Input.GetAxisRaw("Vertical") == 0f) { * rigidbody2D.velocity = Vector3.zero; * rigidbody2D.angularVelocity = 0f; * } */ // Wave Blast single click if (Input.GetButtonDown("Fire1")) { StartWaveBlast(); StartCoroutine("WaveBlastChargeCoroutine"); mWaveBlastChargeTime = Time.realtimeSinceStartup; } // Wave Blast Charge fire if (Input.GetButtonUp("Fire1")) { StopCoroutine("WaveBlastChargeCoroutine"); StopChargeParticle(); FireChargedWaveBlast(); } // Shotgun Blast single click if (Input.GetButtonDown("Fire2")) { StartShotgunBlast(); StartCoroutine("ShotgunBlastChargeCoroutine"); } // Shotgun Blast charge control if (Input.GetButtonUp("Fire2")) { StopCoroutine("ShotgunBlastChargeCoroutine"); StopChargeParticle(); FireChargedShotgunBlast(); } } else if (isController == true && !respawn.GameIsPaused() && !count.GetIsCounting()) { // Player movement //Vector2 move = new Vector2(Input.GetAxis(controller + "Horizontal"), Input.GetAxis(controller + "Vertical")); Vector2 move = new Vector2(Input.GetAxisRaw(controller + "Horizontal"), Input.GetAxisRaw(controller + "Vertical")); rigidbody2D.AddForce(move.normalized * kHeroSpeed); // Right Stick Aim transform.up += new Vector3(Input.GetAxis(controller + "RHorz"), Input.GetAxis(controller + "RVert"), 0); // Wave blast single click if (Input.GetButtonDown(controller + "Fire1")) { StartWaveBlast(); StartCoroutine("WaveBlastChargeCoroutine"); mWaveBlastChargeTime = Time.realtimeSinceStartup; } // Wave blast charge if (Input.GetButtonUp(controller + "Fire1")) { StopCoroutine("WaveBlastChargeCoroutine"); StopChargeParticle(); FireChargedWaveBlast(); } // Shotgun single click if (Input.GetButtonDown(controller + "Fire2")) // this is Right-Control { StartShotgunBlast(); StartCoroutine("ShotgunBlastChargeCoroutine"); } // Shotgun charge if (Input.GetButtonUp(controller + "Fire2")) { StopCoroutine("ShotgunBlastChargeCoroutine"); StopChargeParticle(); FireChargedShotgunBlast(); } } }