Example #1
0
 public override void update(float delta)
 {
     if (Keyboard.GetState().IsKeyDown(Keys.Escape))
     {
         OTRGame.getInstance().setScreen(new MenuScreen());
     }
 }
Example #2
0
 public SpriteButton(int column)
 {
     texture = OTRGame.getInstance().Content.Load <Texture2D>("button");
     //X -> 4.5 = Taille entre chaque colonne. 9 = Espace à gauche.
     position.X += (int)(texture.Width * column + 4.5 * column + 9 + GameMap.offset);
     this.column = column;
 }
Example #3
0
        public override void initialize()
        {
            float width  = OTRGame.getInstance().getWidth();
            float height = OTRGame.getInstance().getHeight();

            jouerBouton = new SpriteMenuItem("jouer");
            float heightMenu = jouerBouton.texture.Height * 4 + 20 * 3;

            jouerBouton.position.X = width / 2 - jouerBouton.texture.Width / 2;
            jouerBouton.position.Y = height / 2 - heightMenu / 2;
            jouerBouton.alpha      = 0;

            scoresBouton            = new SpriteMenuItem("scores");
            scoresBouton.position.X = width / 2 - scoresBouton.texture.Width / 2;
            scoresBouton.position.Y = scoresBouton.texture.Height + jouerBouton.position.Y + 20;
            scoresBouton.alpha      = 0;

            creditsBouton            = new SpriteMenuItem("credits");
            creditsBouton.position.X = width / 2 - creditsBouton.texture.Width / 2;
            creditsBouton.position.Y = creditsBouton.texture.Height + scoresBouton.position.Y + 20;
            creditsBouton.alpha      = 0;

            quitterBouton            = new SpriteMenuItem("quitter");
            quitterBouton.position.X = width / 2 - quitterBouton.texture.Width / 2;
            quitterBouton.position.Y = quitterBouton.texture.Height + creditsBouton.position.Y + 20;
            quitterBouton.alpha      = 0;

            lastMouseState    = Mouse.GetState();
            lastKeyboardState = Keyboard.GetState();
        }
Example #4
0
        public override void update(float delta)
        {
            if (jouerBouton.contains(Mouse.GetState().X, Mouse.GetState().Y) && Mouse.GetState().LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released)
            {
                OTRGame.getInstance().setScreen(new GameScreen());
            }

            if (scoresBouton.contains(Mouse.GetState().X, Mouse.GetState().Y) && Mouse.GetState().LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released)
            {
                OTRGame.getInstance().setScreen(new ScoresScreen());
            }

            if (creditsBouton.contains(Mouse.GetState().X, Mouse.GetState().Y) && Mouse.GetState().LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released)
            {
                OTRGame.getInstance().setScreen(new CreditsScreen());
            }

            if (quitterBouton.contains(Mouse.GetState().X, Mouse.GetState().Y) && Mouse.GetState().LeftButton == ButtonState.Pressed && lastMouseState.LeftButton == ButtonState.Released)
            {
                OTRGame.getInstance().Exit();
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Escape) && lastKeyboardState.IsKeyUp(Keys.Escape))
            {
                OTRGame.getInstance().Exit();
            }

            jouerBouton.alpha   += delta * timeAlpha;
            scoresBouton.alpha  += delta * timeAlpha;
            creditsBouton.alpha += delta * timeAlpha;
            quitterBouton.alpha += delta * timeAlpha;

            lastMouseState = Mouse.GetState();
        }
Example #5
0
 public override void initialize()
 {
     gameMap = new GameMap();
     music   = OTRGame.getInstance().Content.Load <Song>("Tobu - Higher");
     MediaPlayer.IsRepeating = true;
     MediaPlayer.Play(music);
     SpriteButton.resetSpeed();
 }
Example #6
0
        public override void render(SpriteBatch batch)
        {
            //Couleur de fond
            OTRGame.getInstance().GraphicsDevice.Clear(new Color(0, 0, 0));

            batch.Begin();


            batch.End();
        }
Example #7
0
        public override void initialize()
        {
            accueil            = new Sprite("accueil");
            pressEnter         = new Sprite("pressEnter");
            accueil.position.X = OTRGame.getInstance().getWidth() / 2 - accueil.texture.Width / 2;
            accueil.position.Y = OTRGame.getInstance().getHeight() / 2 - accueil.texture.Height / 2;
            accueil.scale      = 1.5f;

            pressEnter.position.X = OTRGame.getInstance().getWidth() / 2 - pressEnter.texture.Width / 2;
            pressEnter.position.Y = accueil.position.Y + accueil.texture.Height + 160;
        }
