private void FireTo(int color) { if (bManager.IsActive(BonusName.DOOM_HAMMER)) { List <AKillable> targets = (bManager.IsActive(BonusName.MULTI_STRIKES) ? gManager.HitAllFirstEntities(ref color) : gManager.HitAllEntities(color)); if (targets == null) { GetHit(true); } else { audioSource.PlayOneShot(shootClip[Random.Range(0, shootClip.Count)], 1.0f); GameObject atk = Instantiate(hammerPrefab, this.transform.position, Quaternion.identity) as GameObject; atk.GetComponent <HammerAttack>().Init(targets, gManager.GetColor(color)); } } else { //Si on est sous multiStrike, on choppe le premier ennemi peu importe la couleur pressée. AKillable target = (bManager.IsActive(BonusName.MULTI_STRIKES) ? gManager.HitFirstEntity(ref color) : gManager.HitEntity(color)); if (target == null) { GetHit(true); } else { audioSource.PlayOneShot(shootClip[Random.Range(0, shootClip.Count)], 1.0f); GameObject atk = Instantiate(attackPrefab, this.transform.position, Quaternion.identity) as GameObject; atk.GetComponent <HeroAttack>().Init(target.transform, gManager.GetColor(color)); } } }
void Update() { if (target != null) { if (Vector2.Distance(this.transform.position, target.position) < range) { AKillable ak = target.GetComponent <AKillable>(); ak.PlayHit(); ak.isHitByAttack = true; //On détruit le particle system 0.3f secondes plus tard pour lui laisser le temps de finir l'animation partColor.loop = false; partColor.transform.parent = null; GameObject.Destroy(partColor.gameObject, 0.3f); GameObject.Destroy(this.gameObject); } else { transform.position = Vector3.MoveTowards(transform.position, target.transform.position, speed * Time.deltaTime); } } else { GameObject.Destroy(this.gameObject); } }
//Stock la valeur de la couleur dans l'argument. Nécessaire pour les ennemis qui changent de couleur après un coup public AKillable HitFirstEntity(ref int color) { AKillable res = null; foreach (AKillable entity in entityList) { if (entity.GetColor() != -1) { if (res == null) { res = entity; } else if (res != null && (res.transform.position.y > entity.transform.position.y)) { res = entity; } } } if (res) { color = res.GetColor(); res.GetHit(1); } return(res); }
void OnTriggerEnter2D(Collider2D other) { AKillable entity = other.GetComponent <AKillable>(); if (entity) { entity.Kill(hardKill); } }
//Direction should be between -1 and 1 public void Init(float time, float direction, AKillable own, HeroController target, float s, int c = -1) { base.Init(own, target, s, c); fuse = time; spriteRenderer = GetComponent <SpriteRenderer>(); colored = gameManager.GetColor(color); step = (colored - new Color(0.3f, 0.3f, 0.3f)) / fuse; spriteRenderer.color = colored; movement = new Vector2(direction * speed, -speed); }
//Touche tous les ennemis de la couleur du premier ennemi public List <AKillable> HitAllFirstEntities(ref int color) { List <AKillable> res = null; AKillable e = HitFirstEntity(ref color); if (e != null) { res = HitAllEntities(color); if (res == null) { res = new List <AKillable>(); } res.Insert(0, e); } return(res); }
// return l'enemie le plus bas de la couleur // return null si pas de couleur private AKillable FindEntityByColor(int colorVal) { AKillable res = null; foreach (AKillable entity in entityList) { if (entity.GetColor() == colorVal) { if (res == null) { res = entity; } else if (res != null && (res.transform.position.y > entity.transform.position.y)) { res = entity; } } } return(res); }
public void Init(AKillable own, HeroController target, float s, int color = -1) { base.Init(target, 1.0f, color); owner = own; speed = s; }
//Retire l'ennemi de la liste public void RemoveEntity(AKillable obj) { entityList.Remove(obj); }
//ajoute un enemy dans la liste et lui attribue une couleur. public void AddEntity(AKillable obj) { entityList.Add(obj); //attribue la couleur d'affichage }
public void Init(Transform h, AKillable own, HeroController target, float s, int c = -1) { base.Init(own, target, s, c); hand = h; }