Ejemplo n.º 1
0
    // called when character is entering this collectable
    public void OnTriggerEnter2D(Collider2D otherCollider)
    {
        APSamplePlayer player = otherCollider.GetComponent <APSamplePlayer>();

        if (!m_launched && player && player.GetGUI() && !string.IsNullOrEmpty(m_levelName))
        {
            m_launched = true;
            player.GetGUI().LoadLevel(m_levelName, m_timeToLoad);
        }
    }
Ejemplo n.º 2
0
    // called when we have been hit by a melee attack
    override public bool OnMeleeAttackHit(APCharacterController character, APHitZone hitZone)
    {
        // Do nothing if player is currently blinking
        APSamplePlayer samplePlayer = character.GetComponent <APSamplePlayer>();

        if (samplePlayer && samplePlayer.IsGodModeEnabled())
        {
            return(false);
        }

        return(AddHitDamage(hitZone.m_damage));
    }
Ejemplo n.º 3
0
    // called when character motor ray is touching us
    override public void OnCharacterTouch(APCharacterController character, APCharacterMotor.RayType rayType)
    {
        // Do nothing if dead
        if (IsDead())
        {
            return;
        }

        // prevent checking hits too often
        if (Time.time < m_lastHitTime + m_minTimeBetweenTwoReceivedHits)
        {
            return;
        }

        // save current hit time
        m_lastHitTime = Time.time;

        // check if jumping on us
        APSamplePlayer samplePlayer = character.GetComponent <APSamplePlayer>();

        if (rayType == APCharacterMotor.RayType.Ground)
        {
            // make character jump
            float  fRatio      = m_jumpRatioInputReleased;
            string sJumpButton = character.m_jump.m_button;
            if (!string.IsNullOrEmpty(sJumpButton) && Input.GetButton(sJumpButton))
            {
                fRatio = m_jumpRatioInputPushed;
            }

            if (fRatio > 0f)
            {
                character.Jump(fRatio);
            }

            // add hit to us
            AddHitDamage(samplePlayer.m_jumpDamage);
        }
        else
        {
            // notify hit to character controller as Blob makes damage by touching it
            samplePlayer.OnHit(this);
        }
    }
Ejemplo n.º 4
0
    // Catch this collectible
    void HandleCatch(APCharacterController character)
    {
        if (!m_catched)
        {
            m_catched = true;

            // update player data
            APSamplePlayer player = character.GetComponent <APSamplePlayer>();
            if (player != null)
            {
                player.AddLife(m_lifePoints);
                player.AddScore(m_scorePoints);
                player.AddAmmo(m_ammoPoints, m_rangedAttackIndex);
            }

            // destroy me
            Object.Destroy(gameObject);
        }
    }
Ejemplo n.º 5
0
    // called when character is entering this collectable
    public void OnTriggerEnter2D(Collider2D otherCollider)
    {
        APSamplePlayer character = otherCollider.GetComponent <APSamplePlayer>();

        if (character && !character.IsGodModeEnabled())
        {
            // prevent checking hits too often
            if (Time.time < m_lastHitTime + m_minTimeBetweenTwoReceivedHits)
            {
                return;
            }

            // save current hit time
            m_lastHitTime = Time.time;

            // add hit to character
            character.OnHit(m_touchDamage, transform.position);
        }
    }
    // Catch this collectible
    void HandleCatch(APCharacterController character)
    {
        if (!m_catched)
        {
            m_catched = true;

            // update player data
            APSamplePlayer player = character.GetComponent <APSamplePlayer>();
            if (player != null)
            {
                player.AddLife(m_lifePoints);
                player.AddScore(m_scorePoints);
                if (m_ammoBox != null)
                {
                    m_ammoBox.AddAmmo(m_ammoPoints);
                }
            }

            StartCoroutine(wait());
        }
    }
Ejemplo n.º 7
0
    // called when character motor ray is touching us
    override public bool OnCharacterTouch(APCharacterController character, APCharacterMotor.RayType rayType, RaycastHit2D hit, float penetration,
                                          APMaterial hitMaterial)
    {
        // Do nothing if dead
        if (IsDead())
        {
            return(false);
        }

        // Do nothing in godmode
        APSamplePlayer samplePlayer = character.GetComponent <APSamplePlayer>();

        if (samplePlayer && samplePlayer.IsGodModeEnabled())
        {
            return(false);
        }

        // check if jumping on us
        bool bHit = false;

        if ((rayType == APCharacterMotor.RayType.Ground) && (penetration <= m_jumpHitPenetrationTolerance))
        {
            // make character jump
            float fRatio = m_jumpRatioInputReleased;
            if (character.m_jump.m_button.IsSpecified() && character.m_jump.m_button.GetButton())
            {
                fRatio = m_jumpRatioInputPushed;
            }

            if (fRatio > 0f)
            {
                character.Jump(character.m_jump.m_minHeight * fRatio, character.m_jump.m_maxHeight * fRatio);
            }

            // add hit to NPC
            if (samplePlayer)
            {
                AddHitDamage(samplePlayer.m_jumpDamage);
            }

            bHit = true;
        }
        else if (penetration <= m_hitPenetrationTolerance)
        {
            // add hit to character
            if (samplePlayer)
            {
                samplePlayer.OnHit(m_touchDamage, transform.position);
            }

            bHit = true;
        }

        // prevent checking hits too often
        if (bHit)
        {
            if (Time.time < m_lastHitTime + m_minTimeBetweenTwoReceivedHits)
            {
                return(false);
            }

            // save current hit time
            m_lastHitTime = Time.time;
        }

        // always ignore contact
        return(false);
    }
Ejemplo n.º 8
0
 // Use this for initialization
 void Awake()
 {
     m_character = GameObject.FindObjectOfType <APCharacterController>();
     m_player    = GameObject.FindObjectOfType <APSamplePlayer>();
 }
 void Start()
 {
     m_player = GetComponent <APSamplePlayer>();
 }