コード例 #1
0
 //configure a radial bullet's stats
 void ConfigureBullet(BulletRadial bc)
 {
     bc.charge       = bulletCharge;
     bc.attraction   = bulletHoming;
     bc.range        = bulletRange;
     bc.ignoredEnemy = enemyHit; //bullets ignore the enemy that tripped this trap
 }
コード例 #2
0
    //spawns bCount bullets in equal intervals, in a circle around This PTrap
    void SpawnRadialBullets(int bCount)
    {
        for (int i = 0; i <= bCount - 1; i++)
        {
            Debug.Log("called instantiate bullet in ProjectileTrap.cs");
            GameObject    bullet     = Instantiate(Resources.Load("Prefabs/MainCanvas/BulletRadial")) as GameObject; //make a bullet
            RectTransform bulletRect = (RectTransform)bullet.transform;
            RectTransform rt         = GetComponent <RectTransform>();                                               //this pt's recttransform
            BulletRadial  bc         = bullet.GetComponent <BulletRadial>();
            bullet.transform.SetParent(Dial.spawnLayer, false);
            //make it the type of bullet this thing fires
            ConfigureBullet(bc);

            //find your angle/handle spread (equidistant bullets around trap)
            float ownangle = this.transform.eulerAngles.z; //rotation of this trap
            float angle    = (ownangle + 90) % 360;        //rotation of this trap
            angle *= (float)Math.PI / 180;
            //Debug.Log ("original angle: " + angle);
            //set angle for each bullet
            float circleSlice = 360 / bCount;
            circleSlice *= Mathf.Deg2Rad;
            angle        = (angle + (circleSlice * i));

            //find where to spawn the bullet
            bc.spawnx = rt.anchoredPosition.x;
            bc.spawny = rt.anchoredPosition.y;
            bc.UpdateSpawnDist();
            //Debug.Log (bc.speed);
            bulletRect.anchoredPosition = new Vector2(bc.spawnx, bc.spawny);
            bc.transform.rotation       = transform.rotation;
            bc.vx = bc.speed * (float)Math.Cos(angle);
            bc.vy = bc.speed * (float)Math.Sin(angle);
        }
    }
コード例 #3
0
ファイル: Dial.cs プロジェクト: Benedict-SC/doom-dial
 public void OnTriggerEnter2D(Collider2D coll)
 {
     Debug.Log("dial called ontriggerenter2d");
     if (coll.gameObject.tag == "DialCollider")
     {
         GameEvent ge = new GameEvent("enemy_arrived");
         ge.addArgument(coll.transform.parent.gameObject);
         EventManager.Instance().RaiseEvent(ge);
     }
     if (coll.gameObject.tag == "Boss")
     {
         Debug.Log("dial hit boss");
         //check if it's a Skizzard, which deals contact damage
         Skizzard skizz = coll.gameObject.GetComponent <Skizzard>();
         if (skizz != null)
         {
             skizz.HitDial();
         }
     }
     else if (coll.gameObject.tag == "BulletRadial")
     {
         BulletRadial bc = coll.gameObject.GetComponent <BulletRadial>();
         bc.Collide();
     }
 }
