示例#1
0
文件: Food.cs 项目: THISisZOLI/snake
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.name.Equals("Snake"))
     {
         Destroy(gameObject);
         OnFoodEaten?.Invoke();
     }
 }
示例#2
0
 private void OnTriggerEnter(Collider other)
 {
     if (!other.CompareTag("Snake"))
     {
         return;
     }
     OnFoodEaten?.Invoke();
     Destroy(gameObject);
 }
示例#3
0
    private void OnTriggerEnter(Collider other)
    {
        InterarctionType it;

        if (_npc && _npc.AllowedToInteract(other.gameObject, out it))
        {
            if (it == InterarctionType.Food)
            {
                OnFoodEaten?.Invoke();
            }
        }
    }
示例#4
0
文件: Snake.cs 项目: Xansher/Snake
        public void Update(Food food)
        {
            // Snake head move
            SnakeHead.Move();
            SnakeHead.Update();
            //Snake bodypart move
            Direction previousDirection;
            Direction nextDirection = SnakeHead.Direction;

            foreach (var part in SnakeBody)
            {
                part.Move();
                part.Update();
                previousDirection = part.Direction;
                part.Direction    = nextDirection;
                nextDirection     = previousDirection;
            }
            //check if snake head hit wall

            if (SnakeHead.HitWall())
            {
                OnHitWall?.Invoke();
            }

            //check if snake eat food

            if (SnakeHead.EatenFood(food))
            {
                OnFoodEaten?.Invoke();
                AddSnakeBody();
            }

            //check if snakehead hit body

            foreach (var part in SnakeBody)
            {
                if (SnakeHead.X == part.X && SnakeHead.Y == part.Y)
                {
                    OnHitBody?.Invoke();
                }
            }
            IsUpdating = false;
        }
示例#5
0
    private void CheckIfItemIsFood()
    {
        // If the selected item is null or is not of the category food, drop the item and reset timer values
        if (m_SelectedSlot.ObjectData == null || m_SelectedSlot.ObjectData.ItemCategory != "Food")
        {
            ResetDropKey();
            DropItem(m_SelectedSlot);
        }
        else
        {
            m_HoldingDropKeyTime -= Time.deltaTime;

            // When the timer is below 0, set the key back to not being pressed, gain the health value and remove the item
            if (m_HoldingDropKeyTime < 0f)
            {
                ResetDropKey();
                OnFoodEaten?.Invoke(m_SelectedSlot.ObjectData);
                RemoveSingleItem(m_SelectedSlot);
            }
        }
    }
示例#6
0
 public override void Remove()
 {
     OnFoodEaten?.Invoke(this, new FoodEatenEventArgs(this));
     base.Remove();
 }