Ejemplo n.º 1
0
    public void FireWeapon(Destroyable target, Weapon weapon)
    {
        if (weapon == Weapon.Missile && CanMissileFire)
        {
            Missile missile1 = (Missile)MissileScene.Instance();
            missile1.Homing         = MissileHoming;
            missile1.Target         = target;
            missile1.GlobalRotation = GlobalRotation;
            missile1.Position       = GlobalPosition;
            missile1.Position      += new Vector2(MissileOffset, 0).Rotated(GlobalRotation + Mathf.Deg2Rad(90));
            missile1.Velocity       = Velocity;
            missile1.AddForce(new Vector2(1, 0).Rotated(GlobalRotation + Mathf.Deg2Rad(90)), ProjectileEjectionForce);
            GetParent().AddChild(missile1);

            Missile missile2 = (Missile)MissileScene.Instance();
            missile2.Homing         = MissileHoming;
            missile2.Target         = target;
            missile2.GlobalRotation = GlobalRotation;
            missile2.Position       = GlobalPosition;
            missile2.Position      += new Vector2(MissileOffset, 0).Rotated(GlobalRotation + Mathf.Deg2Rad(-90));
            missile2.Velocity       = Velocity;
            missile2.AddForce(new Vector2(1, 0).Rotated(GlobalRotation + Mathf.Deg2Rad(-90)), ProjectileEjectionForce);
            GetParent().AddChild(missile2);

            CanMissileFire = false;
            missileCooldownTimer.Start(MissileCooldown);
        }
        else if (weapon == Weapon.Laser && CanLaserFire)
        {
            if (target is SpaceDamagable damagable)
            {
                beam.AddPoint(target.GlobalPosition - GlobalPosition);
                damagable.Hit();
                CanLaserFire = false;
                laserCooldownTimer.Start(LaserCooldown);
            }
        }
        else if (weapon == Weapon.Railgun && CanRailgunFire)
        {
            Rail rail = (Rail)RailScene.Instance();
            rail.PartialHoming = RailHoming;
            rail.Velocity      = Velocity;
            if (target != null)
            {
                rail.Target         = target;
                rail.GlobalRotation = GlobalRotation + GetAngleTo(GetGlobalMousePosition());
                rail.AddForce(new Vector2(1, 0).Rotated(GlobalRotation + GetAngleTo(GetGlobalMousePosition())), RailEjectionForce);
            }
            else
            {
                rail.GlobalRotation = GlobalRotation + GetAngleTo(GetGlobalMousePosition());
                rail.AddForce(new Vector2(1, 0).Rotated(GlobalRotation + GetAngleTo(GetGlobalMousePosition())), RailEjectionForce);
            }
            rail.Position = GlobalPosition;
            GetParent().AddChild(rail);

            CanRailgunFire = false;
            railgunCooldownTimer.Start(RailgunCooldown);
        }
    }