Beispiel #1
0
 private void init(State state) {
   if (state == State.GAME) { // If the state is ingame...
     level = Level.createLevel(0); // Load the spawn level (level 0)
     TileCoordinate playerSpawn =
         new TileCoordinate(
             15,
             60); // Create player coodinates. This class creates coordinates from pixels and
                  // converts it to tile coordinates (16 pixels -> 1 tile)
     String playerName = ""; // Initiate the players name
     if (FileHandler.fileExists(FileHandler.localUserFile))
       playerName =
           FileHandler
               .getPlayerName(); // If the player already exists, set the players name to the
                                 // stored name
     else
       playerName =
           sc
               .getPlayerName(); // Otherwise retrieve the name from the start screen that the user
                                 // has typed into the name box
     player =
         new Player(
             playerName,
             playerSpawn.x(),
             playerSpawn.y(),
             key); // Create a new player. Pass in the name, spawn location (in tile coordinates),
                   // and the keyboard class.
     changeLevel(
         Level
             .activeLevel); // Set the level to the current level (0, as we set that in the
                            // beginning)
     FileHandler.save(player); // Save everything
     initPause = false; // Set pause to false, just in case it is true
     c.clearTextArea(); // Clear the console
     System.out.println(
         "Controls: \n W/up -> Player up \n A/left -> Player left \n S/down -> Player down \n D/right -> Player right \n "
             + "Q -> Inventory \n Shift -> Sprint \n HOME -> home level \n M -> Map \n numbers 1-6 -> Weapons"); // Output the controls so the user can see what to do
   } else if (state == State.START) { // If the state is the start screen...
     sc = new StartScreen(); // Initiate the start screen
     uiManager.addPanel(
         sc); // Add the startscreen to the UI manager, which will render and update it
   } else if (state == State.PAUSE) { // If the state is in pause...
     pause = new Pause(); // Instantiate a new pause menu
     uiManager.addPanel(
         pause); // Add the pause menu to the UI manager, ready for rendering and updating
     initPause = true; // Tell the game we have created a pause menu (prevent more than 1 opening)
     paused = true; // Tell the game we are paused
   }
   STATE =
       State
           .WAITING; // Once the correct state is set up, set the state wo WAITING, which tells the
                     // game we are waiting for the state to change.
 }