Beispiel #1
0
        public override void OnUpdate()
        {
            if (Owner.Get() == null || lifetime <= 0)
            {
                Decorative.Remove(this);
                return;
            }

            if (rof-- > 0 && --lifetime > 0)
            {
                return;
            }
            rof = 5;

            int damage = lifetime > 0 ? 10 : 100;

            TechnoExt target = Decorative as TechnoExt;

            Pointer <WeaponTypeClass> pWeapon = Weapon;
            Pointer <BulletClass>     pBullet = pWeapon.Ref.Projectile.Ref.
                                                CreateBullet(target.OwnerObject.Convert <AbstractClass>(), Owner.Get().OwnerObject,
                                                             damage, Warhead, pWeapon.Ref.Speed, pWeapon.Ref.Bright);

            const int   radius      = 600;
            CoordStruct curLocation = target.OwnerObject.Ref.Base.Base.GetCoords();

            CoordStruct where = curLocation + new CoordStruct(random.Next(-radius, radius), random.Next(-radius, radius), 2000);
            BulletVelocity velocity = new BulletVelocity(0, 0, 0);

            pBullet.Ref.MoveTo(where, velocity);
        }
Beispiel #2
0
        public override void OnUpdate()
        {
            if (Owner.Get() == null || lifetime <= 0)
            {
                Decorative.Remove(this);
                return;
            }

            if (rof-- > 0 && --lifetime > 0)
            {
                return;
            }
            rof = 5;

            int damage = lifetime > 0 ? 10 : 100;

            TechnoExt target = Decorative as TechnoExt;

            Pointer <WeaponTypeClass>  pWeapon  = Weapon;
            Pointer <WarheadTypeClass> pWarhead = Warhead;

            Func <int, Pointer <BulletClass> > CreateBullet = (int damage) => {
                Pointer <BulletClass> pBullet = pWeapon.Ref.Projectile.Ref.
                                                CreateBullet(target.OwnerObject.Convert <AbstractClass>(), Owner.Get().OwnerObject,
                                                             damage, pWarhead, pWeapon.Ref.Speed, pWeapon.Ref.Bright);
                return(pBullet);
            };

            CoordStruct curLocation = target.OwnerObject.Ref.Base.Base.GetCoords();

            if (Cluster)
            {
                CellStruct cur = MapClass.Coord2Cell(curLocation);

                CellSpreadEnumerator enumerator = new CellSpreadEnumerator(2);
                foreach (CellStruct offset in enumerator)
                {
                    Pointer <BulletClass> pBullet = CreateBullet(damage);
                    CoordStruct where = MapClass.Cell2Coord(cur + offset, 2000);
                    if (MapClass.Instance.TryGetCellAt(where, out Pointer <CellClass> pCell))
                    {
                        BulletVelocity velocity = new BulletVelocity(0, 0, 0);
                        pBullet.Ref.MoveTo(where, velocity);
                        pBullet.Ref.SetTarget(pCell.Convert <AbstractClass>());
                    }
                }
            }
            else
            {
                Pointer <BulletClass> pBullet = CreateBullet(damage);

                const int radius = 600;
                CoordStruct where = curLocation + new CoordStruct(random.Next(-radius, radius), random.Next(-radius, radius), 2000);
                BulletVelocity velocity = new BulletVelocity(0, 0, 0);
                pBullet.Ref.MoveTo(where, velocity);
            }
        }
Beispiel #3
0
    public void SpawnTheBullet(GameObject from, Vector3 to, int speed)
    {
        GameObject bulletGameObject = new GameObject("Bullet");

        bulletGameObject.layer = 2; // ignore raycast

        bulletGameObject.transform.position   = from.transform.position;
        bulletGameObject.transform.localScale = new Vector3(0.05f, 0.05f, 1);
        bulletGameObject.transform.LookAt(to, Vector3.back);
        bulletGameObject.transform.Rotate(0, 0, -90);
        bulletGameObject.transform.position += bulletGameObject.transform.right * 1.5f;
        Vector3Int tileLoc = tilemap.WorldToCell(bulletGameObject.transform.position);

        if (tilemap.HasTile(tileLoc))
        {
            Destroy(bulletGameObject);
            return;
        }

        SpriteRenderer bulletSpriteRenderer = bulletGameObject.AddComponent <SpriteRenderer>();

        bulletSpriteRenderer.sprite = Resources.Load <Sprite>("GameScene/Sprites/bullet.png");

        Rigidbody2D bulletRigidBody = bulletGameObject.AddComponent <Rigidbody2D>();

        bulletRigidBody.gravityScale           = 0;
        bulletRigidBody.constraints            = RigidbodyConstraints2D.FreezeRotation;
        bulletRigidBody.collisionDetectionMode = CollisionDetectionMode2D.Continuous;
        bulletRigidBody.drag = 0;

        CircleCollider2D bulletCircleCollider = bulletGameObject.AddComponent <CircleCollider2D>();

        bulletCircleCollider.offset = new Vector2(1, 0);
        bulletCircleCollider.radius = 2.33f;

        BulletVelocity bulletVelocityScript = bulletGameObject.AddComponent <BulletVelocity>();

        bulletVelocityScript.speed = speed;

        bulletGameObject.AddComponent <BulletCollider>();

        GameObject trailGameObject = Instantiate <GameObject>(GameObject.Find("TemplateTrail"));

        trailGameObject.transform.parent   = bulletGameObject.transform;
        trailGameObject.transform.position = bulletGameObject.transform.position;
    }