Ejemplo n.º 1
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
            //Etat initial de la souris
            mouseState = Mouse.GetState();

            this.Window.Title   = "XNArkanoid";
            this.IsMouseVisible = true;

            this.hauteurEcran = this.graphics.PreferredBackBufferHeight;
            this.largeurEcran = this.graphics.PreferredBackBufferWidth;
            this.listeTexture = new List <Texture2D>();
            this.listeFond    = new List <Texture2D>();
            this.r            = new Random();

            this.menu  = new Menu(this.largeurEcran, this.hauteurEcran);
            this.ecran = listeEcran.menu;

            base.Initialize();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }
            this.oldMouseState = this.mouseState;
            this.mouseState    = Mouse.GetState();
            // TODO: Add your update logic here
            switch (ecran)
            {
            case listeEcran.menu:
                this.IsMouseVisible = true;
                if (this.oldMouseState.LeftButton == ButtonState.Pressed && this.mouseState.LeftButton == ButtonState.Released)
                {
                    typeBtn btnClick = this.menu.getBtnClick(Mouse.GetState());
                    switch (btnClick)
                    {
                    case typeBtn.btnJouer:
                        this.level = new Level(1, this.largeurEcran, this.hauteurEcran, this.listeTexture);
                        this.ecran = listeEcran.level;
                        this.fond  = r.Next(0, this.listeFond.Count);
                        break;

                    case typeBtn.btnExit:
                        this.Exit();
                        break;

                    default:
                        break;
                    }
                }
                break;

            case listeEcran.level:
                int deplacement = this.oldMouseState.X - this.mouseState.X;
                if (this.oldMouseState.LeftButton == ButtonState.Pressed && this.mouseState.LeftButton == ButtonState.Released)
                {
                    if (this.oldMouseState.X > 0 && this.oldMouseState.X < this.largeurEcran && this.oldMouseState.Y > 0 && this.oldMouseState.Y < this.hauteurEcran)
                    {
                        this.level.getBall().setIsMoving(true);
                    }
                }
                int finLevel = this.level.Update(deplacement);

                if (finLevel == 0)
                {
                    this.ecran = listeEcran.niveausuivant;
                }
                else if (finLevel == -1)
                {
                    this.ecran = listeEcran.gameover;
                }

                break;

            case listeEcran.gameover:
                if (this.oldMouseState.LeftButton == ButtonState.Pressed && this.mouseState.LeftButton == ButtonState.Released)
                {
                    this.ecran = listeEcran.menu;
                    this.fond  = r.Next(0, this.listeFond.Count);
                }
                break;

            case listeEcran.niveausuivant:
                if (this.oldMouseState.LeftButton == ButtonState.Pressed && this.mouseState.LeftButton == ButtonState.Released)
                {
                    int oldScore = this.level.getScore();
                    int levelnb  = this.level.getLevelId() + 1;
                    this.level = new Level(levelnb, this.largeurEcran, this.hauteurEcran, this.listeTexture);
                    this.level.setScore(oldScore);
                    this.ecran = listeEcran.level;
                    this.fond  = r.Next(0, this.listeFond.Count);
                }
                break;

            default:
                this.Exit();
                break;
            }
            base.Update(gameTime);
        }