Exemplo n.º 1
0
 private void FoodTimeElapse(GameTime gameTime)
 {
     if (Keyboard.GetState().IsKeyDown(Keys.Space))
     {
         if (food != null && food.type == Food.Type.Grapes)
             if (gameTime.TotalGameTime.Subtract(foodTime) > new TimeSpan(0, 0, 3))
                 food = null;
     }
     else
     {
         if (food != null && food.type == Food.Type.Grapes)
             if (gameTime.TotalGameTime.Subtract(foodTime) > new TimeSpan(0, 0, 0, 12))
                 food = null;
     }
 }
Exemplo n.º 2
0
        private void Collision()
        {
            //with walls
            if (gameStage == GameStage.SinglePlayerWBorders)
                if (snake.body[0].iLine == 0 || snake.body[0].iLine == 22 || snake.body[0].iRow == 0 || snake.body[0].iRow == 39)
                {
                    sfxHit.Play(volSfx, 0f, 0f);
                    isDead();
                }

            //with cells
            for (int i = 1; i < snake.iSize; i++)
            {
                if (snake.body[0].iLine == snake.body[i].iLine && snake.body[0].iRow == snake.body[i].iRow)
                {
                    sfxHit.Play(volSfx, 0f, 0f);
                    isDead();
                }
            }

            //with food
            if (food != null)
            {
                if (snake.body[0].iRow == food.row && snake.body[0].iLine == food.line)
                {

                    snake.IncSpeed(food.speed);
                    snake.IncSize(food.size);
                    snake.IncPoints(food.points);

                    snake.Green += food.green;
                    snake.Red += food.red;
                    snake.Blue += food.blue;
                    GenerateColor();

                    sfxBite.Play(volSfx, 0f, 0f);

                    food = null;
                }
            }
        }
Exemplo n.º 3
0
        private void CreateFood(GameTime gameTime)
        {
            int chance = rnd.Next(100);
            food = new Food();

            if (snake.iPoints - snake.lastPoints >= 15)
            {
                food.size = 0;
                food.speed = 0;
                food.points = snake.iPoints;

                food.blue = 8;
                food.red = 3;
                food.green = 0;

                food.type = Food.Type.Grapes;

                snake.lastPoints = snake.iPoints;
            }
            else if (chance < 5)
            {
                food.size = 0;
                food.speed = 0;
                food.points = 1;

                food.green = 7;
                food.blue = 0;
                food.red = 0;

                food.type = Food.Type.Apple;
            }

            else if (chance < 10)
            {
                food.size = 0;
                food.speed = 30;
                food.points = 0;

                food.green = 0;
                food.blue = 12;
                food.red = 0;

                food.type = Food.Type.Blueberry;
            }

            else if (chance < 15)
            {
                food.size = -1;
                food.points = 0;
                food.speed = 0;

                food.green = 6;
                food.red = 3;
                food.blue = 0;

                food.type = Food.Type.Lemon;
            }

            else if (chance < 18)
            {
                food.size = -1;
                food.speed = 20;
                food.points = 1;

                food.green = 3;
                food.red = 3;
                food.blue = 0;

                food.type = Food.Type.Orange;
            }

            else
            {
                food.size = 1;
                food.speed = -15;
                food.points = 1;

                food.red = 1;
                food.blue = 0;
                food.green = 0;

                food.type = Food.Type.Normal;
            }

            if (gameStage == GameStage.SinglePlayerBorderless)
            {
                food.line = rnd.Next(0, 22);
                food.row = rnd.Next(0, 39);
            }
            else if (gameStage == GameStage.SinglePlayerWBorders)
            {
                food.line = rnd.Next(1, 21);
                food.row = rnd.Next(1, 38);
            }

            for (int i = 0; i < snake.iSize; i++)
            {
                if (snake.body[i].iLine == food.line && snake.body[i].iRow == food.row)
                {
                    food = null;
                    return;
                }
            }

            if (food != null && food.type == Food.Type.Grapes)
            {
                foodTime = gameTime.TotalGameTime;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            //to be changed
            gameStage = GameStage.SplashScreen;
            gameType = GameStage.SinglePlayerWBorders;
            snake = new Snake();
            food = null;
            rnd = new Random();
            lastTime = new TimeSpan(0, 0, 3);
            bClickAvailable = false;
            volSfx = 1f;
            volBg = 1f;
            scoreY = 0f;
            bMovingScore = true;
            bTongueOut = false;
            actualName = "";
            scoreTime = new TimeSpan(0, 0, 0);
            pauseTime = new TimeSpan(0, 0, 0);
            tongueTime = new TimeSpan(0, 0, 0);

            base.Initialize();
        }