Ejemplo n.º 1
0
 // Spawn abunch of bullets originating from the mine.
 protected void SpawnBullets()
 {
     for (double i = 0; i < 360; i += (360.0 / this.NumberOfBulletsGenerated))
     {
         BulletRigidBody2D bullet = (BulletRigidBody2D)bulletScene.Instance();
         this.GetNode <Node2D>("/root/EnvironNode2D/OnGround").AddChild(bullet);
         bullet.GlobalPosition = this.GlobalPosition;
         bullet.GlobalRotation = (float)i;
         bullet.Speed          = (float)GD.RandRange(1000, 1400);
         bullet.MaxDistance    = this.BlastRadius;
         bullet.Go();
     }
 }
Ejemplo n.º 2
0
    // Spawns a bullet.
    private void FireBullet()
    {
        // If it's not yet time to fire, then don't (prevents client from calling FireBullet repeatedly to surpass gun's fire rate)
        float timeNeeded = 1.0f / RateOfFire * 60.0f * 1000.0f;

        if (OS.GetTicksMsec() - this.lastBulletTime < timeNeeded)
        {
            return;
        }

        // Create a bullet and position it on the gun.
        for (int i = 0; i < this.NumBulletsPerShot; i++)
        {
            BulletRigidBody2D bullet = (BulletRigidBody2D)this.BulletUsed.Instance();
            this.GetNode <Node2D>("/root/EnvironNode2D/OnGround").AddChild(bullet);
            this.Rotation      = 0;
            this.Rotation     += (float)GD.RandRange(Mathf.Deg2Rad(-this.immediateTheta), Mathf.Deg2Rad(this.immediateTheta));         // jitter gun ("recoil")
            bullet.Rotation    = this.GlobalRotation;
            bullet.Position    = this.GlobalPosition;
            bullet.Position    = this.GetNode <Position2D>("Position2D").GlobalPosition;
            bullet.Position   += bullet.GlobalTransform.x * (float)GD.RandRange(0, this.StaggerDistance);
            bullet.Speed       = this.BulletSpeed;
            bullet.MaxDistance = this.Range;

            // Set off the bullet
            bullet.Go();
        }

        this.GetNode <AudioStreamPlayer2D>("BulletSound").Play();

        this.lastBulletTime  = OS.GetTicksMsec();
        this.immediateTheta += 2.0f;         // add to recoil
        if (this.immediateTheta > this.maxTheta)
        {
            this.immediateTheta = this.maxTheta;
        }
    }