BloodAndGore/Assets/Scripts/Guns/Bullet.cs

49 lines
2.3 KiB
C#
Raw Permalink Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Saltosion.OneWeapon.Effects;
using Saltosion.OneWeapon.Enemies;
using Saltosion.OneWeapon.Environment;
2019-08-14 16:17:48 +02:00
namespace Saltosion.OneWeapon.Guns {
public class Bullet : MonoBehaviour {
public Vector2 Direction;
public float InitialRotation;
public bool HasExploded = false;
public void DoDamage(float Damage, float Intensity, Collider2D Collider, Vector2 Direction) {
Explodable Explodable = Collider.GetComponent<Explodable>();
Health Health = Collider.GetComponent<Health>();
GunDropper VendingMachine = Collider.GetComponent<GunDropper>();
if (Health != null) {
Health.Damage(Damage, -Direction, true);
} else if (VendingMachine != null) {
VendingMachine.ExpelGun();
} else if (Explodable != null) {
Explodable.Explode(true, true);
} else if (Collider.tag == "Environment") {
2019-08-14 23:27:14 +02:00
DebrisLauncher.Splatter(DebrisType.Structural, transform.position, Direction, (int)(5 * Intensity), 30 * Intensity, 360);
}
if (Collider.attachedRigidbody != null && Collider.attachedRigidbody.bodyType == RigidbodyType2D.Dynamic) {
Collider.attachedRigidbody.AddForce(Direction * 4 * Intensity, ForceMode2D.Impulse);
}
}
2019-08-18 20:46:22 +02:00
public void DoDamageAOE(float Damage, float Radius, float Intensity) {
Collider2D[] NearbyColliders = Physics2D.OverlapCircleAll(transform.position, Radius);
foreach (Collider2D curr in NearbyColliders) {
Vector2 Delta = (curr.transform.position - transform.position);
Vector2 Dir = Delta.normalized;
float ScaledDistance = 1 - Mathf.Clamp((Delta.magnitude - (Radius / 3)) / (Radius - (Radius / 3)), 0, 1);
this.DoDamage(ScaledDistance * Damage, ScaledDistance * Intensity, curr, Dir);
if (curr.attachedRigidbody != null && curr.attachedRigidbody.bodyType == RigidbodyType2D.Dynamic) {
// FIXME: AcceleratedMovement currently overrides Rigidbody.velocity so this doesn't do anything
curr.attachedRigidbody.AddForce(Dir * 10f, ForceMode2D.Impulse);
}
}
}
}
}