// Detect collisions with other enemies, or player (while invuln), to prevent stacking
    void OnTriggerStay2D(Collider2D col)
    {
        if (!noCollisions)
        {
            return;
        }

        WeightedEnemyPhysics OtherWEP = col.gameObject.GetComponent <WeightedEnemyPhysics>();
        PlayerHP             PHP      = col.gameObject.GetComponent <PlayerHP> ();

        if (OtherWEP != null || (PHP != null && PlayerHP.invuln))
        {
            Vector2 OtherPos = col.transform.position;
            Vector2 diff     = (OtherPos - (Vector2)transform.position).normalized;

            Vector2 projection = Vector2.Dot(diff, velocity) * diff;

            if ((diff + projection.normalized).magnitude > diff.magnitude)
            {
                velocity -= projection * (1f + bounceScale);
            }
        }

        if (col.GetComponent <turtle_shield>())
        {
            print("found it");
            Vector2 dir = transform.position - col.gameObject.transform.position;
            dir = dir.normalized * 2;
            StartCoroutine(knock_force(dir));
        }
    }
Beispiel #2
0
 // Initialize
 void Start()
 {
     WEP          = GetComponent <WeightedEnemyPhysics> ();
     WEP.maxSpeed = maxSpeed;
     am           = GetComponentInChildren <Animator>();
     StartCoroutine(checkCharge());
 }
Beispiel #3
0
    // Called once per frame
    void Update()
    {
        Vector2 pos = transform.position;

        if (GM.Instance.player == null)
        {
            return;
        }
        Vector2 lookAtPos = GM.Instance.player.transform.position;

        // Decide what direction to look towards
        Vector2 direction = lookAtPos - pos;

        WEP.acceleration = direction.normalized;

        // Only enable shooting if the turret has a shot lined up with the player
        float currentAngle = transform.eulerAngles.z;

        currentAngle = WeightedEnemyPhysics.normalDegrees(currentAngle);

        float targetAngle = Mathf.Atan2(WEP.acceleration.y, WEP.acceleration.x) * Mathf.Rad2Deg;

        targetAngle = WeightedEnemyPhysics.normalDegrees(targetAngle);

        float diff = targetAngle - currentAngle;

        diff = WeightedEnemyPhysics.normalDegrees(diff);

        SAP.shootingEnabled = (Mathf.Abs(diff) <= Mathf.Abs(aimAngleLeeway));
    }
Beispiel #4
0
    // Initialization
    void Start()
    {
        WEP = GetComponent <WeightedEnemyPhysics> ();

        shootingEnabled = true;
        cool_down       = true;
        Invoke("reload", 1 / _fire_rate);
    }
Beispiel #5
0
    // Initialization
    void Awake()
    {
        WEP          = GetComponent <WeightedEnemyPhysics> ();
        WEP.maxSpeed = maxSpeed;

        SwarmersWEP = new List <WeightedEnemyPhysics>(1 + innerCount + outerCount);
        SpawnSwarm();
    }
    // Initialize
    void Start()
    {
        WEP          = GetComponent <WeightedEnemyPhysics> ();
        WEP.maxSpeed = maxSpeed;

        clockwise = false;
        circling  = false;
        delay     = diveTime;
    }
Beispiel #7
0
    // Initialize
    void Start()
    {
        WEP          = GetComponent <WeightedEnemyPhysics> ();
        WEP.maxSpeed = maxSpeed;

        circling   = true;
        delay      = minCircleTime;
        divesSoFar = 0;
    }
Beispiel #8
0
    public void unstun()
    {
        Rigidbody2D rb = GetComponentInChildren <Rigidbody2D>();

        rb.isKinematic = true;
        WeightedEnemyPhysics ws = GetComponentInChildren <WeightedEnemyPhysics>();

        ws.enabled = true;
    }
Beispiel #9
0
    // Initialization
    void Awake()
    {
        WEP          = GetComponent <WeightedEnemyPhysics> ();
        WEP.maxSpeed = 0f;

        SAP      = GetComponent <ShootsAtPlayer> ();
        asteroid = GetComponentInParent <Asteroid> ();
        asteroid.addTurret(this);

        initDegreeClamp();
    }