Example #8
0
        public override void update(float delta)
        {
            temps += delta;
            if (temps > tempsMax)
            {
                tempsMax = rand.Next(300) / 1000f;
                temps    = 0;
                //Passage du true au false en fonction de l'état
                grossir = !grossir;
            }

            if (grossir)
            {
                loose.scale += 0.2f * delta;
            }
            else
            {
                loose.scale -= 0.2f * delta;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Enter))
            {
                OTRGame.getInstance().setScreen(new GameScreen());
            }

            else if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                OTRGame.getInstance().setScreen(new MenuScreen());
            }

            else if (Keyboard.GetState().IsKeyDown(Keys.Back) && lastKeyboardState.IsKeyUp(Keys.Back))
            {
                if (playerName.Length > 0)
                {
                    playerName = playerName.Substring(0, playerName.Length - 1);
                }
            }

            for (int i = 0; i < Keyboard.GetState().GetPressedKeys().Length; i++)
            {
                Keys key = Keyboard.GetState().GetPressedKeys()[i];
                if (lastKeyboardState.IsKeyUp(key) && !isControlKey(key))
                {
                    if (playerName.Length < playerNameLengthMax)
                    {
                        playerName += key.ToString();
                    }
                }
            }


            lastKeyboardState = Keyboard.GetState();
        }
Example #9
0
        public SpriteLight(int column)
        {
            texture = OTRGame.getInstance().Content.Load <Texture2D>("light");

            //On change la position des "lumieres" quand on clique sur une touche
            //X -> 4.5 = Taille entre chaque colonnes. 9 = Espace à gauche.
            //Y -> 156 = Distance avec la fin de la barre de la map
            position.X += (int)(texture.Width * column + 4.5 * column + 9 + GameMap.offset);
            position.Y  = OTRGame.getInstance().getHeight() - 156 - texture.Height;

            //On enregistre les différentes touches et on prend celle qui correspond à notre colonne
            Keys[] inputs = new Keys[] { Keys.D, Keys.F, Keys.J, Keys.K };
            keyInput = inputs[column];
        }
Example #10
0
        public override void render(SpriteBatch batch)
        {
            //Couleur de fond
            OTRGame.getInstance().GraphicsDevice.Clear(new Color(0, 0, 0));

            batch.Begin();

            jouerBouton.render(batch);
            scoresBouton.render(batch);
            creditsBouton.render(batch);
            quitterBouton.render(batch);

            batch.End();
        }
Example #11
0
        public override void render(SpriteBatch batch)
        {
            //Couleur de fond
            OTRGame.getInstance().GraphicsDevice.Clear(new Color(0, 0, 0));

            batch.Begin();

            loose.render(batch);
            tryAgain.render(batch);
            Vector2 playerNameSize = font.MeasureString(playerName);

            batch.DrawString(font, playerName, new Vector2(OTRGame.getInstance().getWidth() / 2 - playerNameSize.X / 2, tryAgain.position.Y + tryAgain.texture.Height + 50), Color.White);

            batch.End();
        }
Example #12
0
        public override void initialize()
        {
            loose            = new Sprite("perdu");
            tryAgain         = new Sprite("tryAgain");
            loose.position.X = OTRGame.getInstance().getWidth() / 2 - loose.texture.Width / 2;
            loose.position.Y = OTRGame.getInstance().getHeight() / 2 - loose.texture.Height / 2;
            loose.scale      = 1.5f;

            tryAgain.position.X = OTRGame.getInstance().getWidth() / 2 - tryAgain.texture.Width / 2;
            tryAgain.position.Y = loose.position.Y + tryAgain.texture.Height + 160;

            font = OTRGame.getInstance().Content.Load <SpriteFont>("font");

            lastKeyboardState = Keyboard.GetState();
        }
Example #13
0
        public override void update(float delta)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Enter))
            {
                fadeOutRequested = true;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                OTRGame.getInstance().Exit();
            }

            if (Keyboard.GetState().IsKeyUp(Keys.Enter))
            {
                temps += delta;
                if (temps > tempsMax)
                {
                    tempsMax = rand.Next(300) / 1000f;
                    temps    = 0;
                    //Passage du true au false en fonction de l'état
                    grossir = !grossir;
                }

                if (grossir)
                {
                    accueil.scale += 0.2f * delta;
                }
                else
                {
                    accueil.scale -= 0.2f * delta;
                }
            }

            if (fadeOutRequested)
            {
                accueil.alpha    -= delta * timeFadeOut;
                pressEnter.alpha -= delta * timeFadeOut;
            }

            if (accueil.alpha <= 0)
            {
                OTRGame.getInstance().setScreen(new MenuScreen());
            }
        }
Example #14
0
        public GameMap() : base("map")
        {
            //On récupère l'image de fond pour la map
            OTRGame game = OTRGame.getInstance();

            offset = OTRGame.getInstance().getWidth() / 2 - texture.Width / 2;

            //On la place tout en bas de l'écran
            position.Y = (game.getHeight() - (texture.Height));
            position.X = offset;

            font = OTRGame.getInstance().Content.Load <SpriteFont>("font");

            //On crée les 4 effets en leur donnant une colonne cible
            for (int i = 0; i < 4; i++)
            {
                lightSprites.Add(new SpriteLight(i));
            }
        }