コード例 #4
0
ファイル: Enemy.cs プロジェクト: Benedict-SC/doom-dial
    public virtual void OnTriggerEnter2D(Collider2D coll)
    {
        if (frozen)
        {
            return;                                         //invincible while boss is moving it
        }
        if (coll != null && coll.gameObject.tag == "Enemy") //handled before anything that cares about shields
        {
            if (knockChained)
            {
                Debug.Log("we hit something with knockchain");
                float timeEstimate = 1.3f; //how long stuff presumably gets knocked back for
                                           //it's an estimate since we can't see it directly (without writing a script to measure it)
                float duration      = knockbackTimer.TimeElapsedSecs();
                float remainingTime = timeEstimate - duration;
                if (remainingTime > 0)
                {
                    float power = (remainingTime / timeEstimate) * knockbackPower;
                    coll.GetComponent <Enemy>().SelfKnockback(power);
                    coll.GetComponent <Enemy>().SelfStun(stunDuration);
                    Debug.Log("we're calling selfknockback on something");
                }
            }
        }
        if (shield != null)
        {
            if (shield.hitThisFrame)//the shield handled collision for us this time
            {
                return;
            }
            else  //the shield was either missed or hasn't been handled by collision yet
            {
                if (secondaryCollisionTicket)
                {
                    //let execution through to actually handle the collision- we're calling this function manually
                    secondaryCollisionTicket = false; //punch the ticket
                }
                else                                  //skip colliding- wait until update to check if the shield got it for us
                {
                    collidedThisFrame = true;
                    heldCollision     = coll; //store the collision so we can handle it if/when we call this manually
                    return;
                }
            }
        }
        if (coll == null)
        {
            Debug.Log("bullet's gone");
            return;
        }
        //Debug.Log ("!!! we made it through to our own collision");
        if (coll.gameObject.tag == "Bullet") //if it's a bullet
        {
            Debug.Log("we got hit by a bullet");
            Bullet bc = coll.gameObject.GetComponent <Bullet>();
            if (bc != null)
            {
                if (bc.CheckActive()) //if we get a Yes, this bullet/trap/shield is active
                {
                    bc.enemyHit = this.gameObject;
                    GetStatused(bc);
                    //StartCoroutine (StatusEffectsBullet (bc));
                    //Vamp-Drain
                    if (bc.vampDrain > 0f)
                    {
                        //if this enemy's hp is about to drop to 0
                        if (hp < bc.dmg * bc.vampDrain)
                        {
                            dialCon.ChangeHealth(hp);
                        }
                        else
                        {
                            dialCon.ChangeHealth(bc.dmg * bc.vampDrain);
                        }
                    }
                    hp -= bc.dmg;

                    timesShot++;
                    bc.Collide();

                    if (hp <= 0)
                    {
                        hp = 0;
                        Die();
                    }
                }
            }
        }
        else if (coll.gameObject.tag == "BulletRadial") //if it's a radial bullet from a BulletTrap
        {
            Debug.Log("we got hit by a radialBullet");
            BulletRadial bc = coll.gameObject.GetComponent <BulletRadial>();
            if (bc != null)
            {
                if (bc.CheckActive())
                {
                    Debug.Log("this bulletRadial that hit an enemy IS active");
                    //bulletRadials ignore the enemy that tripped the PTrap to begin with
                    if (this.gameObject != bc.ignoredEnemy)
                    {
                        Debug.Log(this.gameObject.ToString() + "equals " + bc.ignoredEnemy.ToString());
                        bc.enemyHit = this.gameObject;
                        GetStatused(bc);
                        //StartCoroutine (StatusEffectsBullet (bc));
                        //Vamp-Drain
                        if (bc.vampDrain > 0f)
                        {
                            //if this enemy's hp is about to drop to 0
                            if (hp < bc.dmg * bc.vampDrain)
                            {
                                dialCon.ChangeHealth(hp);
                            }
                            else
                            {
                                dialCon.ChangeHealth(bc.dmg * bc.vampDrain);
                            }
                        }
                        hp -= bc.dmg;
                        timesShot++;
                        bc.Collide();

                        if (hp <= 0)
                        {
                            hp = 0;
                            Die();
                        }
                    }
                }
            }
        }
        else if (coll.gameObject.tag == "Trap")         //if it's a trap
        {
            if (tripsTraps)
            {
                Trap tc = coll.gameObject.GetComponent <Trap>();
                if (tc != null)
                {
                    if (tc.CheckActive())                     //if we get a Yes, this bullet/trap/shield is active
                    {
                        tc.enemyHit = this.gameObject;
                        //Vamp-Drain
                        if (tc.vampDrain > 0f)
                        {
                            //if this enemy's hp is about to drop to 0
                            if (hp < tc.dmg * tc.vampDrain)
                            {
                                dialCon.ChangeHealth(hp);
                            }
                            else
                            {
                                dialCon.ChangeHealth(tc.dmg * tc.vampDrain);
                            }
                        }
                        if (tc.aoe == 0f)
                        {
                            hp -= tc.dmg;
                        }
                        tc.Collide();
                        if (hp <= 0)
                        {
                            Die();
                        }
                    }
                }
            }
        }
        else if (coll.gameObject.tag == "ProjectileTrap") //if it's a projectiletrap
        {
            //Debug.Log("enemy collided with projectiletrap");
            if (tripsTraps)
            {
                //Debug.Log("enemy which collided with PTrap DOES trip traps");
                ProjectileTrap tc = coll.gameObject.GetComponent <ProjectileTrap>();
                if (tc != null)
                {
                    //Debug.Log("PTrap isn't null");
                    if (tc.CheckActive())
                    {
                        tc.enemyHit = this.gameObject;
                        //Vamp-Drain
                        if (tc.vampDrain > 0f)
                        {
                            //if this enemy's hp is about to drop to 0
                            if (hp < tc.dmg * tc.vampDrain)
                            {
                                dialCon.ChangeHealth(hp);
                            }
                            else
                            {
                                dialCon.ChangeHealth(tc.dmg * tc.vampDrain);
                            }
                        }
                        hp -= tc.dmg;
                        //Debug.Log("calling Collide() on projectiletrap");
                        tc.Collide();
                        if (hp <= 0)
                        {
                            Die();
                        }
                    }
                }
            }
        }
        else if (coll.gameObject.tag == "Shield")         //if it's a shield
        {
            //all handled by the shield collision now
        }
        else if (coll.gameObject.tag == "AoE")
        {
            //Debug.Log ("enemy collided with AoE");
            GameObject obj = coll.gameObject;
            AoE        ac  = obj.GetComponent <AoE>();
            if (ac.parent == "Bullet")
            {
                //StartCoroutine (StatusEffectsBullet (bc));
                if (ac.vampIsOn)
                {
                    if (hp < ac.vampDrain)
                    {
                        dialCon.ChangeHealth(hp);
                    }
                    else
                    {
                        dialCon.ChangeHealth(ac.vampDrain);
                    }
                }
                hp -= ac.aoeDamage;
                Debug.Log("damage taken: " + ac.aoeDamage);
                //timesShot++;
                if (hp <= 0)
                {
                    Die();
                }
            }
            else if (ac.parent == "Trap")
            {
                hp -= ac.aoeDamage;
                if (hp <= 0)
                {
                    Die();
                }
            }
        }
        //other types of collision?
    }