public void Invoke(TowerInstance target) { for (int i = _listeners.Count - 1; i >= 0; i--) { _listeners[i].Invoke(target); } }
// Use this for initialization void Start() { Tiles tiles = new Tiles(tilePrefab); Tile center = tiles.GetTile(Tiles.SIZE / 2, Tiles.SIZE / 2); GameObject tower = Instantiate(towerPrefab, new Vector3(Tiles.SIZE / 2 * 15, 0f, Tiles.SIZE / 2 * 15), towerPrefab.transform.rotation); Tower baseTower = new Tower(0, "Base", 100, 100, 0); TowerInstance towerInstance = new TowerInstance(baseTower, center, tower); TowerScript script = tower.GetComponent <TowerScript>(); script.tower = towerInstance; script.tile = center; center.SetUsed(true); center.Hold(towerInstance); TechTree.AddTower(false, new AttackTower(10, "Basic Tower", 10, 0, 35, 5, 10)); TechTree.AddTower(false, new ResourceTower(10, "Small Tree", 10, 10, 200, 1)); TechTree.AddTower(false, new UpgradeTower(25, "Upgrade Tower", 35, 0, 25)); TechTree.AddTower(true, new AttackTower(25, "Better Tower", 15, 0, 75, 10, 15)); }
private void GetCollider(TowerInstance t) { float rangeWithBonus = range * (float)t.GetTotalUpgrades(Upgrade.UpgradeType.Range); Vector3 center = t.GetPosition() + new Vector3(0, 8f, 0); Collider[] hitColliders = Physics.OverlapSphere(center, rangeWithBonus); double max = -9999; attackCollider = null; for (int i = 0; i < hitColliders.Length; i++) { if (hitColliders[i].tag == "enemy") { EnemyInstance ei = hitColliders[i].GetComponentInParent <EnemyScript>().enemy; if (ei != null) { double thisValue = Math.Pow(ei.GetAttackPriority(), 2); if (thisValue > max) { max = thisValue; attackCollider = hitColliders[i]; } } } } }
public void UpdateStatistics(TowerInstance target) { if (TowersBuilt != null) { TowersBuilt.Value++; } }
// Use this for initialization void Start() { // create towers float r = radius; for (int j = 0; j < numberRows; j++) { int numTowers = (int)(r / spacing); float angleInc = angleSpread / numTowers; for (int i = -numTowers / 2; i <= numTowers / 2; i++) { float newX = -r *Mathf.Cos(-i *angleInc); float newZ = -r *Mathf.Sin(-i *angleInc); GameObject t = (GameObject)UnityEngine.Object.Instantiate(towerPrefab, this.transform); t.transform.localPosition = new Vector3(newX, 0, newZ); t.SetActive(true); TowerInstance ti = t.GetComponent <TowerInstance>(); ti.hit += OnTowerHit; towers.Add(ti); } r *= radiusIncrement; } numberTowers = towers.Count; numberAliveTowers = numberTowers; towerNumberChanged.Dispatch(numberAliveTowers); }
public void ImportModifiers(TowerInstance tower) { var specials = tower.SpecialComponents.ToLookup(sc => sc.GetType()); foreach (var modifier in _allModifiers) { switch (modifier) { case BaseTowerModifier towerModifier: towerModifier.AddToTower(tower); break; case ReduceArmorModifier reduceArmorModifier: foreach (var reduceArmorComponent in specials[typeof(ReduceArmorComponent)]) { reduceArmorModifier.AddToTowerSpecial((ReduceArmorComponent)reduceArmorComponent); } break; case ReduceSpeedAmountModifier reduceSpeedAmountModifier: foreach (var reduceSpeedComponent in specials[typeof(ReduceSpeedComponent)]) { reduceSpeedAmountModifier.AddToTowerSpecial((ReduceSpeedComponent)reduceSpeedComponent); } break; // add more stuff } } }
void OnTowerHit(TowerInstance ti) { Debug.Log("TOWER HIT"); towers.Remove(ti); ti.hit -= OnTowerHit; numberAliveTowers--; towerNumberChanged.Dispatch(numberAliveTowers); }
public override void Upgrade(TowerUpgradeDirection direction, Game game) { base.Upgrade(direction, game); if (direction == TowerUpgradeDirection.Range) { float radius = Range / 30f; TowerInstance.GetComponent <CircleCollider2D>().radius = radius; TowerInstance.transform.GetChild(0).localScale = new Vector3(2f * radius, 2f * radius, 1f); } }
// Update is called once per frame void Update() { canvas.enabled = (Game.GetSelectedTower() != null && Game.GetSelectedTower().GetTower() is UpgradeTower); if (Game.GetSelectedTower() != null && Game.GetSelectedTower() != selectedMemory && Game.GetSelectedTower().GetTower() is UpgradeTower) { selectedMemory = Game.GetSelectedTower(); Refresh(); } }
public Tower(Vector3 pos, Vector3 size, Matrix orientation, Color color) { // Physical representation //physicsObject = new TowerPhysicsObject(size, orientation, pos); // Graphical representation Matrix transform = Matrix.CreateTranslation(pos) * orientation; graphicsInstance = new TowerInstance(transform, size, color); }
public void Act(TowerInstance t) { //if (currentTower != null) //{ // bool finished = TechTree.Research(currentTower); // if (finished) // { // currentTower = null; // } //} }
private void StartParticles(TowerInstance t) { GameObject obj = t.GetGameObject(); if (obj != null) { ParticleSystem[] psArray = obj.GetComponentsInChildren <ParticleSystem>(); if (psArray.Length > 0 && psArray[0].isStopped) { psArray[0].Play(); } } }
public void Act(TowerInstance t) { int[] tilePos = t.GetPosition(); Vector3 center = new Vector3(tilePos[0], 2.5f, tilePos[1]); Collider[] hitColliders = Physics.OverlapSphere(center, range); for (int i = 0; i < hitColliders.Length; i++) { hitColliders[i].SendMessage("AddHealth", -damage, SendMessageOptions.DontRequireReceiver); } }
public void Act(TowerInstance t) { GameObject obj = t.GetGameObject(); if (obj != null) { ParticleSystem[] psArray = obj.GetComponentsInChildren <ParticleSystem>(); if (psArray.Length > 0) { psArray[0].Emit(15); } } Game.AddLumber(gain); }
public void Clicked() { TowerInstance selectedTower = Game.GetSelectedTower(); if (selectedTower != null) { if (Game.GetLumber() >= upgrade.GetCost()) { selectedTower.AddUpgrade(upgrade); upms.Refresh(); Game.AddLumber(-upgrade.GetCost()); } } }
public void Act(TowerInstance t) { GameObject obj = t.GetGameObject(); if (obj != null) { ParticleSystem[] psArray = obj.GetComponentsInChildren <ParticleSystem>(); if (psArray.Length > 0) { psArray[0].Emit(15); } } int gainWithUpgrades = (int)Math.Round(gain * t.GetTotalUpgrades(Upgrade.UpgradeType.Gain)); Game.AddLumber(gainWithUpgrades); }
public void Clicked() { TowerInstance ti = Game.GetSelectedTower(); if (ti != null) { //Tile tile = ti.GetTile(); //if (tile.GetHeld() != null) { // tile.SetUsed(false); // Destroy(ti.GetGameObject()); // tile.Hold(null); // Game.SelectTower(null); ti.AddHealth(-ti.GetHealth()); Game.AddLumber((int)Math.Round((ti.GetCost() + ti.GetUpgradesSum()) / 3.0)); //} } }
// Update is called once per frame void Update() { if (Game.GetSelectedTower() != null && Game.GetSelectedTower() != selectedMemory) { selectedMemory = Game.GetSelectedTower(); Refresh(); } if (Game.GetSelectedTower() != null) { canvas.enabled = true; } else { canvas.enabled = false; } }
public void Clicked() { TowerInstance ti = Game.GetSelectedTower(); if (ti != null) { Tile tile = ti.GetTile(); if (tile.GetHeld() != null) { tile.SetUsed(false); Destroy(ti.GetGameObject()); tile.Hold(null); Game.SelectTower(null); Game.AddLumber((int)Math.Round(ti.GetCost() / 3.0)); } } }
public void Clicked() { if (Game.GetLumber() >= tower.GetCost()) { Game.AddLumber(-tower.GetCost()); int[] pos = Game.GetSelected().GetPosition(); GameObject towerObject = Instantiate(towerPrefab, new Vector3(pos[0] * 15, 0f, pos[1] * 15), towerPrefab.transform.rotation); TowerInstance towerInstance = new TowerInstance(tower, Game.GetSelected(), towerObject); towerObject.GetComponent <TowerScript>().tower = towerInstance; towerObject.GetComponent <TowerScript>().tile = Game.GetSelected(); Game.GetSelected().SetUsed(true); Game.GetSelected().Hold(towerInstance); Game.Select(null); } }
public void Clicked() { TowerInstance instance = Game.GetSelectedTower(); if (instance != null && instance.GetTower() is UpgradeTower) { System.Object data; if (upgrade != null) { data = upgrade; } else { data = tower; } instance.SetData(data); } Game.SelectTower(null); }
public void Act(TowerInstance t) { System.Object data = t.GetData(); if (data != null && data is Tower) { if (TechTree.GetAvailableTowers().Contains(data as Tower)) { t.SetData(null); StopParticles(t); } else { TechTree.ResearchTower(data as Tower); StartParticles(t); } } if (data != null && data is Upgrade) { if (TechTree.GetAvailableUpgrades().Contains(data as Upgrade)) { t.SetData(null); StopParticles(t); } else { TechTree.ResearchUpgrade(data as Upgrade); StartParticles(t); } } if (data == null) { StopParticles(t); } }
public override void ElementUpgrade(ElelmentType elementType, Game game) { base.ElementUpgrade(elementType, game); switch (elementType) { case ElelmentType.Ice: TowerInstance.GetComponent <SpriteRenderer>().color = new Color(170f / 255f, 255f / 255f, 228 / 255f); break; case ElelmentType.Fire: TowerInstance.GetComponent <SpriteRenderer>().color = new Color(255f / 255f, 84f / 255f, 0f / 255f); break; case ElelmentType.Thunder: TowerInstance.GetComponent <SpriteRenderer>().color = new Color(120f / 255f, 56f / 255f, 138f / 255f); break; case ElelmentType.Wind: TowerInstance.GetComponent <SpriteRenderer>().color = new Color(160f / 255f, 255f / 255f, 171f / 255f); break; case ElelmentType.Poison: TowerInstance.GetComponent <SpriteRenderer>().color = new Color(37f / 255f, 82f / 255f, 33f / 255f); break; case ElelmentType.Wood: TowerInstance.GetComponent <SpriteRenderer>().color = new Color(0f / 255f, 197f / 255f, 9f / 255f); break; } if (elementType == ElelmentType.Wind) { float radius = Range / 30f; TowerInstance.GetComponent <CircleCollider2D>().radius = radius; TowerInstance.transform.GetChild(0).localScale = new Vector3(2f * radius, 2f * radius, 1f); } }
public void Act(TowerInstance t) { GetCollider(t); if (attackCollider != null) { int damageWithBonus = (int)Math.Round(damage * t.GetTotalUpgrades(Upgrade.UpgradeType.Damage)); GameObject proj = UnityEngine.Object.Instantiate(projectilePrefab, t.GetGameObject().transform); proj.transform.position += new Vector3(0, 8f, 0); GameObject bullet; if (projectile != null) { bullet = UnityEngine.Object.Instantiate(projectile, proj.transform); proj.GetComponent <ProjectileScript>().bullet = bullet.transform; } proj.GetComponent <ProjectileScript>().target = attackCollider.transform; proj.GetComponent <ProjectileScript>().damage = damageWithBonus; } else { t.SetCooldown(0); } }
public virtual void Act(TowerInstance t) { }
public override void AddToTower(TowerInstance tower) { tower.NumberOfTargets.AddModifier(this); }
public override void RemoveFromTower(TowerInstance tower) { tower.NumberOfTargets.RemoveModifier(this); }
public static void SelectTower(TowerInstance newTower) { selectedTower = newTower; }
public double GetPriority(TowerInstance ti, Vector3 pos) { return(enemy.GetPriority(ti, pos)); }
void FixedUpdate() { if (enemy.IsDead()) { System.Random r = new System.Random(); if (r.NextDouble() < chance) { Game.AddMP((int)Math.Round(enemy.GetMaxHealth() * .20)); } Enemies.KillEnemy(enemy); Destroy(healthBar); GameObject.Destroy(gameObject); // Make this dependent on enemy type Game.IncreaseScore(1); } enemy.Update(); if (enemy.GetAttackState()) { if (hitTower == null) { enemy.SetAttackState(false); } else if (enemy.GetCooldown() <= 0) { if (enemy.GetTypeName() == Enemy.EnemyType.Boomer) { hitTower.SendMessageUpwards("DestroyAll"); } else { enemy.SetCooldown((int)Math.Round(120 / ((30 + enemy.GetAttackSpeed() / 3) * 0.01))); hitTower.SendMessageUpwards("AddHealth", -enemy.GetDamage()); } } } else { float step = enemy.GetSpeed() * Time.deltaTime; // calculate distance to move if (towerTarget != null) { float distance = Vector3.Distance(transform.position, towerTarget.position + new Vector3(0, 8f, 0)); if (distance < enemy.GetAttackRange()) { enemy.SetAttackState(true); } transform.position = Vector3.MoveTowards(transform.position, towerTarget.position + new Vector3(0, 8f, 0), step); } else { transform.position = Vector3.MoveTowards(transform.position, Game.baseTower.GetPosition() + new Vector3(0, 8f, 0), step); } Collider[] hitColliders = Physics.OverlapSphere(transform.position, enemy.GetDetectionRange()); double highest = -9999; for (int i = 0; i < hitColliders.Length; i++) { if (hitColliders[i].tag == "tower" || hitColliders[i].tag == "base") { TowerInstance ti = hitColliders[i].GetComponentInParent <TowerScript>().tower; if (ti != null) { double thisValue = enemy.GetPriority(ti, enemy.GetPosition()); if (thisValue > highest) { towerTarget = ti.GetGameObject().transform; highest = thisValue; hitTower = hitColliders[i]; } } } } } }