예제 #1
0
파일: Score.cs 프로젝트: igorkiss/MonoSnake
 public Score()
 {
     font = Global.Content.Load<SpriteFont>("gamefont");
     gameArea = new GameArea();
     ScoreCount = 0;
     Position = new Vector2(gameArea.RightBound, 0);
     gameArea = null;
 }
예제 #2
0
파일: Apple.cs 프로젝트: igorkiss/MonoSnake
 public void Update(SnakeSection[] snake, GameArea gameArea)
 {
     if (!IsAlive)
     {
         IsAlive = true;
         ok = false;
         while (!ok)
         {
             int x = rnd.Next(gameArea.LeftBound / Texture.Width, gameArea.RightBound / Texture.Width) * Texture.Width;
             int y = rnd.Next(0, Global.GraphicsManager.PreferredBackBufferHeight / Texture.Height) * Texture.Height;
             base.Rectangle = new Rectangle(x, y, Texture.Width, Texture.Height);
             ok = true;
             for (int i = 0; i < snake.Length; i++)
             {
                 if (snake[i].Rectangle.Intersects(base.Rectangle)) ok = false;
             }
         }
         IsAlive = true;
     }
 }
예제 #3
0
파일: Snake.cs 프로젝트: igorkiss/MonoSnake
        private void Collision(GameTime gameTime, GameArea gameArea, Apple apple, ScreenManager screenManager)
        {
            if(snakeSectionArray[0].Rectangle.X < gameArea.LeftBound
                || snakeSectionArray[0].Rectangle.Y < 0
                || snakeSectionArray[0].Rectangle.X + snakeSectionArray[0].Rectangle.Width> gameArea.RightBound
                || snakeSectionArray[0].Rectangle.Y + snakeSectionArray[0].Rectangle.Height > Global.GraphicsManager.PreferredBackBufferHeight)
            {
                GameOver(screenManager);
            }

            for (int i = 1; i < snakeSectionArray.Length; i++)
            {
                if(snakeSectionArray[0].Rectangle.Intersects(snakeSectionArray[i].Rectangle))
                {
                    GameOver(screenManager);
                }
            }
            if(snakeSectionArray[0].Rectangle.Intersects(apple.Rectangle))
            {
                score.IncreaseScore();
                apple.IsAlive = false;
                SnakeSection[] buffer = snakeSectionArray;
                snakeSize++;
                snakeSectionArray = new SnakeSection[snakeSize];

                for (int i = 0; i < buffer.Length; i++)
                {
                    snakeSectionArray[i] = buffer[i];
                }
                if(snakeSectionArray[snakeSectionArray.Length - 2].Rectangle.X - snakeSectionArray[snakeSectionArray.Length - 3].Rectangle.X == 0)
                {
                    snakeSectionArray[snakeSectionArray.Length - 1] = new SnakeSection(pathToTexture, new Rectangle(snakeSectionArray[snakeSectionArray.Length - 2].Rectangle.X,
                        snakeSectionArray[snakeSectionArray.Length - 2].Rectangle.Y + Texture.Height, Texture.Width, Texture.Height));
                }
                else if (snakeSectionArray[snakeSectionArray.Length - 2].Rectangle.Y - snakeSectionArray[snakeSectionArray.Length - 3].Rectangle.Y == 0)
                {
                    snakeSectionArray[snakeSectionArray.Length - 1] = new SnakeSection(pathToTexture, new Rectangle(snakeSectionArray[snakeSectionArray.Length - 2].Rectangle.X,
                        snakeSectionArray[snakeSectionArray.Length - 2].Rectangle.Y + Texture.Height, Texture.Width, Texture.Height));
                }
            }
        }
예제 #4
0
파일: Snake.cs 프로젝트: igorkiss/MonoSnake
 public void Update(GameTime gameTime, ScreenPad screenPad, GameArea gameArea, Apple apple, ScreenManager screenManager)
 {
     Movement(gameTime, screenPad);
     Collision(gameTime, gameArea, apple, screenManager);
 }
예제 #5
0
        private void LoadContent()
        {
            gameArea = new GameArea();

            if (Global.TextureWidth == 20)
            {
                snake = new Snake("Snake/SmallSize/middle");
                apple = new Apple("Snake/SmallSize/apple");
            }
            else
            {
                snake = new Snake("Snake/MediumSize/middle");
                apple = new Apple("Snake/MediumSize/apple");
            }
            screenPad = new ScreenPad(Global.Content.Load<Texture2D>("Controls/upButton"),
                Global.Content.Load<Texture2D>("Controls/downButton"),
                Global.Content.Load<Texture2D>("Controls/leftButton"),
                Global.Content.Load<Texture2D>("Controls/rightButton"), false);
        }