コード例 #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();
     }
 }
コード例 #2
0
ファイル: TankKinematicBody2D.cs プロジェクト: MA86/TankGame
    // Spawn a bullet if the space key is pressed
    void FireBulletIfNeeded()
    {
        if (Input.IsActionJustPressed(fireCannon))
        {
            // Position the bullet and fire
            BulletRigidBody2D bullet = (BulletRigidBody2D)bulletGenerator.Instance();
            bullet.Position = this.GetNode <AnimatedSprite>("Sprite/Sprite2/Sprite/AnimatedSprite").GlobalPosition;
            bullet.Rotation = this.GetNode <Sprite>("Sprite/Sprite2/Sprite").GlobalRotation + Mathf.Deg2Rad(0);
            this.GetParent().AddChild(bullet);
            bullet.FireBullet();
            bullet.Show();
            this.GetNode <AudioStreamPlayer2D>("AudioStreamPlayer2D").Play();

            // Play the fire animation
            this.GetNode <AnimatedSprite>("Sprite/Sprite2/Sprite/AnimatedSprite").Show();
            this.GetNode <AnimatedSprite>("Sprite/Sprite2/Sprite/AnimatedSprite").SetFrame(0);
            this.GetNode <AnimatedSprite>("Sprite/Sprite2/Sprite/AnimatedSprite").Play();
        }
    }
コード例 #3
0
ファイル: GenericGun.cs プロジェクト: MA86/TopDownShooter
    // 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;
        }
    }