예제 #1
0
  // ***************************************************************************
  // initDisplay
  // ***************************************************************************
  private static void initDisplay(boolean fullscreen) {
    DisplayMode chosenMode = null;

    try {
      DisplayMode[] modes = Display.getAvailableDisplayModes();

      for (int i = 0; i < modes.length; i++) {
        if ((modes[i].getWidth() == targetWidth) && (modes[i].getHeight() == targetHeight)) {
          chosenMode = modes[i];
          break;
        }
      }
    } catch (LWJGLException e) {
      Sys.alert("Error", "Unable to determine display modes.");
      System.exit(0);
    }

    // at this point if we have no mode there was no appropriate, let the user know
    // and give up
    if (chosenMode == null) {
      Sys.alert("Error", "Unable to find appropriate display mode.");
      System.exit(0);
    }

    try {
      Display.setDisplayMode(chosenMode);
      Display.setFullscreen(fullscreen);
      Display.setTitle("OpenCraft");
      Display.create();

    } catch (LWJGLException e) {
      Sys.alert("Error", "Unable to create display.");
      System.exit(0);
    }
  }
  /**
   * *************************************************************************************************************************************************************************************************
   * Initialization stuff comes in here...
   * ************************************************************************************************************************************************************************************************
   */
  private void init() {

    try {
      Display.setDisplayMode(new DisplayMode(640, 480));
      Display.setVSyncEnabled(true);
      Display.setTitle("MS3D Loader [G36C]");
      Display.create();

      Keyboard.create();

    } catch (LWJGLException e) {
      Sys.alert("Error", "Initialization failed!\n\n" + e.getMessage());
      System.exit(0);
    }

    /* OpenGL */
    int width = Display.getDisplayMode().getWidth();
    int height = Display.getDisplayMode().getHeight();

    GL11.glViewport(0, 0, width, height); // Reset The Current Viewport
    GL11.glMatrixMode(GL11.GL_PROJECTION); // Select The Projection Matrix
    GL11.glLoadIdentity(); // Reset The Projection Matrix
    GLU.gluPerspective(
        45.0f,
        ((float) width / (float) height),
        0.1f,
        1000.0f); // Calculate The Aspect Ratio Of The Window
    GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix
    GL11.glLoadIdentity(); // Reset The Modelview Matrix

    GL11.glEnable(GL11.GL_TEXTURE_2D);
    GL11.glShadeModel(GL11.GL_SMOOTH);
    GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Background color
    GL11.glClearDepth(1.0f);
    GL11.glEnable(GL11.GL_DEPTH_TEST);
    GL11.glDepthFunc(GL11.GL_LEQUAL);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);

    // Load model
    //		g36c = new
    // MS3DModel(resourceLoader.loadResourceAsStream("models/gsg9.ms3d"),this.getClass().getResource("./data/textures").getPath());
    g36c =
        new MS3DModel(
            resourceLoader.loadResourceAsStream("models/assassin.ms3d"),
            this.getClass().getResource("./data/textures").getPath());

    //		tdsLoader=new TDSLoader();
    //		try {
    //			tdsLoader.load(resourceLoader.loadResourceAsStream("models/face.3ds"));
    //			System.out.println(tdsLoader.getObjectSize());
    //		} catch (IOException e) {
    //			e.printStackTrace();
    //		}

    // Load font
    font = new Font(resourceLoader.loadResourceAsStream("textures/font.bmp"), 12, width, height);

    // Init timer
    timer = new Timer();
  }
예제 #3
0
 /**
  * Disconnect from game. Allows for resetting server and client if triggered, but is not used in
  * all situations.
  *
  * @param message the message
  */
 public static void disconnectGame(String message) {
   /*
   //wouldn't be hard to use something like this to reset to lobby rather than quit the game:
   //at the moment this disconnect is only in a few places between stages, i.e. while waiting
   //so it's not too bad to quit the game.
   Player leaver = null;
   for(Player p : session.getPlayers()) {
   	if(p.getID() == message.origin) {
   		leaver = p;
   	}
   }
   session.removePlayer(leaver);
   System.out.println(leaver.getName()+" LEFT THE GAME");
    * */
   if (FEServer.getServer() != null) {
     // boot the server back to lobby
     FEServer.resetToLobbyAndKickPlayers();
   } else {
     // exit the client
     if (message != null && !message.equals("")) {
       Sys.alert("FE:MP", message);
     }
     System.exit(0);
   }
 }
