Esempio n. 1
0
    /**
     * Spawn SpeedPotions in the area
     */
    private void SpawnSpeedPotions()
    {
        FunctionPeriodic.Create(
            () =>
        {
            if (IngestibleManager.IngestibleCount <SpeedPotion>() < _SPEED_POTION_MAX_SPAWNS)
            {
                Vector3 speedPotionWorldPosition = new Vector3(
                    Random.Range(-_MAX_RADIUS, _MAX_RADIUS),
                    AssetManager.Get_Prefab_SpeedPotion().transform.localScale.y / 2 + AssetManager.GetTerrain().localScale.y,
                    Random.Range(-_MAX_RADIUS, _MAX_RADIUS)
                    );

                SpeedPotion speedPotion = Instantiate(
                    AssetManager.Get_Prefab_SpeedPotion(),
                    speedPotionWorldPosition,
                    Quaternion.identity
                    );

                IngestibleManager.AddIngestible(speedPotion);
            }
        },
            "SpawnSpeedPotions",
            0f,
            0f,
            () =>
        {
            if (IngestibleManager.IngestibleCount <SpeedPotion>() >= _SPEED_POTION_MAX_SPAWNS)
            {
                Destroy(GameObject.Find("SpawnSpeedPotions"));
            }
        }
            );
    }
Esempio n. 2
0
 public void Set()
 {
     Health             = new HealthPotion(_player);
     HealthRegeneration = new HealthRegenerationPotion(_player);
     Speed    = new SpeedPotion(_player);
     Damage   = new DamagePotion(_player);
     Defense  = new DefensePotion(_player);
     Guidance = new GuidancePotion(_player);
 }
        public void Generate()
        {
            int amount = Rand.NextExp(1, 4, 1);

            Potion[] potions = new Potion[amount];
            Vector2  pos     = new Vector2(xpbar.Position.X + xpbar.cage.Width, xpbar.Position.Y);

            for (int i = 0; i < amount; i++)
            {
                pos.X += padding;
                int       r       = Rand.Next(4);
                Texture2D texture = vials[r];
                Potion    p       = null;
                switch (r)
                {
                case 0:
                    p = new HealthPotion(yat, texture, null, pos, Rand.Next(2, 16), Rand.Next(10, 20), Rand.Next(1, 11));
                    break;

                case 1:
                    p = new InvulnerabilityPotion(yat, texture, null, pos, Rand.Next(1, 11));
                    break;

                case 2:
                    p = new JumpPotion(yat, texture, null, pos, Rand.Next(10, 20));
                    break;

                case 3:
                    p = new SpeedPotion(yat, texture, null, pos, Rand.Next(10, 20), Rand.Next(2, 5));
                    break;
                }
                potions[i] = p;
                pos.X     += texture.Width;
            }
#if DEBUG
            Debugger.Log(1, "Main", string.Format("Generated {0} potions...\n", amount));;
#endif
            this.created.AddRange(potions);
        }
Esempio n. 4
0
        public override void Update()
        {
            base.Update();

            ShowPlayerInformation();
            counter++;
            animationOn.Start();

            if (GetWorld().GetActors().Find(a => a.GetName() == "enemy") == null)
            {
                world = GetWorld();
                world.SetEndCondition(world => MapStatus.Finished);
            }

            if (GetHealth() == 0)
            {
                Die();
            }

            if (myState == false)
            {
                animationOn.Stop();
                world = GetWorld();
                world.SetEndCondition(world => MapStatus.Failed);
            }
            else
            {
                if (Input.GetInstance().IsKeyPressed(Input.Key.LEFT))
                {
                    if (side == false)
                    {
                        animationOn.FlipAnimation();
                        side = true;
                    }
                }
                else if (Input.GetInstance().IsKeyPressed(Input.Key.RIGHT))
                {
                    if (side == true)
                    {
                        animationOn.FlipAnimation();
                        side = false;
                    }
                }
                else if (Input.GetInstance().IsKeyDown(Input.Key.SPACE) && Input.GetInstance().IsKeyDown(Input.Key.LEFT) && bunnyHop > 0)
                {
                    SetPhysics(false);
                    foreach (Command command in jumpLeft)
                    {
                        command.Execute();
                    }
                    bunnyHop--;
                }
                else if (Input.GetInstance().IsKeyDown(Input.Key.SPACE) && Input.GetInstance().IsKeyDown(Input.Key.RIGHT) && bunnyHop > 0)
                {
                    SetPhysics(false);
                    foreach (Command command in jumpRight)
                    {
                        command.Execute();
                    }
                    bunnyHop--;
                }
                else if (Input.GetInstance().IsKeyDown(Input.Key.LEFT))
                {
                    SetPhysics(true);
                    moveLeft.Execute();
                }
                else if (Input.GetInstance().IsKeyDown(Input.Key.RIGHT))
                {
                    SetPhysics(true);
                    moveRight.Execute();
                }
                else if (Input.GetInstance().IsKeyDown(Input.Key.UP) && bunnyHop > 0)
                {
                    SetPhysics(false);
                    jump.Execute();
                    bunnyHop--;
                }
                else if (Input.GetInstance().IsKeyPressed(Input.Key.E))
                {
                    backpack.ShiftRight();
                }
                else if (Input.GetInstance().IsKeyPressed(Input.Key.Q))
                {
                    backpack.ShiftLeft();
                }
                else if (Input.GetInstance().IsKeyDown(Input.Key.F))
                {
                    potion = backpack.GetItem();
                    if (potion is HealingPotion)
                    {
                        healingPotion = (HealingPotion)potion;
                        healingPotion.Use(this);
                    }
                    else if (potion is ManaPotion)
                    {
                        manaPotion = (ManaPotion)potion;
                        manaPotion.Use(this);
                    }
                    else if (potion is SpeedPotion)
                    {
                        speedPotion = (SpeedPotion)potion;
                        speedPotion.Use(this);
                        speedCounter = 1;
                    }
                    else if (potion is JumpPotion)
                    {
                        jumpPotion = (JumpPotion)potion;
                        jumpPotion.Use(this);
                        jumpCounter = 1;
                    }
                }
                else if (Input.GetInstance().IsKeyPressed(Input.Key.R))
                {
                    backpack.RemoveItem(backpack.GetCapacity() - position);
                    position++;
                }
                else
                {
                    SetPhysics(true);
                    animationOn.Stop();
                }

                if (bunnyHop < 20)
                {
                    if (counter % 120 == 0)
                    {
                        bunnyHop = 20;
                    }
                }

                if (jumpCounter > 0)
                {
                    jumpCounter++;
                    if (jumpCounter == jumpPotion.GetDuration())
                    {
                        SetJump(3);
                        jumpCounter = 0;
                    }
                }


                if (speedCounter > 0)
                {
                    speedCounter++;
                    if (speedCounter == speedPotion.GetDuration())
                    {
                        this.SetSpeedStrategy(speedStrategy);
                        speedCounter = 0;
                    }
                }
            }
        }