Beispiel #1
0
        // ignore own bullets
        private bool IsReachablePrecalc(BulletPath p)
        {
            foreach (var ray in p.Rays)
            {
                GameEntity result = null;
                Func <Fixture, Vector2, Vector2, float, float> callback = (f, pos, normal, frac) =>
                {
                    if (f.UserData == Cannon)
                    {
                        return(-1);                                          // ignore self;
                    }
                    if (f.UserData == p.TargetCannon)
                    {
                        return(frac);                                                  // limit
                    }
                    var bulletData = f.UserData as Bullet;
                    if (bulletData != null && bulletData.Source == Cannon)
                    {
                        return(-1);                                                                       // ignore own Bullets
                    }
                    var shieldData = f.UserData as ShieldCollisionMarker;
                    if (shieldData != null && !shieldData.Active)
                    {
                        return(-1);                                                              // ignore deactivated shields
                    }
                    if (f.UserData is IPhysicsMarker)
                    {
                        return(-1);                                                  // ignore
                    }
                    result = (GameEntity)f.UserData;

                    return(0);                    // terminate
                };

                Owner.GetPhysicsWorld().RayCast(callback, ray.Item1, ray.Item2);

                if (result != null)
                {
                    return(false);
                }

                foreach (var lsource in Owner.GetLaserNetwork().Sources)
                {
                    if (lsource.UserData != Cannon)
                    {
                        foreach (var lray in lsource.Lasers)
                        {
                            if (Math2D.LineIntersection(lray.Start, lray.End, ray.Item1.ToFPoint(), ray.Item2.ToFPoint(), out _))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }

            return(true);
        }
Beispiel #2
0
    public void BulletTrail(Vector3 target, float distance, Elements.Element bulletType)
    {
        Debug.Log("b trail");
        GameObject bulletPath = Instantiate(lineRendPrefab, shootPoint.position, shootPoint.rotation);

        bulletPath.transform.SetParent(shootPoint);
        bulletPath.GetComponent <LineRenderer>().materials[0].SetColor("_TintColor", GetTrailColorBasedOn(bulletType));
        BulletPath script = bulletPath.GetComponent <BulletPath>();

        script.target   = target;
        script.distance = distance;
    }
Beispiel #3
0
 public Bullet(Entity entity, BulletPath path, Vector2 position, float bulletSpeed)
 {
     this.entity = entity;
     sprite      = new Sprite()
     {
         texture   = ContentIndex.Textures["DevBullet"],
         rectangle = new Rectangle(0, 0, 2, 4)
     };
     this.position    = position;
     this.bulletSpeed = bulletSpeed;
     canDispose       = false;
     this.path        = path;
     bbox             = new Rectangle((int)position.X, (int)position.Y, sprite.rectangle.Width, sprite.rectangle.Height);
 }
Beispiel #4
0
    private IEnumerator ExplodeBomb()
    {
        float timer = 0f;

        while (timer < timeToDestroy)
        {
            while (GameManager.instance.gamePaused)
            {
                yield return(null);
            }

            timer += Time.deltaTime;
            yield return(null);
        }

        Collider2D[] overlapCircle = Physics2D.OverlapCircleAll(transform.position, explosionRadius);
        foreach (var t in overlapCircle)
        {
            //Have to check if game is paused to not destroy/move everything
            while (GameManager.instance.gamePaused)
            {
                yield return(null);
            }
            var rb = t.GetComponent <Rigidbody2D>();
            if (rb != null)
            {
                var direction = (rb.position - m_rb.position).normalized;
                rb.AddForce(direction * explosionForce, ForceMode2D.Impulse);
            }

            var component = t.GetComponent <Player>();
            if (component != null)
            {
                component.TakeDamage(damage);
            }

            BulletPath bullet = t.GetComponent <BulletPath>();
            if (bullet != null)
            {
                bullet.Remove();
            }
        }
        Debug.Log("BOOM");
        GetComponent <Enemy>().Remove();
    }
Beispiel #5
0
        // ignore all bullets
        private bool IsBulletBlockedReachablePrecalc(BulletPath p)
        {
            foreach (var ray in p.Rays)
            {
                GameEntity result = null;
                Func <Fixture, Vector2, Vector2, float, float> callback = (f, pos, normal, frac) =>
                {
                    if (f.UserData == Cannon)
                    {
                        return(-1);                                          // ignore self;
                    }
                    if (f.UserData == p.TargetCannon)
                    {
                        return(frac);                                                  // limit
                    }
                    if (f.UserData is Bullet)
                    {
                        return(-1);                                         // ignore _all_ Bullets
                    }
                    if (f.UserData is IPhysicsMarker)
                    {
                        return(-1);                                                  // ignore
                    }
                    var shieldData = f.UserData as ShieldCollisionMarker;
                    if (shieldData != null && !shieldData.Active)
                    {
                        return(-1);                                                              // ignore deactivated shields
                    }
                    result = (GameEntity)f.UserData;

                    return(0);                    // terminate
                };

                Owner.GetPhysicsWorld().RayCast(callback, ray.Item1, ray.Item2);

                if (result != null)
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #6
0
 private bool AreSameBulletType(BulletPath bullet)
 {
     return(bullet.isEnemyBullet == isEnemyBullet);
 }
 void OnEnable()
 {
     path = target as BulletPath;
     SceneView.onSceneGUIDelegate += OnSceneGUI;
 }