Example #1
0
  /**
   * doNonGameplayInput: This method handles the non-gameplay input of the game. Pre: None. Post:
   * The game's zoom in/out, volume up/down requests will be handled.
   */
  private static void doNonGameplayInput() {

    // Handle zoomin/zoomout requests.
    if (GameInput.baActions[GameActions.ZOOM_IN]) {
      GameGraphics.increaseZoom();
    }
    if (GameInput.baActions[GameActions.ZOOM_OUT]) {
      GameGraphics.decreaseZoom();
    }
    if (GameInput.baActions[GameActions.VOLUME_INCREASE]) {
      GameSounds.incVolume();
      GameInput.baActions[GameActions.VOLUME_INCREASE] = false;
    }
    if (GameInput.baActions[GameActions.VOLUME_DECREASE]) {
      GameSounds.decVolume();
      GameInput.baActions[GameActions.VOLUME_DECREASE] = false;
    }
    if (GameInput.baActions[GameActions.VIEW_DEBUG]) {
      GameGraphics.bDebugView = !(GameGraphics.bDebugView);
      GameInput.baActions[GameActions.VIEW_DEBUG] = false;
    }
  }
Example #2
0
  /**
   * main: This method initializes and coordinates the main actions of the game. Pre: None Post: The
   * game has been completed
   */
  public static void main(String[] args) {
    JOptionPane.showMessageDialog(
        null,
        "CLEANSANITY\n"
            + "Instructions:\n"
            + "Use W, A, S, and D to move the Cleansinator towards the exit (a pulsating GREEN tile)\n"
            + "Clean the forces of dirt by pointing at them and pressing the RIGHT or LEFT MOUSE BUTTONS.\n"
            + "Use COMMA and PERIOD to zoom in and out.\n"
            + "Press SHIFT to toggle sprint.\n"
            + "Use P and O to increase/decrease the volume.",
        "CLEANSANITY",
        JOptionPane.PLAIN_MESSAGE);

    String strSeedToSetTo =
        JOptionPane.showInputDialog(
            null, "Input a game seed:", "CLEANSANITY", JOptionPane.INFORMATION_MESSAGE);
    try {
      iCurrentMapSeed = Integer.parseInt(strSeedToSetTo);
    } catch (NumberFormatException e) {
      iCurrentMapSeed = strSeedToSetTo.hashCode();
    }

    JOptionPane.showMessageDialog(
        null,
        "CLEANSANITY\n" + "NOW PLAYING: " + iCurrentMapSeed,
        "CLEANSANITY",
        JOptionPane.PLAIN_MESSAGE);

    strGamePath = new File("").getAbsolutePath();

    // Initialization begins
    iGameReadinessState = -1;
    mainGameWindow = new GameWindow();

    GameInput.initGameInput();
    GameSettings.initGameSettings();
    GameSettings.setDefaultKeyBindings();
    ColorScheme.initColorScheme();

    iMSPFOGmAdj = GameSettings.iMSPFOGm;
    lCurrentFrame = 0;
    mainGameWindow.start();

    entveCurrentEntities = new Vector<Entity>();
    addEntity(
        ContentLibrary.PLAYER_BLUEPRINT,
        0,
        0,
        0,
        new ControllerPlayer(),
        new SkeletonHumanoid(),
        ContentLibrary.PLAYER_COLORS);
    // addEntity(ContentLibrary.RAT_BLUEPRINT, 10,17,0, new ControllerAI(), new SkeletonCreature(),
    // ContentLibrary.CREATURE_COLORS);
    // addEntity(ContentLibrary.DIRTY_BUBBLE_BLUEPRINT, 15,15,0, new ControllerAI(), new
    // SkeletonBubble(), ContentLibrary.DIRTY_BUBBLE_COLORS);
    addItem(
        new Item(
            ContentLibrary.DUSTER_BLUEPRINT,
            new ControllerItem(),
            new SkeletonDuster(),
            ContentLibrary.DUSTER_COLORS,
            0,
            handleEntity(0).ensSkeleton.sklaSkeleton[5]),
        handleEntity(0));
    addItem(
        new Item(
            ContentLibrary.BROOM_BLUEPRINT,
            new ControllerItem(),
            new SkeletonBroom(),
            ContentLibrary.BROOM_COLORS,
            0,
            handleEntity(0).ensSkeleton.sklaSkeleton[6]),
        handleEntity(0));

    dngCurrentDungeon = new Dungeon(iCurrentMapSeed);

    iGameReadinessState += 1;
    // Initialization ends
    bRenderMenu = false;
    bRenderGame = true;

    mainGameWindow.show();
    // The Gameplay Loop
    while (true) {

      lGameLoopStartTime = System.currentTimeMillis();

      if (bRenderGame) {
        doGameLoop();
        ColorScheme.updateColorList();
        lCurrentFrame++;
      }
      // Do features such as zoom in, zoom out, calling out menus, etc.
      doNonGameplayInput();
      // Checks whether different music needs to be played
      GameSounds.updateGameSounds();
      regulateFramerate();
    }
  }