Example #15
0
        public void render(SpriteBatch batch)
        {
            Vector2 tailleScore  = font.MeasureString("Score : " + score);
            Vector2 tailleFailed = font.MeasureString("Echecs : " + fails + "/" + maxFails);

            //On dessine la map
            base.render(batch);
            //On dessine d'abord les effets pour qu'ils ne soient pas au dessus des boutons
            foreach (SpriteLight light in lightSprites)
            {
                light.render(batch);
            }

            //On dessine les boutons
            foreach (SpriteButton button in buttons)
            {
                button.render(batch);
            }

            batch.DrawString(font, "Score : " + score, new Vector2(OTRGame.getInstance().getWidth() - tailleScore.X - 50, 20), Color.White);
            batch.DrawString(font, "Echecs : " + fails + "/" + maxFails, new Vector2(OTRGame.getInstance().getWidth() - tailleFailed.X - 50, tailleScore.Y + 20 + 20), Color.White);
        }
Example #16
0
        public void update(float delta)
        {
            //On ajoute delta aux chronos
            lastSpawnTime += delta;
            lastChange    += delta;
            float timeRatio = (SpriteButton.speed / SpriteButton.baseSpeed);

            if (lastSpawnTime * timeRatio > spawnTime)
            {
                //On doit ajouter un bouton
                addButton();
                lastSpawnTime = 0;
            }

            if (lastChange * timeRatio > changeTime)
            {
                //On doit changer le temps entre chaque spawn de bouton
                //On sélectionne un nombre au hasard entre 0.30 et 0.33 secondes
                spawnTime = Math.Max((float)rand.Next(200) / 1000.0f, 0.33f);
                //On change la durée de la phase avant le prochain changement
                changeTime = (float)rand.Next(10000) / 1000.0f;
                lastChange = 0;
            }

            //On regarde si les touches sont appuyées quand le bouton est proche de la fin
            Keys[] inputs = new Keys[] { Keys.D, Keys.F, Keys.J, Keys.K };
            //Les boutons les plus proches sont ceux qui sont les premiers dans la liste
            //On vérifie les 4 premier boutons au cas où on en aurait 4 en même temps
            List <SpriteButton> premiersBoutons = new List <SpriteButton>();
            float lastY = 0;

            for (int i = 0; i < Math.Min(4, buttons.Count); i++)
            {
                if (i == 0)
                {
                    lastY = buttons[i].position.Y;
                    premiersBoutons.Add(buttons[i]);
                }

                if (buttons[i].position.Y == lastY)
                {
                    premiersBoutons.Add(buttons[i]);
                }
            }

            for (int j = 0; j < inputs.Count(); j++)
            {
                //Si la touche est appuyée à l'instant on regarde
                if (Keyboard.GetState().IsKeyDown(inputs[j]) && !lastState.IsKeyDown(inputs[j]))
                {
                    for (int i = 0; i < premiersBoutons.Count(); i++)
                    {
                        if (premiersBoutons[i].column == j)
                        {
                            float distance = OTRGame.getInstance().getHeight() - (premiersBoutons[i].position.Y + premiersBoutons[i].texture.Height + 156);
                            //On a appuyé sur la touche correspondante au bouton, on vérifie si il est proche (- de 150px)
                            if (distance < 150)
                            {
                                //Il est proche. On calcule le score que l'on obtient.
                                int scoreTouche = Math.Abs(50 * ((int)(distance % 3) + 1));
                                score += scoreTouche;

                                fails = (fails <= 0) ? 0 : fails - 1;

                                buttons.Remove(premiersBoutons[i]);
                                break;
                            }
                        }
                    }
                }
            }


            //On met à jour les boutons et on vérifie que les boutons ne descendent pas trop bas, sinon on les détruits
            for (int i = buttons.Count - 1; i >= 0; i--)
            {
                SpriteButton button = buttons[i];
                button.update(delta);

                if ((button.position.Y) > (OTRGame.getInstance().getHeight() - 156))
                {
                    buttons.Remove(button);
                    fails++;

                    if (fails >= maxFails)
                    {
                        OTRGame.getInstance().setScreen(new PerduScreen(score));
                    }
                }
            }

            //On met à jour les effets des touches
            foreach (SpriteLight light in lightSprites)
            {
                light.update(delta);
            }

            //On change la vitesse du niveau si on vient d'appuyer sur F3 (baisser vitesse) ou F4 (augmenter vitesse)
            float pallier = (50.0f);

            if (Keyboard.GetState().IsKeyDown(Keys.F3) && !lastState.IsKeyDown(Keys.F3))
            {
                if (SpriteButton.speed <= (50.0f))
                {
                    SpriteButton.speed = (50.0f);
                }
                else
                {
                    SpriteButton.speed -= pallier;
                }
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.F4) && !lastState.IsKeyDown(Keys.F4))
            {
                SpriteButton.speed += pallier;
            }

            lastState = Keyboard.GetState();
        }
Example #17
0
 public override void initialize()
 {
     font = OTRGame.getInstance().Content.Load <SpriteFont>("font");
 }
Example #18
0
 public override void initialize()
 {
     credits            = new Sprite("creditsEcran");
     credits.position.X = OTRGame.getInstance().getWidth() / 2 - credits.texture.Width / 2;
     credits.position.Y = OTRGame.getInstance().getHeight() / 2 - credits.texture.Height / 2;
 }