//---------------------------------------------------------------------------

        public void Spawn(EPickups pickup)
        {
            TransformComponent transform = GetComponent <TransformComponent>();

            if (transform != null)
            {
                float   rot   = (SeedManager.Get().NextRandF() * (float)Math.PI * 2.0f);
                float   dist  = (SeedManager.Get().NextRandF() * 120.0f + 400.0f);
                Vector3 force = new Vector3((float)Math.Sin(rot) * dist, (float)Math.Cos(rot) * dist, SeedManager.Get().NextRandF(20, 40));
                PickupFactory.Create(pickup, transform.Location, force);
            }
        }
Example #2
0
        //---------------------------------------------------------------------------

        public static Pickup Create(EPickups pickupType, Vector3 location, Vector3 force)
        {
            Pickup pickup = Create(pickupType.ToString(), location, force);

            IPickupComponent pickupComponent = null;

            Sprite sprite = m_Sprites[pickupType];

            pickup.AddComponent <SpriteComponent>().Init(sprite, Vector2.Zero, Vector2.One * 2);
            pickup.AddComponent <ShadowComponent>().Init(sprite, Vector2.One * 2, new Vector2(0, 3));
            pickup.AddComponent <LightingComponent>().Init(sprite, Vector2.Zero, Vector2.One * 2, Color.White, 0.5f);

            switch (pickupType)
            {
            case EPickups.Health:
                pickupComponent = pickup.AddComponent <HealthPickupComponent>();
                break;

            case EPickups.Mana:
                pickupComponent = pickup.AddComponent <ManaPickupComponent>();
                break;

            case EPickups.Coin:
                pickupComponent = pickup.AddComponent <CoinPickupComponent>();
                break;

            default:
                AssertManager.Get().Show("Value used by 'Create' does not fit range of EPickups");
                break;
            }

            if (pickupComponent != null)
            {
                pickup.GetComponent <CircleColliderComponent>().Enter += (source, target) =>
                {
                    pickupComponent.OnPickup(target);
                };
            }

            return(pickup);
        }
        //---------------------------------------------------------------------------

        public void Spawn()
        {
            int t_rnd = m_Rand.Next(5, 9);

            for (int i = 0; i < t_rnd; i++)
            {
                EPickups type = (EPickups)m_Rand.Next(0, Enum.GetValues(typeof(EPickups)).Length);

                if (type == EPickups.Item)
                {
                    EItemType item = ItemManager.Get().Next(EItemPool.SmallChest);
                    if (item != EItemType.None)
                    {
                        Spawn(item);
                    }
                }
                else
                {
                    Spawn(type);
                }
            }
        }
    void Start()
    {
        holdingSomething = false;

        //Edit this later so that all pick up items are placed here
        onCameraCube = GameObject.FindGameObjectWithTag("PickedUpCube");
        if (null != onCameraCube)
        {
            onCameraCube.SetActive(false);
        }

        onCameraBottle = GameObject.FindGameObjectWithTag("PickedUpBottle");
        if (null != onCameraCube)
        {
            onCameraBottle.SetActive(false);
        }

        onCameraChicken = GameObject.FindGameObjectWithTag("PickedUpChicken");
        if (null != onCameraChicken)
        {
            onCameraChicken.SetActive(false);
        }

        onCameraBanana = GameObject.FindGameObjectWithTag("PickedUpBanana");
        if (null != onCameraBanana)
        {
            onCameraBanana.SetActive(false);
        }

        onCameraEgg = GameObject.FindGameObjectWithTag("PickedUpEgg");
        if (null != onCameraEgg)
        {
            onCameraEgg.SetActive(false);
        }

        onCameraSteak = GameObject.FindGameObjectWithTag("PickedUpSteak");
        if (null != onCameraSteak)
        {
            onCameraSteak.SetActive(false);
        }

        onCameraKey = GameObject.FindGameObjectWithTag("PickedUpKey");
        if (null != onCameraKey)
        {
            onCameraKey.SetActive(false);
        }

        onCameraHam = GameObject.FindGameObjectWithTag("PickedUpHam");
        if (null != onCameraHam)
        {
            onCameraHam.SetActive(false);
        }

        onCameraSandwitch = GameObject.FindGameObjectWithTag("PickedUpSandwitch");
        if (null != onCameraSandwitch)
        {
            onCameraSandwitch.SetActive(false);
        }

        onCameraApple = GameObject.FindGameObjectWithTag("PickedUpApple");
        if (null != onCameraApple)
        {
            onCameraApple.SetActive(false);
        }

        holding = EPickups.ENONE;
    }
    void Update()
    {
        if (Input.GetKeyDown("space"))
        {
            if (!holdingSomething && null != test)
            {
                if (test.tag == "PickUpChicken")
                {
                    if (null != onCameraChicken)
                    {
                        holding = EPickups.ECHICKEN;

                        onCameraChicken.SetActive(true);
                    }
                }
                else if (test.tag == "PickUpBottle")
                {
                    if (null != onCameraBottle)
                    {
                        holding = EPickups.EBOTTLE;

                        onCameraBottle.SetActive(true);
                    }
                }
                else if (test.tag == "PickUpBanana")
                {
                    if (null != onCameraBanana)
                    {
                        holding = EPickups.EBANANA;

                        onCameraBanana.SetActive(true);
                    }
                }
                else if (test.tag == "PickUpEgg")
                {
                    if (null != onCameraEgg)
                    {
                        holding = EPickups.EEGG;

                        onCameraEgg.SetActive(true);
                    }
                }
                else if (test.tag == "PickUpSteak")
                {
                    if (null != onCameraSteak)
                    {
                        holding = EPickups.ESTEAK;

                        onCameraSteak.SetActive(true);
                    }
                }
                else if (test.tag == "PickUpKey")
                {
                    if (null != onCameraKey)
                    {
                        holding = EPickups.EKEY;

                        onCameraKey.SetActive(true);
                    }
                }
                else if (test.tag == "PickUpHam")
                {
                    if (null != onCameraHam)
                    {
                        holding = EPickups.EHAM;

                        onCameraHam.SetActive(true);
                    }
                }
                else if (test.tag == "PickUpSandwitch")
                {
                    if (null != onCameraSandwitch)
                    {
                        holding = EPickups.ESANDWITCH;

                        onCameraSandwitch.SetActive(true);
                    }
                }
                else if (test.tag == "PickUpApple")
                {
                    if (null != onCameraApple)
                    {
                        holding = EPickups.EAPPLE;

                        onCameraApple.SetActive(true);
                    }
                }
                else if (test.tag == "PickUpCube")
                {
                    if (null != onCameraCube)
                    {
                        holding = EPickups.ECUBE;

                        onCameraCube.SetActive(true);
                    }
                }
                test.gameObject.SetActive(false);
                holdingSomething = true;
            }
            else
            {
                if (!m_wallInfront)
                {
                    switch (holding)
                    {
                    case EPickups.ECUBE:
                    {
                        if (null != onCameraCube)
                        {
                            onCameraCube.SetActive(false);
                        }
                        break;
                    }

                    case EPickups.EBOTTLE:
                    {
                        if (null != onCameraBottle)
                        {
                            onCameraBottle.SetActive(false);
                        }
                        break;
                    }

                    case EPickups.ECHICKEN:
                    {
                        if (null != onCameraChicken)
                        {
                            onCameraChicken.SetActive(false);
                        }
                        break;
                    }

                    case EPickups.EBANANA:
                    {
                        if (null != onCameraBanana)
                        {
                            onCameraBanana.SetActive(false);
                        }
                        break;
                    }

                    case EPickups.EEGG:
                    {
                        if (null != onCameraEgg)
                        {
                            onCameraEgg.SetActive(false);
                        }
                        break;
                    }

                    case EPickups.ESTEAK:
                    {
                        if (null != onCameraSteak)
                        {
                            onCameraSteak.SetActive(false);
                        }
                        break;
                    }

                    case EPickups.EKEY:
                    {
                        if (null != onCameraKey)
                        {
                            onCameraKey.SetActive(false);
                        }
                        break;
                    }

                    case EPickups.EHAM:
                    {
                        if (null != onCameraHam)
                        {
                            onCameraHam.SetActive(false);
                        }
                        break;
                    }

                    case EPickups.ESANDWITCH:
                    {
                        if (null != onCameraSandwitch)
                        {
                            onCameraSandwitch.SetActive(false);
                        }
                        break;
                    }

                    case EPickups.EAPPLE:
                    {
                        if (null != onCameraApple)
                        {
                            onCameraApple.SetActive(false);
                        }
                        break;
                    }

                    default:
                        break;
                    }
                }

                if (holding != EPickups.ENONE)
                {
                    test.gameObject.SetActive(true);

                    test.transform.position = transform.position + (transform.forward * distanceInfront);
                    test.transform.rotation = transform.rotation;

                    holding          = EPickups.ENONE;
                    holdingSomething = false;
                    test             = null;
                }
            }
        }
    }