/// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            time += gameTime.ElapsedGameTime;
            var blobsToAdd = new List <Blob>();

            if (time.TotalSeconds > ROUND_TIME)
            {
                foreach (var blob in blobs.Where(b => b.Alive))
                {
                    if (!blob.HasEaten)
                    {
                        blob.Alive = false;
                    }
                    else
                    {
                        var blobFactory = new Factory <Blob>();
                        var children    = blobFactory.CreateRandom(2);
                        blobsToAdd.AddRange(children);
                    }
                }
                blobs.Clear();
                blobs.AddRange(blobsToAdd);
                var foodFactory = new Factory <Food>();
                food = foodFactory.CreateRandom(FOOD_AMOUNT, new Rectangle(650, 400, 500, 500));

                time = new TimeSpan();
            }

            Renderer.Dt = gameTime.ElapsedGameTime.TotalMilliseconds / 1000;
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }


            foreach (var blob in blobs.Where(b => b.Alive))
            {
                foreach (var f in food.Where(f => !f.Eaten))
                {
                    if (CollisionDetector.Collides(blob, f))
                    {
                        f.Eaten           = true;
                        blob.CurrentState = Blob.state.searching;
                        blob.Energy      += f.Energy;
                        blob.HasEaten     = true;
                        blob.color        = Color.White;
                        blob.Stop();
                    }
                }

                blob.Update(food);
            }
            // TODO: Add your update logic here

            base.Update(gameTime);
        }
Exemple #2
0
    public bool CanMoveTo(float x, float y, Rect collisionBox)
    {
        Rect collider = new Rect(collisionBox.x + x, collisionBox.y + y, collisionBox.width, collisionBox.height);

        return(!collisionDetector.Collides(collider));
    }