Ejemplo n.º 1
0
        public GameState Update(RenderWindow win, float deltaTime)
        {
            int index = -1;

            lastScreen.Update(deltaTime);
            nextScreen.Update(deltaTime);
            foreach (LevelSelectButton l in mainButtonList)
            {
                l.Update(deltaTime, win, currentScreenPosition);
            }
            SetCurrentLevelInfo();
            levelInfo.Update(deltaTime, currentScreenPosition);
            leftButton.Update(deltaTime, win, currentScreenPosition);
            rightButton.Update(deltaTime, win, currentScreenPosition);
            if (stopwatch.ElapsedMilliseconds > 500)
            {
                if (Keyboard.IsKeyPressed(Keyboard.Key.Escape))
                {
                    stars.lastSelectedLevel = currentLevel;
                    stars.saveManageStars(profiles.getActiveProfileName());
                    return(GameState.MainMenu);
                }
                if (sliding)
                {
                    SlideMap(deltaTime);
                    return(GameState.LoadLevelState);
                }
                bool soundactiv = false;
                if (KeyboardInputManager.Downward(Keyboard.Key.Up) || KeyboardInputManager.Downward(Keyboard.Key.Down))
                {
                    int bottomLength = 1;
                    if (KeyboardInputManager.Downward(Keyboard.Key.Up) && currentScreenPosition.Y != 0)
                    {
                        soundactiv = true;
                        currentScreenPosition.Y = 0;
                        currentScreenPosition.X = GetPositionOnCurrentLevelScreen();
                    }
                    if (KeyboardInputManager.Downward(Keyboard.Key.Down) && currentScreenPosition.Y != 1)
                    {
                        soundactiv = true;
                        currentScreenPosition.Y = 1;
                        float help = (float)currentScreenPosition.X * (float)bottomLength / (float)(mainButtonList.Count - 1);
                        currentScreenPosition.X = (int)Math.Round(help);
                    }
                }

                if ((KeyboardInputManager.Downward(Keyboard.Key.Left) || KeyboardInputManager.Downward(Keyboard.Key.Right)) & currentScreenPosition.Y == 1)
                {
                    int bottomLength = 1;
                    if (KeyboardInputManager.Downward(Keyboard.Key.Right) && currentScreenPosition.X < bottomLength)
                    {
                        soundactiv = true;
                        currentScreenPosition.X += 1;
                    }
                    if (KeyboardInputManager.Downward(Keyboard.Key.Left) && currentScreenPosition.X > 0)
                    {
                        soundactiv = true;
                        currentScreenPosition.X -= 1;
                    }
                }
                if ((KeyboardInputManager.Downward(Keyboard.Key.Left) || KeyboardInputManager.Downward(Keyboard.Key.Right)) && currentScreenPosition.Y == 0)
                {
                    if (KeyboardInputManager.Downward(Keyboard.Key.Left))
                    {
                        if (currentLevel > 0)
                        {
                            soundactiv = true;
                            currentLevel--;
                            currentScreenPosition.X -= 1;
                            if (currentScreenPosition.X < 0)
                            {
                                InitiateSlide(false);
                                currentScreenPosition.X = GetPositionOnCurrentLevelScreen();
                            }
                        }
                    }
                    else
                    {
                        if (stars.levelIsUnlocked(currentLevel + 1))
                        {
                            soundactiv = true;
                            currentLevel++;
                            currentScreenPosition.X = GetPositionOnCurrentLevelScreen();
                            if (GetPositionOnCurrentLevelScreen() == 0)
                            {
                                InitiateSlide(true);
                            }
                        }
                    }
                    if (soundactiv)
                    {
                        MusicManager.PlaySound(AssetManager.SoundName.MenueClick);
                    }
                    else if (KeyboardInputManager.Downward(Keyboard.Key.Up) || KeyboardInputManager.Downward(Keyboard.Key.Down) || KeyboardInputManager.Downward(Keyboard.Key.Right) || KeyboardInputManager.Downward(Keyboard.Key.Left))
                    {
                        MusicManager.PlaySound(AssetManager.SoundName.Wall);
                    }

                    return(GameState.LoadLevelState);
                }

                if (soundactiv)
                {
                    MusicManager.PlaySound(AssetManager.SoundName.MenueClick);
                }
                else if (KeyboardInputManager.Downward(Keyboard.Key.Up) || KeyboardInputManager.Downward(Keyboard.Key.Down) || KeyboardInputManager.Downward(Keyboard.Key.Right) || KeyboardInputManager.Downward(Keyboard.Key.Left))
                {
                    MusicManager.PlaySound(AssetManager.SoundName.Wall);
                }



                if (KeyboardInputManager.Downward(Keyboard.Key.Return) && currentScreenPosition.Y == 0)
                {
                    return(StartLevelIfUnlocked());
                }
                if (KeyboardInputManager.Downward(Keyboard.Key.Return) && currentScreenPosition.Y == 1) //Wurde die LinkeMaustaste gedrückt?
                {
                    switch (currentScreenPosition.X)                                                    //Bin mit der Maus über den Index: SwitchCaseWeg
                    {                                                                                   //bearbeitet das aktuelle TextFeld
                    //
                    case 0:
                        CanSlide(false);
                        return(GameState.LoadLevelState);

                    case 1:
                        CanSlide(true);
                        return(GameState.LoadLevelState);

                    default:
                        return(GameState.LoadLevelState);
                    }
                }
                else
                {
                    if (index != -1)
                    {
                        IntRect curRect = rectList[index];
                        debugRect.Position  = new Vector2f(curRect.Left, curRect.Top);
                        debugRect.Size      = new Vector2f(curRect.Width, curRect.Height);
                        debugRect.FillColor = Color.Cyan;
                    }
                }
            }
            return(GameState.LoadLevelState);
        }
