// Checks with player is doing damage and minus the damage done from the other players health public void Damage(CharacterBattle attacker, int damageAmount) { healthSystem.Damage(damageAmount); // CodeMonkey.CMDebug.TextPopup("health " + healthSystem.GetHealthAmount(), GetPosition()); Vector3 dirFromAttacker = (GetPosition() - attacker.GetPosition()).normalized; if (isPlayerTeam) { GameObject.FindGameObjectWithTag("P1Life").GetComponent <Health>().health -= damageAmount; } else { GameObject.FindGameObjectWithTag("P2Life").GetComponent <Health>().health -= damageAmount; } DamagePopup.Create(GetPosition(), damageAmount, false); characterBase.SetColorTint(new Color(1, 0, 0, 1f)); Blood_Handler.SpawnBlood(GetPosition(), dirFromAttacker); if (healthSystem.IsDead()) { // Died Debug.Log("level" + " " + level + " " + "complete"); } }
private void Update() { float flySpeed = 400f; transform.position += flyDirection * flySpeed * Time.deltaTime; float scaleSpeed = 7f; transform.localScale += Vector3.one * scaleSpeed * Time.deltaTime; float eulerSpeed = 360f * 4f; eulerZ += eulerSpeed * Time.deltaTime; transform.localEulerAngles = new Vector3(0, 0, eulerZ); spawnBloodTimer -= Time.deltaTime; if (spawnBloodTimer <= 0f) { float spawnBloodTimerMax = .016f; spawnBloodTimer = spawnBloodTimerMax; Blood_Handler.SpawnBlood(5, transform.position, flyDirection * -1f); } timer += Time.deltaTime; if (timer >= 1f) { Destroy(gameObject); } }
public void Damage(IEnemyTargetable attacker) { Vector3 bloodDir = (GetPosition() - attacker.GetPosition()).normalized; Blood_Handler.SpawnBlood(GetPosition(), bloodDir); int damageAmount = 30; DamagePopup.Create(GetPosition(), damageAmount, false); healthSystem.Damage(damageAmount); if (IsDead()) { FlyingBody.Create(GameAssets.i.pfEnemyFlyingBody, GetPosition(), bloodDir); Destroy(gameObject); } else { // Knockback transform.position += bloodDir * 5f; if (hitUnitAnim != null) { state = State.Busy; characterBase.PlayHitAnimation(bloodDir * (Vector2.one * -1f), SetStateNormal); } } }
public void Damage(Vector3 attackerPosition) { Vector3 bloodDir = (GetPosition() - attackerPosition).normalized; Blood_Handler.SpawnBlood(GetPosition(), bloodDir); // Knockback transform.position += bloodDir * 3f; }
public void Damage(CharacterBattle attacker, int damageAmount) { //damageAmount = 1; Debug.Log("##### No Damage"); Vector3 bloodDir = (GetPosition() - attacker.GetPosition()).normalized; Blood_Handler.SpawnBlood(GetPosition(), bloodDir); SoundManager.PlaySound(SoundManager.Sound.CharacterDamaged); DamagePopup.Create(GetPosition(), damageAmount, false); healthSystem.Damage(damageAmount); DamageFlash(); playerBase.GetUnitAnimation().PlayAnimForced(hitUnitAnimType, GetTargetDir(), 1f, (UnitAnim unitAnim) => { PlayIdleAnim(); }, null, null); if (IsDead()) { if (!IsPlayerTeam()) { // Enemy if (characterType != Character.Type.EvilMonster && characterType != Character.Type.EvilMonster_2 && characterType != Character.Type.EvilMonster_3) { // Don't spawn Flying Body for Evil Monster FlyingBody.Create(GameAssets.i.pfEnemyFlyingBody, GetPosition(), bloodDir); SoundManager.PlaySound(SoundManager.Sound.CharacterDead); } gameObject.SetActive(false); } else { // Player Team stats.special = 0; SoundManager.PlaySound(SoundManager.Sound.OooohNooo); } playerBase.GetUnitAnimation().PlayAnimForced(UnitAnim.GetUnitAnim("LyingUp"), 1f, null); healthWorldBar.Hide(); transform.localScale = new Vector3(-1, 1, 1); //gameObject.SetActive(false); //Destroy(gameObject); } else { // Knockback /* * transform.position += bloodDir * 5f; * if (hitUnitAnim != null) { * state = State.Busy; * enemyBase.PlayHitAnimation(bloodDir * (Vector2.one * -1f), SetStateNormal); * } */ } }
private void HandleAttack() { if (Input.GetKeyDown(KeyCode.Space)) { // Attack SetStateBusy(); Vector3 attackDir = lastMoveDir; EnemyHandler enemyHandler = getClosestEnemyHandlerFunc(GetPosition() + attackDir * 4f); if (enemyHandler != null) { // Has a target nearby attackDir = (enemyHandler.GetPosition() - GetPosition()).normalized; // Test if too close to dash const float tooCloseToDashDistance = 10f; if (Vector3.Distance(enemyHandler.GetPosition(), GetPosition()) > tooCloseToDashDistance) { // Dash towards attack distance transform.position = transform.position + attackDir * 4f; } // Is enemy within attack range? const float attackDistance = 30f; if (Vector3.Distance(enemyHandler.GetPosition(), GetPosition()) < attackDistance) { // Close enough to damage enemyHandler.GetHealthSystem().Damage(34); Blood_Handler.SpawnBlood(enemyHandler.GetPosition(), attackDir); } } else { // No nearby target transform.position = transform.position + attackDir * 4f; } lastMoveDir = attackDir; Transform swordSlashTransform = Instantiate(GameAssets.i.pfSwordSlash, GetPosition() + attackDir * 13f, Quaternion.Euler(0, 0, UtilsClass.GetAngleFromVector(attackDir))); swordSlashTransform.GetComponent <SpriteAnimator>().onLoop = () => Destroy(swordSlashTransform.gameObject); UnitAnimType activeAnimType = unitAnimation.GetActiveAnimType(); if (activeAnimType == GameAssets.UnitAnimTypeEnum.dSwordTwoHandedBack_Sword) { swordSlashTransform.localScale = new Vector3(swordSlashTransform.localScale.x, swordSlashTransform.localScale.y * -1, swordSlashTransform.localScale.z); unitAnimation.PlayAnimForced(GameAssets.UnitAnimTypeEnum.dSwordTwoHandedBack_Sword2, lastMoveDir, 1f, (UnitAnim unitAnim) => SetStateNormal(), null, null); } else { unitAnimation.PlayAnimForced(GameAssets.UnitAnimTypeEnum.dSwordTwoHandedBack_Sword, lastMoveDir, 1f, (UnitAnim unitAnim) => SetStateNormal(), null, null); } } }
private void EnemyMain_OnDamaged(object sender, EnemyMain.OnDamagedEventArgs e) { Vector3 bloodDir = (GetPosition() - e.attacker.GetPosition()).normalized; Blood_Handler.SpawnBlood(5, GetPosition(), bloodDir); enemyMain.HealthSystem.Damage(Mathf.RoundToInt(30 * e.damageMultiplier)); if (enemyMain.HealthSystem.IsDead()) { //FlyingBody.Create(GameAssets.i.pfEnemyFlyingBody, GetPosition(), bloodDir); enemyMain.DestroySelf(); } }
protected override void OnUpdate() { EntityQuery entityQuery = GetEntityQuery(typeof(Zombie)); int entityCount = entityQuery.CalculateEntityCount(); MarineShotZombieAction marineShotZombieAction; while (TestECS.queuedActions.TryDequeue(out marineShotZombieAction)) { if (EntityManager.Exists(marineShotZombieAction.marineEntity) && EntityManager.Exists(marineShotZombieAction.zombieEntity)) { float3 marinePosition = EntityManager.GetComponentData <Translation>(marineShotZombieAction.marineEntity).Value; float3 zombiePosition = EntityManager.GetComponentData <Translation>(marineShotZombieAction.zombieEntity).Value; float3 marineToZombieDir = math.normalize(zombiePosition - marinePosition); bool bonusEffects = (entityCount < 400 || UnityEngine.Random.Range(0, 100) < 60); if (bonusEffects) { WeaponTracer.Create(marinePosition + marineToZombieDir * 10f, (Vector3)zombiePosition + UtilsClass.GetRandomDir() * UnityEngine.Random.Range(0, 20f)); Shoot_Flash.AddFlash(marinePosition + marineToZombieDir * 14f); Blood_Handler.SpawnBlood(2, zombiePosition, marineToZombieDir); UtilsClass.ShakeCamera(TestECS.GetCameraShakeIntensity(), .05f); //Sound_Manager.PlaySound(Sound_Manager.Sound.Rifle_Fire, marinePosition); } Health zombieHealth = EntityManager.GetComponentData <Health>(marineShotZombieAction.zombieEntity); zombieHealth.health -= marineShotZombieAction.damageAmount; if (zombieHealth.health < 0) { // Zombie dead! FlyingBody.TryCreate(GameAssets.i.pfEnemyFlyingBody, zombiePosition, marineToZombieDir); EntityManager.DestroyEntity(marineShotZombieAction.zombieEntity); EntityManager.RemoveComponent <HasTarget>(marineShotZombieAction.marineEntity); } else { // Zombie still has health EntityManager.SetComponentData(marineShotZombieAction.zombieEntity, zombieHealth); } } else { if (EntityManager.Exists(marineShotZombieAction.marineEntity) && !EntityManager.Exists(marineShotZombieAction.zombieEntity)) { // Marine exists but zombie is dead EntityManager.RemoveComponent <HasTarget>(marineShotZombieAction.marineEntity); } } } }
public void Damage(Vector3 attackerPosition) { Vector3 bloodDir = (GetPosition() - attackerPosition).normalized; Blood_Handler.SpawnBlood(GetPosition(), bloodDir); // Knockback transform.position += bloodDir * 1.5f; health--; if (health == 0) { FlyingBody.Create(GameAssets.i.pfEnemyFlyingBody, GetPosition(), bloodDir); gameObject.SetActive(false); //transform.Find("Body").gameObject.SetActive(false); } }
public void Damage(CharacterBattle attacker, int damageAmount) { healthSystem.Damage(damageAmount); //CodeMonkey.CMDebug.TextPopup("Hit " + healthSystem.GetHealthAmount(), GetPosition()); Vector3 dirFromAttacker = (GetPosition() - attacker.GetPosition()).normalized; DamagePopup.Create(GetPosition(), damageAmount, false); characterBase.SetColorTint(new Color(1, 0, 0, 1f)); Blood_Handler.SpawnBlood(GetPosition(), dirFromAttacker); CodeMonkey.Utils.UtilsClass.ShakeCamera(1f, .1f); if (healthSystem.IsDead()) { // Died characterBase.PlayAnimLyingUp(); } }
public void Damage(CharacterBattle attacker, int damageAmount) { animator.Play("Hit"); healthSystem.Damage(damageAmount); Vector3 dirFromAttacker = (GetPosition() - attacker.GetPosition()).normalized; DamagePopup.Create(GetPosition(), damageAmount, false); Blood_Handler.SpawnBlood(GetPosition(), dirFromAttacker); CodeMonkey.Utils.UtilsClass.ShakeCamera(1f, .1f); if (healthSystem.IsDead()) { Dead = true; // Died state = State.Dead; //animator.Play("DieBack"); } }
public void Damage(EnemyAim attacker) { Vector3 bloodDir = (GetPosition() - attacker.GetPosition()).normalized; Blood_Handler.SpawnBlood(GetPosition(), bloodDir); healthSystem.Damage(1); if (IsDead()) { FlyingBody.Create(GameAssets.i.pfEnemyFlyingBody, GetPosition(), bloodDir); playerBase.DestroySelf(); Destroy(gameObject); } else { // Knockback transform.position += bloodDir * 2.5f; } }
public void Damage(UnitGridCombat attacker, int damageAmount) { Vector3 bloodDir = (GetPosition() - attacker.GetPosition()).normalized; Blood_Handler.SpawnBlood(GetPosition(), bloodDir); DamagePopup.Create(GetPosition(), damageAmount, false); healthSystem.Damage(damageAmount); if (healthSystem.IsDead()) { FlyingBody.Create(GameAssets.i.pfEnemyFlyingBody, GetPosition(), bloodDir); Destroy(gameObject); } else { // Knockback //transform.position += bloodDir * 5f; } }
private void Update() { float flySpeed = 400f; transform.position += flyDirection * flySpeed * Time.deltaTime; float scaleSpeed = 7f; transform.localScale += Vector3.one * scaleSpeed * Time.deltaTime; float eulerSpeed = 360f * 4f; eulerZ += eulerSpeed * Time.deltaTime; transform.localEulerAngles = new Vector3(0, 0, eulerZ); RaycastHit2D raycastHit2D = Physics2D.Raycast(transform.position, flyDirection, flySpeed * Time.deltaTime); if (raycastHit2D.collider != null) { // Hit something, stop spawning Blood! spawnBlood = false; } if (spawnBlood) { spawnBloodTimer -= Time.deltaTime; while (spawnBloodTimer <= 0f) { Blood_Handler.SpawnBlood(5, transform.position, flyDirection * -1f); spawnBloodTimer += spawnBloodTimerMax; } } timer += Time.deltaTime; if (timer >= 1f) { Destroy(gameObject); } }
public void Damage(IEnemyTargetable attacker, int damageAmount) { Vector3 bloodDir = (GetPosition() - attacker.GetPosition()).normalized; Blood_Handler.SpawnBlood(4, GetPosition(), bloodDir); health -= damageAmount; if (IsDead()) { FlyingBody.Create(GameAssets.i.pfEnemyFlyingBody, GetPosition(), bloodDir); Destroy(gameObject); } else { // Knockback /*transform.position += bloodDir * 5f; * if (hitUnitAnim != null) { * state = State.Busy; * unitAnimation.PlayAnimForced(hitUnitAnim, bloodDir * (Vector2.one * -1f), 1f, (UnitAnim unitAnim) => { * state = State.Normal; * }, null, null); * }*/ } }
private void Update() { float flySpeed = 400f; transform.position += flyDirection * flySpeed * Time.deltaTime; float scaleSpeed = 7f; transform.localScale += Vector3.one * scaleSpeed * Time.deltaTime; float eulerSpeed = 360f * 4f; eulerZ += eulerSpeed * Time.deltaTime; transform.localEulerAngles = new Vector3(0, 0, eulerZ); Blood_Handler.SpawnBlood(2, transform.position, flyDirection * -1f); timer += Time.deltaTime; if (timer >= 1f) { flyingBodyList.Remove(this); Destroy(gameObject); } }
public void Damage(Enemy attacker) { Vector3 bloodDir = (GetPosition() - attacker.GetPosition()).normalized; Blood_Handler.SpawnBlood(GetPosition(), bloodDir); }