// Initializor=============================================
        public override void Initialize()
        {
            // Initialize the Camera
            camera = new ShakedCamera(this);
            camera.Position = new Vector3(0, 13, 17);
            camera.Target = new Vector3(0, 0, 3);

            if (!Engine.Services.ContainsService(typeof(Camera)))
                Engine.Services.AddService(typeof(Camera), (ShakedCamera)camera);

            // Initialize the keyboard
            keyboard = Engine.Services.GetService<KeyboardDevice>();

            // Initialize the sounds

            music = Engine.Content.Load<Song>("Content\\Sounds\\music1");
            MediaPlayer.Play(music);
            MediaPlayer.Volume = 0.2f;
            MediaPlayer.IsRepeating = true;

            // Inistialize tha black Texture
            black = new Entity2D(Engine.Content.Load<Texture2D>("Content\\Textures\\black"),
                    Vector2.Zero, this);

            // Initialize tha Radar
            radar = new Radar(Engine.Content.Load<Model>("Content\\Models\\Radar"), Vector3.One, this);
            radar.Visible = false;

            // Initialize the Ball
            ball = new Ball(Engine.Content.Load<Model>("Content\\Models\\GameBall"),
                            new Vector3(0f,0f,5f), this);
            ball.defaultLightingEnabled = true;

            // Initialize the Bricks List
            brickLenghtLine = 3;
            brickLenghtColumn = 10;
            totalOfBricks = brickLenghtLine * brickLenghtColumn;
            totalOfBricksLeft = totalOfBricks;
            brickMapArray=new int[brickLenghtLine, brickLenghtColumn];
            brickObjectArray = new Brick[brickLenghtLine, brickLenghtColumn];

            for (int i = 0; i < brickLenghtLine; i++)
            {
                for (int j = 0; j < brickLenghtColumn; j++)
                {
                    brickMapArray[i, j] = Util.random.Next(0, 3);
                }
            }

            // Initialize the Released Object array
            ReleasedObjectArray = new ReleasedObject[totalOfBricks];
            for (int i = 0; i < totalOfBricks; i++)
                ReleasedObjectArray[i] = null;

            ReleasedObjectArrayIndex = 0;

            // initialize the ObjectArray of bricks
            for (int i = 0; i < brickLenghtLine; i++)
            {
                for (int j = 0; j < brickLenghtColumn; j++)
                {
                    Brick brick;
                    Model model;
                    // Type of Brick
                    Vector3 brikPos = new Vector3(-7f + j * 1.5f, 0f, -4f + i*1.5f);
                    switch (brickMapArray[i,j])
                    {
                        case 0:
                            // Type Normal
                            model = Engine.Content.Load<Model>("Content\\Models\\GameBrick1");
                            brick = new Brick(model, brikPos, this);
                            brick.BrickReleaseType = BrickReleaseType.Normal;
                            brickObjectArray[i, j] = brick;

                            model = Engine.Content.Load<Model>("Content\\Models\\ReleasedNormObject");
                            ReleasedObjectArray[brickLenghtColumn * i + j] = new NormalObject(model, brikPos, this);
                            break;
                        case 1:
                            // Type Score
                            model = Engine.Content.Load<Model>("Content\\Models\\GameBrick1");
                            brick = new Brick(model, brikPos, this);
                            brick.BrickReleaseType = BrickReleaseType.Money;
                            brickObjectArray[i, j] = brick;

                            model = Engine.Content.Load<Model>("Content\\Models\\ReleasedMoneyObject");
                            ReleasedObjectArray[brickLenghtColumn * i + j] = new MoneyObject(model, brikPos, this);
                            break;
                        case 2:
                            // Type Life
                            model = Engine.Content.Load<Model>("Content\\Models\\GameBrick1");
                            brick = new Brick(model, brikPos, this);
                            brick.BrickReleaseType = BrickReleaseType.Danger;
                            brickObjectArray[i, j] = brick;

                            model = Engine.Content.Load<Model>("Content\\Models\\ReleasedDangerObject");
                            ReleasedObjectArray[brickLenghtColumn * i + j] = new DangerObject(model, brikPos, this);
                            break;

                        default:
                            // Type Normal
                            model = Engine.Content.Load<Model>("Content\\Models\\GameBrick1");
                            brick = new Brick(model, brikPos, this);
                            brick.BrickReleaseType = BrickReleaseType.Normal;
                            brickObjectArray[i, j] = brick;

                            model = Engine.Content.Load<Model>("Content\\Models\\ReleasedNormObject");
                            ReleasedObjectArray[brickLenghtColumn * i + j] = new NormalObject(model, brikPos, this);
                            break;
                    }

                    // Update the ReleasedObjectArrayIndex
                    if (ReleasedObjectArrayIndex >= totalOfBricks)
                        ReleasedObjectArrayIndex = 0;
                    else
                        ReleasedObjectArrayIndex++;
                }
            }

            // Initialize the Paddle
            paddle = new Paddle(Engine.Content.Load<Model>("Content\\Models\\GamePaddle"), Vector3.Zero, this);
            paddle.defaultLightingEnabled = true;

            // Iniotialize the spiralRod
            paddleSupport = new PaddleSupport(Engine.Content.Load<Model>("Content\\Models\\SpiralRod"),
                                     new Vector3(0f, 0.6f, 9f), this);
            //paddleSupport.Rotation = Matrix.CreateRotationZ(MathHelper.ToRadians(90f));
            paddleSupport.defaultLightingEnabled = true;

            // Initialize the Blur
            blur = new GaussianBlur(Engine.Viewport.Width, Engine.Viewport.Height, this);
            blur.Visible = false;

            // Initialize HUD
            hud = new Hud(this);

            // Initialize the gameMap
            gameMap = new Entity3D(Engine.Content.Load<Model>("Content\\Models\\GameMap"), Vector3.Zero, this);
            gameMap.defaultLightingEnabled = true;

            base.Initialize();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            bricks = new Brick[bricksWidth, bricksHeight];
            for (int i = 0; i < bricksHeight; i++)
            {
                for (int j = 0; j < bricksWidth; j++)
                {
                    bricks[j, i] = new Brick(Content, j * (105), i * 25);
                }
            }

            ball = new Ball(Content, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            paddle = new Paddle(Content, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
            // TODO: use this.Content to load your game content here
        }
Ejemplo n.º 3
0
        public void OnStart()
        {
            //display player hp's
            hpLabelp1.Text = "HP: " + p1HP.ToString();
            hpLabelp2.Text = "HP: " + p2HP.ToString();

            //initializes ticks since hit counter
            ticksSinceHit = 10;

            //set all button presses to false.
            leftArrowDown = downArrowDown = rightArrowDown = upArrowDown = false;

            //set player 2 button presses to false
            aKeyDown = sKeyDown = dKeyDown = wKeyDown = false;

            // setup starting paddle values and create paddle object
            int paddleWidth  = 80;
            int paddleHeight = 20;
            int paddleX      = ((this.Width / 2) - (paddleWidth / 2));
            int paddleY      = (this.Height - paddleHeight) - 60;
            int paddle2X     = ((this.Width / 2) - (paddleWidth / 2));
            int paddle2Y     = 60;
            int paddleSpeed  = 8;

            //add both paddles
            paddle  = new Paddle(paddleX, paddleY, paddleWidth, paddleHeight, paddleSpeed, Color.White);
            paddle2 = new Paddle(paddle2X, paddle2Y, paddleWidth, paddleHeight, paddleSpeed, Color.White);

            // setup starting ball values
            int ballX = ((this.Width / 2) - 10);
            int ballY = (this.Height - paddle.height) - 80;

            // Creates a new ball
            int xSpeed   = 6;
            int ySpeed   = 6;
            int ballSize = 20;

            ball = new Ball(ballX, ballY, xSpeed, ySpeed, ballSize);

            // Creates blocks for generic level
            blocks1p.Clear();
            blocks2p.Clear();
            int x = 10;



            //blocks in this mode will always be the same
            while (blocks1p.Count < 12)
            {
                x += 57;
                Block b = new Block(x, 10, 1, Color.White);
                blocks1p.Add(b);
            }

            x = 10;

            //blocks in this mode will always be the same
            while (blocks2p.Count < 12)
            {
                x += 57;
                Block b = new Block(x, 500, 1, Color.White);
                blocks2p.Add(b);
            }

            // start the game engine loop
            gameTimer.Enabled = true;
        }