Beispiel #10
0
    // Initialize
    void Start()
    {
        WEP          = GetComponent <WeightedEnemyPhysics> ();
        WEP.maxSpeed = maxSpeed;

        SR           = GetComponent <SpriteRenderer> ();
        normalSprite = SR.sprite;

        triggered   = false;
        normalState = true;
    }
Beispiel #11
0
    // Initialize
    void Start()
    {
        WEP          = GetComponent <WeightedEnemyPhysics> ();
        WEP.maxSpeed = circleSpeed;
        SR           = GetComponentInChildren <SpriteRenderer> ();
        SR.sprite    = AsleepSprite;
        SO           = GetComponent <ScrollingObject> ();
        SO.enabled   = true;

        chasing = false;
        angry   = false;
    }
Beispiel #12
0
    // Initialize the degree clamp in the WEP
    private void initDegreeClamp()
    {
        WEP.clampPerp = true;
        Vector2 normal = transform.position - asteroid.transform.position;
        float   theta  = Mathf.Rad2Deg * Mathf.Atan2(normal.x, normal.y);

        float realDoF   = 360f - degreesOfFreedom;       // Have to do this to fix something...
        float minDegree = (90f - realDoF / 2) + theta;
        float maxDegree = (90f + realDoF / 2) + theta;

        WEP.minDegree = WeightedEnemyPhysics.normalDegrees(minDegree);
        WEP.maxDegree = WeightedEnemyPhysics.normalDegrees(maxDegree);
    }
Beispiel #13
0
    // Spawn a single swarmer enemy at the given location, attached to this swarm
    private void SpawnOneSwarmer(Vector3 position)
    {
        GameObject newSwarmer = Instantiate(SwarmerPrefab);

        newSwarmer.transform.position = position;

        SwarmerCount++;

        WeightedEnemyPhysics newWEP = newSwarmer.GetComponent <WeightedEnemyPhysics> ();

        newWEP.maxSpeed = maxSpeed;
        SwarmersWEP.Add(newWEP);
        //GM.Instance.Spawn (newSwarmer);
    }
Beispiel #14
0
    // Initialize
    void Start()
    {
        WEP       = GetComponent <WeightedEnemyPhysics> ();
        leaderWEP = objToFollow.GetComponent <WeightedEnemyPhysics> ();

        if (!objToFollow)
        {
            SetControllerScript(true);
            return;
        }
        else
        {
            SetControllerScript(false);
            maxSpeed = getLeaderSpeed();
        }

        WEP.maxSpeed = maxSpeed;
    }
Beispiel #15
0
    public WeightedEnemyPhysics getLeaderWEP()
    {
        FollowerEnemy nextInChain = objToFollow.GetComponent <FollowerEnemy> ();

        if (nextInChain && nextInChain.enabled)
        {
            return(nextInChain.getLeaderWEP());
        }
        else
        {
            WeightedEnemyPhysics newLeadWEP = objToFollow.GetComponent <WeightedEnemyPhysics> ();
            if (newLeadWEP)
            {
                return(newLeadWEP);
            }
            else
            {
                Debug.LogError("No leader WeightedEnemyPhysics component found");
                return(null);
            }
        }
    }
Beispiel #16
0
 // Called when damage is taken
 public void gotHit(Vector3 knock_back, int dmg = 1, bool noDrop = false)
 {
     if (special())
     {
         HP -= dmg;
     }
     if (HP <= 0)
     {
         die(noDrop);
     }
     else             //hit animation
     {
         take_hit th;
         if (th = GetComponentInChildren <take_hit>())
         {
             th.hit();
             WeightedEnemyPhysics ws = GetComponentInChildren <WeightedEnemyPhysics>();
             if (ws)
             {
                 ws.KnockBack(knock_back);
             }
         }
     }
 }
Beispiel #17
0
 // Initialize
 void Start()
 {
     WEP          = GetComponent <WeightedEnemyPhysics> ();
     WEP.maxSpeed = maxSpeed;
 }