Exemplo n.º 1
0
    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag == "Pickup")
        {
            // Fetch item
            Item.ItemInstance item = collision.gameObject.GetComponent <Item>().myInstance;
            // Try add to player
            gameObject.GetComponentInParent <ItemController>().AddItem(item);
            // If fireball change projectile
            if (item.Type == Item.ItemType.FireBall)
            {
                Projectile proj = collision.gameObject.GetComponent <Projectile>();
                gameObject.GetComponentInParent <ItemController>().ChangeProjectile(proj);
            }
            // Play soundeffect
            AudioManager.Instance.Play("Pickup");
            // Delete item
            Destroy(collision.transform.parent.gameObject);
        }
        // Ignore own projectiles
        else if (collision.gameObject.tag == "Projectile")
        {
            GameObject           projGo = collision.gameObject;
            ProjectileController proj   = projGo.GetComponent <ProjectileController>();

            if (proj.creator == "Enemy")
            {
                AudioManager.Instance.Play("Explosion");
                GameManager.Instance.DamageControllerInstance.ChangeHealth(proj.damage, DamageController.DamageType.Enemy, "projectile");
            }
        }
        else if (bodyPart == BodyPart.Torso && !collision.gameObject.CompareTag("Sword"))
        {
            Obstacle obs = collision.gameObject.GetComponentInParent <Obstacle>();
            if (obs != null)
            {
                if (!obs.HasGesturePassed)
                {
                    GameManager.Instance.DamageControllerInstance.ChangeHealth(10, DamageController.DamageType.Obstacle, "obstacle");
                }
                else
                {
                    Debug.Log("No damage b/c gesture was passed!");
                }
            }
            else
            {
                Debug.Log("No damage b/c no obstacle attached!");
            }
        }
        else if (collision.gameObject.CompareTag("Coin"))
        {
            GameManager.Instance.ScoreManagerInstance.AddPoints(GameManager.Instance.ScoreManagerInstance.coinPoints);
            // Play soundeffect
            AudioManager.Instance.Play("Coin");
            // Delete item
            Destroy(collision.transform.parent.gameObject);
        }
    }
Exemplo n.º 2
0
    // Trys to give the player the item
    public void AddItem(Item.ItemInstance item)
    {
        GameObject   itemObject;
        HandednessGO handDic;

        // Activate gestures
        long userId = KinectManager.Instance.GetUserIdByIndex(playerIndex);

        switch (item.Type)
        {
        case Item.ItemType.FireBall:
        {
            if (item.Version == Item.ItemVersion.FireFlower)
            {
                KinectManager.Instance.DetectGesture(userId, KinectGestures.Gestures.FireFlower);
            }
            else
            {
                KinectManager.Instance.DetectGesture(userId, KinectGestures.Gestures.HadoukenCharge);
                KinectManager.Instance.DetectGesture(userId, KinectGestures.Gestures.HadoukenFire);
            }
            // Remove sword
            RemoveItem(Item.ItemType.Sword);
            break;
        }

        case Item.ItemType.Shield:
        {
            KinectManager.Instance.DetectGesture(userId, KinectGestures.Gestures.ShieldBegin);
            break;
        }

        case Item.ItemType.Sword:
        {
            KinectManager.Instance.DetectGesture(userId, KinectGestures.Gestures.Sword);
            // Remove fireball
            RemoveItem(Item.ItemType.FireBall);
            break;
        }

        default:
        {
            Debug.LogError("Invalid item type " + item.Type);
            break;
        }
        }

        // If the player doesnt have the item type already
        if (ownedItems[item.Type].Version == Item.ItemVersion.Invalid)
        {
            // Save the version
            ownedItems[item.Type] = item;
        }
        // Otherwise exchange
        else
        {
            // Disable old gameobject
            if (itemObjects.TryGetValue(ownedItems[item.Type].Version, out handDic))
            {
                if (handDic.TryGetValue(PlayerManager.Instance.GetPlayerCalibration(playerIndex).Handedness, out itemObject))
                {
                    if (itemObject != null)
                    {
                        itemObject.SetActive(false);
                    }
                }
            }
            // Save new version
            ownedItems[item.Type] = item;
        }

        // Enable corresponding gameobject
        if (itemObjects.TryGetValue(ownedItems[item.Type].Version, out handDic))
        {
            if (handDic.TryGetValue(PlayerManager.Instance.GetPlayerCalibration(playerIndex).Handedness, out itemObject))
            {
                // Hadouken is not activated here
                if (itemObject != null && item.Version != Item.ItemVersion.Hadouken)
                {
                    itemObject.SetActive(true);
                }
            }
        }
    }