Пример #1
0
        public bool Colliding(Vector2 position, Vector2 size, ICollider check)
        {
            int StartX = 0;
            int StartY = 0;

            if (position.X + StartX >= 0 && position.Y + StartY >= 0)
            {
                for (int y = 0; y < size.Y; y++)
                {
                    for (int x = 0; x < size.X; x++)
                    {
                        if (GetTile(new Vector2(position.X + x, position.Y + y)) != null)
                        {
                            if (check != null)
                            {
                                if (check is ICollider && GetTile(new Vector2(position.X + x, position.Y + y)) is ICollider)
                                {
                                    check.Collision(GetTile(new Vector2(position.X + x, position.Y + y)));
                                }
                            }
                            return(false);
                        }
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        public bool Move()
        {
            Position newSnakeHeadPosition = new Position(snakePositions[0]);

            snakeTailOldPosition = new Position(snakePositions[snakePositions.Count - 1]);

            UpdateNewSnakePosition(newSnakeHeadPosition);
            if (newSnakeHeadPosition.Equals(snakePositions[0])) // Snake hasn't moved
            {
                return(ConstBools.GameNotOver);
            }
            WrapUpSnakePosition(newSnakeHeadPosition); // Wrapping if player wwent outside of the map
            ICollider collisionObject = myGameManager.GetColliderAtPosition(newSnakeHeadPosition);

            myGameManager.ChangeColliderPosition(snakePositions[snakePositions.Count - 1], newSnakeHeadPosition);
            snakePositions.Insert(0, newSnakeHeadPosition);
            snakePositions.RemoveAt(snakePositions.Count - 1);

            if (collisionObject != null && collisionObject.Collision(this) == ConstBools.GameOver)
            {
                numberofSnakeParts = 1;
                return(ConstBools.GameOver);
            }

            return(ConstBools.GameNotOver);
        }
 public void Colliding(ICollider checkingCollider)
 {
     foreach (ICollider collider in colliders)
     {
         if (collider != checkingCollider)
         {
             if (CheckCollision(checkingCollider, collider))
             {
                 checkingCollider.Collision(collider);
                 if (collider is Projectile && checkingCollider is ModifiableTile)
                 {
                     if (((Projectile)collider).Shooter.TeamAssociation != ((ModifiableTile)checkingCollider).TeamAssociation)
                     {
                         deletedColliders.Add(collider);
                     }
                 }
             }
         }
     }
 }