Example #1
0
 private void DrawLevel()
 {
     foreach (Block b in blockList)
     {
         b.Draw(spriteBatch);
     }
     floor.Draw(spriteBatch);
     spriteBatch.Draw(cannonTexture, new Rectangle((int)cannonPosition.X, (int)cannonPosition.Y, cannonTexture.Width, cannonTexture.Height), new Rectangle(0, 0, cannonTexture.Width, cannonTexture.Height), Color.White, -1 * cannonAngle, new Vector2(20, 35), SpriteEffects.None, .9f);
     spriteBatch.Draw(powerBar, new Vector2(160, 370), new Rectangle(0, (powerBar.Height / 8) * (powerInt - 1), powerBar.Width, powerBar.Height / 8), Color.White);
     for (int i = 0; i < ballList.Count; i++)
     {
         spriteBatch.Draw(ballTexture, new Rectangle(25, LevelData.screenHeight - (i * 50 + 100), 30, 30), LevelData.GetColor(ballList.ElementAt(i)));
     }
     spriteBatch.DrawString(regFont, "[esc]", new Vector2(20, 10), Color.Black);
 }
Example #2
0
        private void UpdateLevel(GameTime gameTime)
        {
            world.Step((float)gameTime.ElapsedGameTime.TotalSeconds);

            //Check if level is won.
            bool won = true;

            foreach (Block b in blockList)
            {
                if (b.colorNum > 0)
                {
                    won = false;
                }
            }
            if (won)
            {
                gameState = GameState.LevelWon;
                return;
            }

            if (powerUp)
            {
                cannonPower += 5;
                if (cannonPower == 375)
                {
                    powerUp = false;
                }
            }
            else
            {
                cannonPower -= 5;
                if (cannonPower == 25)
                {
                    powerUp = true;
                }
            }
            powerInt = LevelData.GetPowerInt(cannonPower);

            if (keyboardState.IsKeyDown(Keys.Space) && oldKeyboardState.IsKeyUp(Keys.Space) || keyboardState.IsKeyDown(Keys.Enter) && oldKeyboardState.IsKeyUp(Keys.Enter))
            {
                //Check if level is lost.
                bool lost = false;
                if (ballList.Count == 0)
                {
                    lost = true;
                }
                if (lost)
                {
                    gameState = GameState.LevelLose;
                    return;
                }

                soundCannon.Play();
                Block ball = new Block(world, ballTexture, new Vector2(50, 0), new Vector2(cannonPosition.X, cannonPosition.Y), ballList.ElementAt(0), false);
                ball.body.ApplyForce(new Vector2(cannonPower * (float)Math.Cos(cannonAngle), -1 * cannonPower * (float)Math.Sin(cannonAngle)));
                blockList.Add(ball);
                ballList.RemoveAt(0);
            }

            if (keyboardState.IsKeyDown(Keys.Up) && cannonAngle < Math.PI / 2)
            {
                cannonAngle += (float)Math.PI / 300;
            }
            if (keyboardState.IsKeyDown(Keys.Down) && cannonAngle > 0)
            {
                cannonAngle -= (float)Math.PI / 300;
            }

            if (keyboardState.IsKeyDown(Keys.R) && oldKeyboardState.IsKeyUp(Keys.R))
            {
                LoadLevel();
            }

            if (keyboardState.IsKeyDown(Keys.Escape) && oldKeyboardState.IsKeyUp(Keys.Escape))
            {
                gameState = GameState.LevelSelect;
            }
        }