Exemplo n.º 1
0
        public void Update()
        {
            var fruitsPerSec = developmentSpeed;
            var growFruit    = Random.Chance(fruitsPerSec * Time.DeltaTime * UpdateInterval);

            if (fruits < maxFruits && Time.TotalTime > fruitTimer && growFruit)
            {
                // spawn a fruit
                var fruitOffset = Random.Range(new Vector2(-fruitSpawnRange), new Vector2(fruitSpawnRange));
                var capNt       = Entity.Scene.CreateEntity(null, Entity.Position + fruitOffset)
                                  .SetTag(Constants.Tags.THING);
                var fruit = capNt.AddComponent <Capsule>();
                fruit.firstAvailableAt = Time.TotalTime + ripeningTime;
                fruit.creator          = this;
                fruit.energy           = Random.Range(fruitBaseValue * 0.6f, fruitBaseValue * 2.2f);
                fruit.body.velocity    = Vector2.Zero;
                childFruits.Add(fruit);
                fruits++;

                fruitTimer = Time.TotalTime + Random.Range(1.4f, 3.4f) * developmentSpeed;
            }

            // update existing fruits
            var growthPoints = 0;

            if (fruits > 0)
            {
                var rmFruits = new HashSet <Capsule>();
                foreach (var child in childFruits)
                {
                    var toChild = Entity.Position - child.Entity?.Position;
                    if (child.acquired || !toChild.HasValue || toChild.Value.LengthSquared() > childRange * childRange)
                    {
                        fruits--;
                        harvest++;
                        growthPoints++;
                        rmFruits.Add(child);
                    }
                }

                childFruits.RemoveAll(x => rmFruits.Contains(x));
            }

            // update general tree growth
            growthTimer -= developmentSpeed * growthPoints * 10f;
            if (Time.TotalTime > growthTimer)
            {
                stage++; // upgrade stage
                if (stage > 10)
                {
                    stage = 10;             // clamp to max stage
                }
                updateStage();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Place torches
        /// </summary>
        private void Stage7()
        {
            foreach (var room in _rooms)
            {
                var chance = 0.05f;
                foreach (var x in Enumerable.Range(room.Bounds.X, room.Bounds.Width))
                {
                    foreach (var y in Enumerable.Range(room.Bounds.Y, room.Bounds.Height))
                    {
                        if (x != room.Bounds.Left && x != room.Bounds.Right - 1 && y != room.Bounds.Top && y != room.Bounds.Bottom - 1)
                        {
                            continue;
                        }
                        if (x == room.Bounds.Left && (y == room.Bounds.Bottom - 1 || y == room.Bounds.Top))
                        {
                            continue;
                        }
                        if (x == room.Bounds.Right - 1 && (y == room.Bounds.Bottom - 1 || y == room.Bounds.Top))
                        {
                            continue;
                        }
                        if (_tileMap[x, y] != TileType.Wall)
                        {
                            continue;
                        }

                        if (RNG.Chance(chance))
                        {
                            _entities.Add(EntityFactory.Presets
                                          .Torch(_settings.TorchColor)
                                          .AtPosition(x * Tile.Width + 8, y * Tile.Height + 8)
                                          .Create());

                            chance = 0f;
                        }
                        else
                        {
                            chance += 0.015f;
                        }
                    }
                }
            }
        }