Ejemplo n.º 1
0
 public override void registerFoodLeaf(Leaf leafToRegister, Food foodBeingEaten, int sequenceLength)
 {
     if (!_connectedFoodLeaves.Contains(leafToRegister) && sequenceLength < _pulseStrength + foodBeingEaten.getEnergyAmount())
     {
         leafToRegister.startEating(foodBeingEaten);
         foodBeingEaten.resolveCollision(this);
         _connectedFoodLeaves.Add(leafToRegister);
         _pulseStrength += foodBeingEaten.getEnergyAmount();
     }
 }
Ejemplo n.º 2
0
 private void startBeingConsumed(Leaf collider)
 {
     _texture = _gameManager.Content.Load<Texture2D>("Textures/food_being_consumed_160");
     _isBeingConsumed = true;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// This function is recursively called on the parents until it reaches a heart or a leaf that has no parents.
        /// </summary>
        /// <param name="?"></param>
        public virtual void registerFoodLeaf(Leaf leafToRegister, Food foodBeingEaten, int sequenceLength = 0)
        {
            sequenceLength++;

            for (int i = 0; i < _parents.Count; i++)
                _parents[i].registerFoodLeaf(leafToRegister, foodBeingEaten, sequenceLength);
        }
Ejemplo n.º 4
0
        public void addChild(Leaf child)
        {
            if (!_children.Contains(child))
                _children.Add(child);
            if (!child._parents.Contains(this))
                child._parents.Add(this);

            for (int i = 0; i < GameManager.NUM_COLORS; i++)
            {
                if (_distToColors[i] == -1 || _distToColors[i] > GameManager.MAX_DIST_TO_COLOR[i])
                    child.updateDistToColor(i, -1);
                else
                    child.updateDistToColor(i, _distToColors[i]+1);
            }
        }
Ejemplo n.º 5
0
 public void addLeaf(Leaf leaf, bool doInit = true)
 {
     _leaves.Add(leaf);
     addEntity(leaf, true, doInit);
 }
Ejemplo n.º 6
0
        public override void update(float dT)
        {
            base.update(dT);

            #region Seed (cursor) placement
            Leaf closestLeaf        = null;
            float closestDist       = float.MaxValue;
            Vector2 mouseWorldPos   = (InputManager.getMousePos() - GameManager.WORLDOGIRIN)/GameManager.ZOOMLEVEL;
            for (int i = 0; i < _leaves.Count; i++) //Find closest leaf
            {
                _leaves[i].isSelected = false;

                float distToLeaf = (_leaves[i].getPosition() - mouseWorldPos).Length() - _leaves[i].getRadius();
                if (distToLeaf < closestDist && distToLeaf >= 0) //Find closest leaf
                {
                    closestLeaf = _leaves[i];
                    closestDist = distToLeaf;
                }
            }

            if (closestLeaf != null) //We have a winner!
            {
                closestLeaf.isSelected  = true;
                Vector2 leafToMouse     = mouseWorldPos - closestLeaf.getPosition();
                leafToMouse.Normalize();
                leafToMouse             *= closestLeaf.getRadius() + 1;
                Vector2 seedPos         = closestLeaf.getPosition() + leafToMouse;
                bool canPlace           = true;

                for (int i = 0; i < _leaves.Count; i++) //Find intersecting leaves
                {
                    if ((_leaves[i].getPosition() - seedPos).LengthSquared() < _leaves[i].getRadius() * _leaves[i].getRadius())
                        canPlace = false;
                }

                if (canPlace)
                    _seedCursor.setPosition(seedPos);

                //Handle input
                if (InputManager.isMouseLeftReleased() &&
                    _gameManager.GraphicsDevice.Viewport.Bounds.Contains(InputManager.getMouseX(), InputManager.getMouseY()))
                {
                    Leaf newLeaf = new Leaf(_gameManager, this);
                    newLeaf.setPosition(_seedCursor.getPosition());
                    addLeaf(newLeaf);
                    closestLeaf.addChild(newLeaf);
                }
            }
            #endregion

            _seedCursor.update(dT);

            //Pulse hearts
            if (GameManager.CURRENTTIME - _lastPulseTime >= _timeBetweenPulses)
            {
                _lastPulseTime = GameManager.CURRENTTIME;
                for (int i = 0; i < _hearts.Count; i++)
                    _hearts[i].pulse();
            }
        }