Ejemplo n.º 2
0
        public GameState Update(RenderWindow win, float deltaTime)
        {
            int index = -1;

            if (stopwatch.ElapsedMilliseconds > 500)
            {
                if (Keyboard.IsKeyPressed(Keyboard.Key.Escape) && selectingLevel)
                {
                    stopwatch.Restart();
                    selectingLevel = false;
                    currentNumberInputDisplay.DisplayedString = "";
                    numberInput = "";
                    return(GameState.ChooseLevelState);
                }
                if (Keyboard.IsKeyPressed(Keyboard.Key.Escape))
                {
                    return(GameState.LoadLevelState);
                }
                for (int e = 0; e < 4; e++)
                {
                    if (IsMouseInRectangle(list[e], win))                           //Geht die Liste mit rectInt duch!
                    {
                        index = e;                                                  //Maus war auf einem -> der index wird gespeichert! (nummer des Rectint)
                        break;
                    }
                }
                if (selectingLevel)
                {
                    if (KeyboardInputManager.Downward(Keyboard.Key.Back) && numberInput != "")
                    {
                        numberInput = numberInput.Remove(numberInput.Length - 1);
                    }
                    if (KeyboardInputManager.Downward(Keyboard.Key.Return) && numberInput != "")
                    {
                        int level = int.Parse(numberInput);
                        numberInput = "";
                        ManageProfiles manageProfiles = new ManageProfiles();
                        manageProfiles = manageProfiles.loadManageProfiles();

                        ManageStars manageStars = new ManageStars();
                        // TODO: find a freakin better way to do this... f*****g hax :(
                        manageStars = manageStars.unsafelyLoadManageStars(manageProfiles.getActiveProfileName());

                        if (manageStars.levelIsUnlocked(level))
                        {
                            Logger.Instance.Write("Level " + level + " is starting...", Logger.level.Info);
                            ProfileConstants.levelToPlay = level;
                            return(GameState.StartGameAtLevel);
                        }
                        else
                        {
                            Logger.Instance.Write("Level " + level + " was not yet unlocked", Logger.level.Info);
                            currentNumberInputDisplay.DisplayedString = "Level was not yet unlocked";
                            selectingLevel = false;
                            return(GameState.ChooseLevelState);
                        }
                    }
                    List <char> charList = KeyboardInputManager.getNumberInput();
                    foreach (char c in charList)
                    {
                        numberInput += c;
                    }
                    currentNumberInputDisplay.DisplayedString = numberInput;
                }
                else
                {
                    if (Mouse.IsButtonPressed(Mouse.Button.Left))                       //Wurde die LinkeMaustaste gedrückt?
                    {
                        switch (index)                                                  //Bin mit der Maus über den Index: SwitchCaseWeg
                        {                                                               //bearbeitet das aktuelle TextFeld
                        case 0:
                            selectingLevel = true;
                            return(GameState.ChooseLevelState);

                        //Levels
                        case 1: return(GameState.LoadLevelState);    //LevelsStarten

                        //Steuerung
                        case 2: return(GameState.LoadLevelState);

                        //MainMenu
                        case 3: return(GameState.LoadLevelState);
                        }
                    }
                    else
                    {
                        if (index != -1)
                        {
                            textlist[index].Color = Color.Blue;
                        }
                    }
                }
            }

            return(GameState.ChooseLevelState);
        }