/**
   * Ce qui charge les natives
   *
   * @param c une classe
   */
  private static void loadNatives(Class c) {
    final File jarFile = new File(c.getProtectionDomain().getCodeSource().getLocation().getPath());
    final String path = "res/native/";

    if (jarFile.isFile()) {
      try {
        // Run with JAR file
        final JarFile jar = new JarFile(jarFile);

        final Enumeration<JarEntry> entries = jar.entries(); // gives ALL entries in jar
        final String nativeFolderPath = jarFile.getParent() + "/native/";
        final File nativeFolder = new File(nativeFolderPath);
        nativeFolder.delete();
        nativeFolder.mkdir();

        while (entries.hasMoreElements()) {
          final String name = entries.nextElement().getName();

          if (name.startsWith(path)) { // filter according to the path
            Object temp = null;

            InputStream is = c.getResourceAsStream("/" + name);
            String nativeName = name.replace(path, "");
            File nativePath = new File(nativeFolderPath + nativeName);
            if (!nativeName.isEmpty()) {
              System.out.println("Extracting: " + nativeName);
              OutputStream os = null;
              try {
                os = new FileOutputStream(nativePath);
                byte[] buffer = new byte[1024];
                int length;
                while ((length = is.read(buffer)) > 0) {
                  os.write(buffer, 0, length);
                }
              } finally {
                is.close();
                os.close();
              }
            }
          }
        }
        jar.close();

        System.setProperty("org.lwjgl.librarypath", nativeFolderPath);
      } catch (IOException ex) {
        Logger.getLogger(c.getName()).log(Level.SEVERE, null, ex);
      }
    } else {
      try {
        System.setProperty(
            "org.lwjgl.librarypath", new File(c.getResource("/" + path).toURI()).getAbsolutePath());
      } catch (URISyntaxException ex) {
        Logger.getLogger(c.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }
Exemple #2
0
 public void keyPressed(int key, char c) {
   if (key == Input.KEY_DOWN) {
     for (int i = 0; i < 4; ++i) {
       if (hovering[i]) {
         hovering[i] = false;
         hovering[i + 1] = true;
         break;
       }
     }
     hovering[0] = true;
   } else if (key == Input.KEY_UP) {
     for (int i = 0; i < 4; ++i) {
       if (hovering[i]) {
         hovering[i] = false;
         hovering[i - 1] = true;
         break;
       }
     }
     hovering[0] = true;
   } else if (key == Input.KEY_ENTER) {
     if (hovering[0]) Demigods.enterMenuState(Demigods.PLAYER_SELECT_SCREEN);
     else if (hovering[1]) return; // No settings menu yet
     else if (hovering[2]) System.exit(0);
   }
 }
Exemple #3
0
 public void mouseReleased(int button, int x, int y) {
   if (button == 0) {
     if (x > 455 && x < 600 && y > 260 && y < 300)
       Demigods.enterMenuState(Demigods.PLAYER_SELECT_SCREEN);
     else if (x > 380 && x < 675 && y > 320 && y < 360) return; // No Settings menu yet
     else if (x > 455 && x < 600 && y > 380 && y < 420) System.exit(0);
   }
 }
Exemple #4
0
 /** @see org.newdawn.slick.BasicGame#keyPressed(int, char) */
 public void keyPressed(int key, char c) {
   if (key == Input.KEY_ESCAPE) {
     System.exit(0);
   }
   if (key == Input.KEY_F1) {
     if (app != null) {
       try {
         app.setDisplayMode(600, 600, false);
         app.reinit();
       } catch (Exception e) {
         Log.error(e);
       }
     }
   }
 }