Ejemplo n.º 1
0
    public void DamagePlanks(float amount, ShipStructure attacker)
    {
        PlanksHealth -= amount;
        while (PlanksHealth < (healthPerPlank * (planks.Count - 1)) && Planks.Count > 0)
        {
            if (!planks[planks.Count - 1].FloatingComponent.TryReturnToSpawner())
            {
                Debug.LogError("Should not happen");
            }
        }

        if (PlanksHealth <= 0)
        {
            if (attacker.CompareTag("Player"))
            {
                GameObject.Find("GameManager").GetComponent <Scoring>().ShipsSunk++;
            }

            PlanksHealth = 0;
            OnLose.Invoke(this);
            onDestroySounds.PlayRandomOneShot(Instantiate(onDestroySoundPrefab, transform.position, Quaternion.identity).GetComponent <AudioSource>());
            Instantiate(onDestroyParticles, transform.position, Quaternion.identity);
            Destroy(gameObject);
        }
    }
Ejemplo n.º 2
0
    public bool TryAttachToShip(ShipStructure structure)
    {
        // Try attaching this to the ship. If this returns false, then the ship
        // rejected the attachment (possibly because it already had a component of that type, or it hit a max number of components)
        if (enabled && shipComponent.Attach(structure))
        {
            // Attach was successful, so remove this from the spawner and
            // disable the floating behaviours

            // Release from the spawner if it was owned by it, as this is now owned by the ship
            if (SpawnTag != null)
            {
                SpawnTag.spawner.Remove(this);
            }

            attachSounds.PlayRandomOneShot(audioSource);

            // Disable the FloatingComponent, as this has been attached to the ship
            Destroy(rigidbody2D);
            rigidbody2D           = null;
            enabled               = false;
            outline.eraseRenderer = true;
            mouseOver             = false;
            //mask.alphaCutoff = 0;
            //oldMaskInteraction = renderer.maskInteraction;
            //renderer.maskInteraction = SpriteMaskInteraction.None;

            return(true);
        }

        return(false);
    }
Ejemplo n.º 3
0
    public void ApplyDamage(Collider2D collider, DamageInfo info)
    {
        if (!collider.transform.IsChildOf(transform))
        {
            // TODO: There's a bug here that I need to fix...
            Debug.LogError("Can't apply damage to object that we don't own");
            return;
        }

        if (scoring)
        {
            scoring.DamageTaken += (uint)info.amount;
        }
        if (info.source && info.source.CompareTag("Player"))
        {
            GameObject.Find("GameManager").GetComponent <Scoring>().DamageDealt += (uint)info.amount;
        }

        if (collider.CompareTag("Plank") || collider.CompareTag("Oar"))
        {
            DamagePlanks(info.amount, info.source);
        }
        else if (collider.CompareTag("Bow") || collider.CompareTag("Weapon"))
        {
            DamageBow(info.amount);
        }
        else if (collider.CompareTag("Stern"))
        {
            DamageStern(info.amount);
        }

        onDamagedSounds.PlayRandomOneShot(audioSource);

        rigidbody2D.AddForce(info.force.normalized * 100);
    }
Ejemplo n.º 4
0
 public void OnTrigger(TileTrigger.TriggerInfo info)
 {
     // User wins game on trigger!
     if (info.enter && info.isRobot && !win)
     {
         win = true;
         onPreWin.Invoke();
         onWinAudio.PlayRandomOneShot(audioSource);
         Instantiate(onWinParticles, transform);
         StartCoroutine(WinAnimation());
     }
 }
Ejemplo n.º 5
0
    public bool TryReturnToSpawner()
    {
        ShipStructure structure = shipComponent.AttachedStructure;

        if (!enabled && shipComponent.Detach())
        {
            rigidbody2D = gameObject.AddComponent <Rigidbody2D>();
            rigidbody2D.gravityScale = 0;

            // Pick a random direction away from structure and eject the component in that direction
            Vector2 direction = transform.position - structure.transform.position;
            rigidbody2D.AddForce(direction.normalized * 100);

            detachSounds.PlayRandomOneShot(audioSource);

            enabled = true;
            //renderer.maskInteraction = oldMaskInteraction;

            if (particlesOnDetach)
            {
                Instantiate(particlesOnDetach, transform.position, Quaternion.identity);
            }

            if (SpawnTag != null && !destroyOnDetach)
            {
                SpawnTag.spawner.Add(this);
            }
            else
            {
                // Was either not owned by a spawner, or we're set to destroy on detach
                Destroy(gameObject);
            }

            return(true);
        }

        return(false);
    }