public GameObject fireSpread(Vector2 goalPos) { GameObject target = null; float minDist = 0; bool minStatus = true; foreach (GameObject creep in GameObject.FindGameObjectsWithTag("Creep")) { float creepDist = Mathf.Pow((creep.transform.position.x - this.transform.position.x), 2.0f) + Mathf.Pow((creep.transform.position.z - this.transform.position.z), 2.0f); if (creepDist < (Mathf.Pow(range, 2))) { float targetDist = Mathf.Pow((creep.transform.position.x - goalPos.x), 2.0f) + Mathf.Pow((creep.transform.position.z - goalPos.y), 2.0f); creep c = (creep)creep.GetComponent("creep"); bool hasStatus = false; for (int i = 1; i < c.currentStatuses.Length; i++) { if (c.currentStatuses[i] > 0) { hasStatus = true; break; } } //we assign a new target if it is closer to the goal or we don't have a target yet if ((minStatus && !hasStatus) || ((minStatus || (!minStatus && !hasStatus)) && (targetDist < minDist)) || minDist == 0) { target = creep; minDist = targetDist; minStatus = hasStatus; } } } return(target); }
// Update is called once per frame void Update() { if ((int)state == (int)gameState.battlePhase) { //continue spawning current wave sm.UpdateSpawn(); //execute turret AI foreach (GameObject currentTurret in GameObject.FindGameObjectsWithTag("Turret")) { turret t = (turret)currentTurret.GetComponent("turret"); t.Fire(new Vector2(9, 9)); } //execute creep AI GameObject[] creeps = GameObject.FindGameObjectsWithTag("Creep"); foreach (GameObject currentCreep in creeps) { creep c = (creep)currentCreep.GetComponent("creep"); c.Seek(new Vector2(9, 9), currentPath, 10); c.updateStatuses(); } //update missiles foreach (GameObject currentMissile in GameObject.FindGameObjectsWithTag("Missile")) { missile m = (missile)currentMissile.GetComponent("missile"); m.Fly(); } //check if wave is defeated if (creeps == null || creeps.Length == 0) { Debug.Log("here"); if (sm.isWaveDefeated()) { updateAvailableUnits(sm.currentWave); if (sm.currentWave == sm.totalWaves) { totalWin(); } else { win(); } } } if (tm.selected == selectedState.creep && tm.selectedObject != null) { //apply stun creep c = (creep)tm.selectedObject.GetComponent("creep"); c.applyStatus(creepStatus.stun, 3 * c.durationMultipliers[1]); //tm.selected = selectedState.none; } tm.selected = selectedState.none; tm.clickable = true; } }
void InitGridVal(int x, int y) { cellVal elem = (cellVal)Enum.Parse(typeof(cellVal), m_gridarr[x, y].m_val.ToString()); Console.WriteLine(elem.ToString()); var temp = elem.ToString(); if (temp != "empty") { var newobj = Instantiate(GameObject.Find(elem.ToString()), m_gridarr[x, y].m_pos, Quaternion.identity); if (temp == "creep") { creep newcreep = newobj.GetComponent <creep>(); newcreep.InitGrid(m_gridarr); } } }
public GameObject fireStrong() { GameObject target = null; float maxHealth = 0; foreach (GameObject creep in GameObject.FindGameObjectsWithTag("Creep")) { float creepDist = Mathf.Pow((creep.transform.position.x - this.transform.position.x), 2.0f) + Mathf.Pow((creep.transform.position.z - this.transform.position.z), 2.0f); if (creepDist < (Mathf.Pow(range, 2))) { creep c = (creep)creep.GetComponent("creep"); float targetHealth = c.health; //we assign a new target if it is closer to the goal or we don't have a target yet if ((targetHealth > maxHealth) || maxHealth == 0) { target = creep; maxHealth = targetHealth; } } } return(target); }
void onHit() { GameObject[] creeps = GameObject.FindGameObjectsWithTag("Creep"); foreach (GameObject creep in creeps) { if (creep != null) { float dFromCenter = Vector3.Distance(creep.transform.position, this.transform.position); //Debug.Log(dFromCenter); if (dFromCenter < radius) { //splash removed //float splashDamage = ((radius - dFromCenter)/radius)*damage; creep c = (creep)creep.GetComponent("creep"); c.hit(damage); c.applyStatus((creepStatus)statusEffect, potency); } } } Destroy(this.gameObject); }
public State(creep cp) { m_creep = cp; }
public Idle(creep cp) : base(cp) { }
public FindPathState(creep cp) : base(cp) { }
public MovingState(creep cp) : base(cp) { }