/// <summary>
    /// Public constructor
    /// </summary>
    public PlayerMovement(
        Transform massEjectionTransform,
        GameObject lightBallPrefab,
        float thrustForce,
        float changeDirectionBoost,
        float thrustEnergyCost,
        float brakeDrag,
        Transform transform,
        Rigidbody rigidbody,
        LightEnergy lightEnergy,
        GameObject jetFuelEffect,
        float rotationSpeed
    )
    {
        this.massEjectionTransform = massEjectionTransform;
        this.lightBallPrefab = lightBallPrefab;
        this.thrustForce = thrustForce;
        this.changeDirectionBoost = changeDirectionBoost;
        this.thrustEnergyCost = thrustEnergyCost;
        this.brakeDrag = brakeDrag;
        this.jetFuelEffect = jetFuelEffect;
        this.defaultDrag = rigidbody.drag;
        this.rotationSpeed = rotationSpeed;

        this.transform = transform;
        this.rigidbody = rigidbody;
        this.lightEnergy = lightEnergy;

        OnPropulsionEnd();
    }
Beispiel #2
0
    /// <summary>
    /// Public constructor
    /// </summary>
    public PlayerMovement(
        Transform massEjectionTransform,
        GameObject lightBallPrefab,
        float thrustForce,
        float changeDirectionBoost,
        float thrustEnergyCost,
        float brakeDrag,
        Transform transform,
        Rigidbody rigidbody,
        LightEnergy lightEnergy,
        GameObject jetFuelEffect,
        float rotationSpeed
        )
    {
        this.massEjectionTransform = massEjectionTransform;
        this.lightBallPrefab       = lightBallPrefab;
        this.thrustForce           = thrustForce;
        this.changeDirectionBoost  = changeDirectionBoost;
        this.thrustEnergyCost      = thrustEnergyCost;
        this.brakeDrag             = brakeDrag;
        this.jetFuelEffect         = jetFuelEffect;
        this.defaultDrag           = rigidbody.drag;
        this.rotationSpeed         = rotationSpeed;

        this.transform   = transform;
        this.rigidbody   = rigidbody;
        this.lightEnergy = lightEnergy;

        OnPropulsionEnd();
    }
Beispiel #3
0
    /// <summary>
    /// Update is called every frame, if the MonoBehaviour is enabled
    /// <see cref="Unity Documentation">
    /// </summary>
    protected virtual void Update()
    {
        // Cycle through each absorbable light source being touched by this GameObject
        for (int i = 0; i < absorbableLightDetector.NeighbourCount; i++)
        {
            GameObject absorbableLight = absorbableLightDetector.GetNeighbour(i);
            if (absorbableLight == null)
            {
                continue;
            }

            LightSource otherLightSource = absorbableLight.GetComponentInParent <LightSource>();
            if (otherLightSource == null)
            {
                continue;
            }

            // If this GameObject can absorb the touched light source,
            // Transfer light energy from the other light source to this one
            if (CanAbsorb(otherLightSource))
            {
                if (this is Player)
                {
                    PlayerSound playerSound = GetComponent <PlayerSound>();
                    playerSound.EatSound();
                }
                LightEnergy lightEnergyToAbsorb = otherLightSource.LightEnergy;

                // Calculate the amount of light to absorb from the other light source
                float lightToAbsorb = absorptionRate * Time.deltaTime;

                // If the player was hit
                if (otherLightSource is Player)
                {
                    if (this is AbstractFish)
                    {
                        // Absorb a certain amount of light from the player to the fish
                        AbstractFish fish = (AbstractFish)this;
                        lightToAbsorb = fish.damageInflicted;
                    }

                    // Debug.Log("Absorb " + lightToAbsorb + " from player");

                    // Knockback the player away from the enemy fish
                    otherLightSource.Knockback(this);
                }

                // Transfer light energy from the other light source to this one
                float lightAbsorbed = lightEnergyToAbsorb.Deplete(lightToAbsorb);
                lightEnergy.Add(lightAbsorbed);

                // Inform subscribers that this light source consumed another light source.
                ConsumedLightSource(otherLightSource);
            }
        }
    }
 private void UpdateDisplay()
 {
     if (Get_SoLEnergy != 0f)
     {
         this.lightPowerString = LightEnergy.ToString("0.#") + " | " + Get_SoLEnergy.ToString("0.#");
     }
     else
     {
         this.lightPowerString = LightEnergy.ToString("0.#");
     }
 }
 public PlayerMovement(MovementBean movementBean, Transform transform, Rigidbody rigidbody, LightEnergy lightEnergy)
 {
     this.massEjectionTransform = movementBean.MassEjectionTransform;
     this.lightBallPrefab       = movementBean.LightBallPrefab;
     this.thrustForce           = movementBean.ThrustForce;
     this.changeDirectionBoost  = movementBean.ChangeDirectionBoost;
     this.thrustEnergyCost      = movementBean.ThrustEnergyCost;
     this.brakeDrag             = movementBean.BrakeDrag;
     this.jetFuelEffect         = movementBean.JetFuelEffect;
     this.rotationSpeed         = movementBean.RotationSpeed;
     this.transform             = transform;
     this.rigidbody             = rigidbody;
     this.defaultDrag           = rigidbody.drag;
     this.lightEnergy           = lightEnergy;
     OnPropulsionEnd();
 }
    protected virtual void Start()
    {
        lightSource = GetComponentInParent <LightSource>();

        // Choose either the override (if assigned in the Inspector) or the component
        // attached to this GameObject.
        if (lightEnergyOverride != null)
        {
            this.lightEnergy = lightEnergyOverride;
        }
        else if (lightSource)
        {
            this.lightEnergy = lightSource.LightEnergy;
        }
        else
        {
            this.lightEnergy = null;
        }

        Subscribe();
        // Initialize the attribute to the light's initial energy
        OnLightChanged(lightEnergy.CurrentEnergy);
    }
    public virtual void Start()
    {
        lightSource = GetComponentInParent<LightSource>();

        // Choose either the override (if assigned in the Inspector) or the component
        // attached to this GameObject.
        if (lightEnergyOverride != null)
        {
            this.lightEnergy = lightEnergyOverride;
        }
        else if (lightSource)
        {
            this.lightEnergy = lightSource.LightEnergy;
        }
        else
        {
            this.lightEnergy = null;
        }

        Subscribe();

        // Initialize the attribute to the light's initial energy
        OnLightChanged(lightEnergy.CurrentEnergy);
    }