예제 #4
0
 /**
  * Application init
  *
  * @param args Commandline args
  */
 public static void main(String[] args) {
   try {
     init(false);
     run();
   } catch (Exception e) {
     e.printStackTrace(System.err);
     Sys.alert(GAME_TITLE, "An error occured and the game will exit.");
   } finally {
     cleanup();
   }
   System.exit(0);
 }
예제 #5
0
  /**
   * Get the Sound based on a specified OGG file
   *
   * @param ref The reference to the OGG file in the classpath
   * @param in The stream to the OGG to load
   * @return The Sound read from the OGG file
   * @throws IOException Indicates a failure to load the OGG
   */
  public Audio getOgg(String ref, InputStream in) throws IOException {
    if (!soundWorks) {
      return new NullAudio();
    }
    if (!inited) {
      throw new RuntimeException(
          "Can't load sounds until SoundStore is init(). Use the container init() method.");
    }
    if (deferred) {
      return new DeferredSound(ref, in, DeferredSound.OGG);
    }

    int buffer = -1;

    if (loaded.get(ref) != null) {
      buffer = ((Integer) loaded.get(ref)).intValue();
    } else {
      try {
        IntBuffer buf = BufferUtils.createIntBuffer(1);

        OggDecoder decoder = new OggDecoder();
        OggData ogg = decoder.getData(in);

        AL10.alGenBuffers(buf);
        AL10.alBufferData(
            buf.get(0),
            ogg.channels > 1 ? AL10.AL_FORMAT_STEREO16 : AL10.AL_FORMAT_MONO16,
            ogg.data,
            ogg.rate);

        loaded.put(ref, new Integer(buf.get(0)));

        buffer = buf.get(0);
      } catch (Exception e) {
        Log.error(e);
        Sys.alert("Error", "Failed to load: " + ref + " - " + e.getMessage());
        throw new IOException("Unable to load: " + ref);
      }
    }

    if (buffer == -1) {
      throw new IOException("Unable to load: " + ref);
    }

    return new AudioImpl(this, buffer);
  }
예제 #6
0
  public static void init(SpriteSheet sheet) {
    spritesheet = sheet;
    // Initialize Tile type Dictionary
    tileTypes = new HashMap<Integer, Tile>();

    // Initialize Tile name Dictionaries
    tileNames = new HashMap<String, Integer>();

    // Initialize Tile types
    try {
      fog = new Fog(FOG, "fog", sheet.getCustomTileTexture(5, 6, 5, 3));
      addTile(new Tile(AIR, "air"));
      addTile(new Tile(NULL, "null", sheet.getTileTexture(9 * sheet.width)));
      addTile(new DirtTile(DIRT, "dirt", sheet.getCustomTileTexture(0, 0, 5, 3)));
      addTile(new MultitextureTile(GRASS, "grass", sheet.getCustomTileTexture(1, 9, 3, 1)));
      addTile(new LakeTile(LAKE, "lake", sheet.getCustomTileTexture(10, 3, 5, 3)));
      addTile(new SandTile(SAND, "sand", sheet.getCustomTileTexture(10, 0, 5, 3)));
      addTile(new RoadTile(COBBLESTONE_ROAD, "road", sheet.getCustomTileTexture(5, 0, 5, 3)));
      addTile(
          new SnowyGrassTile(SNOWY_GRASS, "snowy grass", sheet.getCustomTileTexture(0, 6, 5, 3)));
      addTile(
          new FrozenLakeTile(LAKE_FROZEN, "frozen lake", sheet.getCustomTileTexture(5, 3, 3, 3)));

      addTile(new MultitextureForegroundTile(TREE, "tree", sheet.getCustomTileTexture(4, 9, 2, 1)));
      addTile(new MultitextureForegroundTile(BUSH, "bush", sheet.getCustomTileTexture(6, 9, 1, 1)));
      addTile(new MultitextureForegroundTile(SIGN, "sign", sheet.getCustomTileTexture(7, 9, 3, 1)));
      addTile(
          new MultitextureForegroundTile(ROCK, "rock", sheet.getCustomTileTexture(11, 9, 1, 1)));
      addTile(new MountainTile(MOUNTAIN, "mountain", sheet.getCustomTileTexture(0, 3, 5, 3)));
      addTile(new PotTile(POT, "pot", sheet.getTileTexture(0 + 10 * sheet.width)));
      addTile(
          new BrokenPotTile(BROKEN_POT, "broken_pot", sheet.getTileTexture(1 + 10 * sheet.width)));
    } catch (IOException ex) {
      Sys.alert("TileLand", "Unable to load tiletypes!");
      MenuManager.getMenuManager().openMenu("mainmenu");
    }
  }
