Ejemplo n.º 1
0
 private void _onDamageCalculation(int damage, Vector2 hitDir, Godot.Object source, Godot.Object target)
 {
     if (target != null && IsInstanceValid(target))
     {
         if (target.HasMethod("TakeDamage"))
         {
             Tank tankTarget = (Tank)(target);
             Tank tankSource = (Tank)(source);
             tankTarget.TakeDamage(damage, hitDir, tankSource);
         }
         else if (target.HasMethod("TakeEnvironmentDamage"))
         {
             ((Obstacle)(target)).TakeEnvironmentDamage(damage);
         }
     }
 }
        public static bool CallOrNull(this Object obj, string method, out object result, params object[] args)
        {
            var o = obj.HasMethod(method);

            result = o ? obj.Call(method, args) : null;
            return(o);
        }
Ejemplo n.º 3
0
 public void _OnBulletBodyEnter(Godot.Object body)
 {
     if (body.HasMethod("HitByBullet"))
     {
         body.Call("HitByBullet");
     }
 }
 public static bool TryCall(this Object obj, string method, params object[] args)
 {
     if (!obj.HasMethod(method))
     {
         return(false);
     }
     obj.Call(method, args);
     return(true);
 }
Ejemplo n.º 5
0
 private void _onDamageCalculation(int damage, Vector2 hitDir, Godot.Object source, Team sourceTeam, Godot.Object target)
 {
     if (target != null && IsInstanceValid(target))
     {
         if (target.HasMethod(nameof(Agent.TakeDamage)))
         {
             Agent targetAgent = (Agent)(target);
             Agent sourceAgent = (Agent)(source);
             targetAgent.TakeDamage(damage, hitDir, sourceAgent, sourceTeam);
         }
         else if (target.HasMethod(nameof(Obstacle.TakeEnvironmentDamage)))
         {
             ((Obstacle)(target)).TakeEnvironmentDamage(damage);
         }
         else if (target.HasMethod(nameof(Shield.TakeShieldDamage)))
         {
             ((ShieldPhysics)(target)).TakeShieldDamage(damage);
         }
     }
 }
Ejemplo n.º 6
0
    public void dispara()
    {
        try {
            Jugador jugador = (Jugador)GetNode("Jugador");

            // efecto del disparo
            jugador.disparaArma();

            Spatial Cabeza    = (Spatial)jugador.GetNode("Cabeza");
            Camera  objcamera = (Camera)Cabeza.GetNode("Camera");
            RayCast ray       = (RayCast)objcamera.GetNode("RayCast");

            if (ray.Enabled && ray.IsColliding())
            {
                Godot.Object objetivo = (Godot.Object)ray.GetCollider();

                Vector3 vectorimpacto = ray.GetCollisionPoint();

                // si el impacto lo recibe un objeto preparado para recibir balas
                if (objetivo.HasMethod("recibeBala"))
                {
                    // calculamos la direccion del impacto
                    Vector3 inicio    = ray.Translation;
                    Vector3 vectordir = vectorimpacto - inicio;

                    objetivo.Call("recibeBala", vectordir);
                }

                // pintamos el impacto de la bala

                // debug con cajas en vez de impacto

                poneCajaEscenario(vectorimpacto);

                /*
                 * PackedScene objeto = (PackedScene)ResourceLoader.Load("res://objetos/mini/ImpactoBalaPared.tscn");
                 * //  objetos.mini.ImpactoBalaPared efecto = (objetos.mini.ImpactoBalaPared)objeto.Instance();
                 * ImpactoBalaPared efecto = (ImpactoBalaPared)objeto.Instance();
                 * AddChild(efecto);
                 * efecto.haceEfecto(vectorimpacto);
                 */
            }
        }
        catch (Exception ex) {
        }
    }
Ejemplo n.º 7
0
    public void FireBullet()
    {
        if (_useRaycast)
        {
            _nodeRaycast.LookAt(_currentKinematic.GlobalTransform.origin + new Vector3(0, _playerHeight, 0), new Vector3(0, 1, 0));

            _nodeRaycast.ForceRaycastUpdate();

            if (_nodeRaycast.IsColliding())
            {
                Godot.Object _body = _nodeRaycast.GetCollider();
                if (_body.HasMethod("BulletHit"))
                {
                    _callback = GD.FuncRef(_body, "BulletHit");
                    _callback.CallFunc(_TurretDamageRaycast, _nodeRaycast.GetCollisionPoint());
                }
                _ammoInTurret--;
            }
        }
        else
        {
            StandardBullet _clone     = (StandardBullet)_bulletScene.Instance();
            Node           _sceneRoot = GetTree().Root.GetChild(0);
            _sceneRoot.AddChild(_clone);

            _clone.GlobalTransform = GetNode <Spatial>("Head/Barrel_End").GlobalTransform;
            _clone.Scale           = new Vector3(10, 10, 5);
            _clone.BulletDamage    = _TurretDamageBullet;
            _clone.BulletSpeed     = 5;
            _clone.Gravity         = -0.1f;

            _ammoInTurret--;
        }

        _nodeFlashOne.Visible = true;
        _nodeFlashTwo.Visible = true;

        _flashTimer = _flashTime;
        _fireTimer  = _fireTime;

        if (_ammoInTurret <= 0)
        {
            _ammoReloadTimer = _ammoReloadTime;
        }
    }
Ejemplo n.º 8
0
 public bool IsInkObjectOfType(Godot.Object inkObject, string name)
 {
     return(inkObject.HasMethod("is_class") && name.Equals(inkObject.Call("is_class")));
 }
Ejemplo n.º 9
0
 private bool IsInkObject(Godot.Object inkObject, string name)
 {
     return(inkObject.HasMethod("is_class") && name.Equals(inkObject.Call("is_class")));
 }