Beispiel #1
0
 public Texture(string name, string displayName, Sprite sprite, Bitmap image, Vector2 position, DrawManager.ImagePosition orientation)
 {
     Sprite = sprite;
     DisplayName = displayName;
     Position = position;
     Orientation = orientation;
     Image = image;
     Name = name;
     Type = ObjectType.Texture;
 }
        public static Vector2 getTexturePosition(this Texture texture, DrawManager.ImagePosition overrideOrientation = DrawManager.ImagePosition.Default)
        {
            Vector2 Position = texture.Position;
            DrawManager.ImagePosition orientation = (overrideOrientation == DrawManager.ImagePosition.Default) ? texture.Orientation : overrideOrientation;
            
            switch (orientation)
            {
                case DrawManager.ImagePosition.TopLeft:
                    //no change
                    break;
                case DrawManager.ImagePosition.TopCenter:
                    Position -= new Vector2(texture.Image.Width / 2, 0);
                    break;
                case DrawManager.ImagePosition.TopRight:
                    Position -= new Vector2(texture.Image.Width, 0);
                    break;
                case DrawManager.ImagePosition.MiddleLeft:
                    Position -= new Vector2(0, texture.Image.Height / 2);
                    break;
                case DrawManager.ImagePosition.Center:
                    Position -= new Vector2(texture.Image.Width / 2, texture.Image.Height / 2);
                    break;
                case DrawManager.ImagePosition.MiddleRight:
                    Position -= new Vector2(texture.Image.Width, texture.Image.Height / 2);
                    break;
                case DrawManager.ImagePosition.BottomLeft:
                    Position -= new Vector2(0, texture.Image.Height);
                    break;
                case DrawManager.ImagePosition.BottomCenter:
                    Position -= new Vector2(texture.Image.Width / 2, texture.Image.Height);
                    break;
                case DrawManager.ImagePosition.BottomRight:
                    Position -= new Vector2(texture.Image.Width, texture.Image.Height);
                    break;
            }

            if(overrideOrientation != DrawManager.ImagePosition.Default)
                return Position - (Position - texture.getTexturePosition());

            return Position;
        }
Beispiel #3
0
        public static void DoMovement()
        {
            Vector2 nextPosition = snakePositions.First().Move(direction, snakePieceSize);
            Texture background   = DrawManager.GetTexture("Background");

            //allow the snake to go through the borders of the screen
            //this if statement checks if it is still within the screen border. if not, it needs to put the snake on the other side
            if (!new System.Drawing.Rectangle(
                    background.getTexturePosition(DrawManager.ImagePosition.TopLeft)
                    .ToPoint(), new Size(background.Image.Width - snakePieceSize, background.Image.Height - snakePieceSize))
                .IsInside(nextPosition + background.Position))
            {
                if (direction == Direction.West)
                {
                    nextPosition.X = (background.getTexturePosition(DrawManager.ImagePosition.TopLeft) - background.Position).X + background.Image.Width - snakePieceSize;
                }
                if (direction == Direction.South)
                {
                    nextPosition.Y = 0;
                }
                if (direction == Direction.East)
                {
                    nextPosition.X = (background.getTexturePosition(DrawManager.ImagePosition.TopLeft) - background.Position).X;
                }
                if (direction == Direction.North)
                {
                    nextPosition.Y = background.Image.Height - snakePieceSize;
                }
            }

            //try to move the snake or destroy it
            if (!WillBeDestroyed(nextPosition))
            {
                if (eggPosition.Distance(nextPosition) < 25)
                {
                    snakePositions.Add(snakePositions[snakePositions.Count() - 1]);
                    eggPosition = GetNewEggPosition();

                    DrawManager.activeTextures.RemoveAll(new Predicate <Texture>(a => a.DisplayName == "Egg"));
                    DrawManager.CreateTexture("SnakePiece", "Egg", background.Position + eggPosition, DrawManager.ImagePosition.TopLeft);
                }

                //ends at 1 so it skips the first snake piece to override later
                for (int i = snakePositions.Count() - 1; i > 0; i--)
                {
                    snakePositions[i] = snakePositions[i - 1];
                }
                snakePositions[0] = nextPosition;

                //remove all active snakes
                DrawManager.activeTextures.RemoveAll(new Predicate <Texture>(a => a.DisplayName == "Snake Piece"));

                //draw the new ones
                foreach (Vector2 pos in snakePositions)
                {
                    DrawManager.CreateTexture("SnakePiece", "Snake Piece",
                                              background.Position + pos, DrawManager.ImagePosition.TopLeft);
                }
            }
            else
            {
                Chat.Print("You lose! Your snake was " + snakePositions.Count() + " in length with a speed setting of " + MenuHandler.GetSliderValue(MenuHandler.SnakeMenu, "Game Speed"));
                DrawManager.MenuState = DrawManager.HUDState.MainMenu;
            }
        }