예제 #7
0
  // ***************************************************************************
  // run
  // ***************************************************************************
  private void run() {
    // Main camera = new Main(0, 0, 0);

    float dx = 0.0f;
    float dy = 0.0f;
    float dt = 0.0f;

    float lastTime = 0.0f; // when the last frame was
    float time = 0.0f;

    float mouseSensitivity = 0.15f;
    float movementSpeed = 10.0f; // move 10 units per second

    // hide the mouse
    Mouse.setGrabbed(true);

    while ((gameRunning) && (!Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))) {
      // update();

      // render();
      GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
      // GL11.glLoadIdentity();
      GL11.glTranslatef(0.0f, 0.0f, -5.0f);

      axis.draw();
      grid.render();
      // cube.render();

      /*
      {
         Color.white.bind();
         texture.bind(); // or GL11.glBind(texture.getTextureID());

         GL11.glBegin(GL11.GL_QUADS);
         GL11.glTexCoord2f(0,0);
         GL11.glVertex2f(100,100);
         GL11.glTexCoord2f(1,0);
         GL11.glVertex2f(100+texture.getTextureWidth(),100);
         GL11.glTexCoord2f(1,1);
         GL11.glVertex2f(100+texture.getTextureWidth(),100+texture.getTextureHeight());
         GL11.glTexCoord2f(0,1);
         GL11.glVertex2f(100,100+texture.getTextureHeight());
         GL11.glEnd();
      }
      */

      Display.update();

      // keep looping till the display window is closed the ESC key is down
      /*
      while (!Display.isCloseRequested() ||
      !Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
      {
       */
      time = Sys.getTime();

      // here is your movement speed, which can be changed to anything
      dt = 0.0005f;

      lastTime = time;

      // distance in mouse movement from the last getDX() call.
      dx = Mouse.getDX();
      // distance in mouse movement from the last getDY() call.
      dy = Mouse.getDY();

      // control camera yaw from x movement from the mouse
      camera.yaw(dx * mouseSensitivity);
      // control camera pitch from y movement from the mouse
      camera.pitch(-dy * mouseSensitivity);

      // when passing in the distrance to move
      // we times the movementSpeed with dt this is a time scale
      // so if its a slow frame u move more then a fast frame
      // so on a slow computer you move just as fast as on a fast computer

      if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
        camera.moveForward(movementSpeed * dt);
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
        camera.moveBackwards(movementSpeed * dt);
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
        camera.moveLeft(movementSpeed * dt);
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
        camera.moveRight(movementSpeed * dt);
      }
      if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
        camera.moveRight(movementSpeed * dt);
      }

      if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
        camera.moveUp(movementSpeed * dt);
      }

      if (Keyboard.isKeyDown(Keyboard.KEY_P)) {

        // camera.moveRight(movementSpeed * dt);
      }

      // set the modelview matrix back to the identity
      GL11.glLoadIdentity();
      // look through the camera before you draw anything
      camera.lookThrough();

      // you would draw your scene here.

      if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
        Sys.alert("Close", "To continue, press ESCAPE on your keyboard or OK on the screen.");
        System.exit(0);
      }
    }
  }