Esempio n. 1
0
 @Override
 public void key(int i, boolean bln) {
   super.key(i, bln);
   if (!bln) {
     return;
   }
   if (stepOn != codes.length && i == codes[stepOn]) {
     stepOn++;
     if (stepOn == codes.length) {
       SoundPlayer.getSoundPlayer().playCoffeeBrewing();
     } else {
       SoundPlayer.getSoundPlayer().playMouseClick();
     }
   }
 }
Esempio n. 2
0
  @Override
  public void key(int i, boolean bln) {
    super.key(i, bln);
    if (i == KeyCode.KEY_D) {
      right = bln;
    }
    if (i == KeyCode.KEY_A) {
      left = bln;
    }

    // scare the house the demon is nearby
    if (i == KeyCode.KEY_F) {
      boolean allScared = true;
      for (int j = 0; j < housesPosX.length; j++) {
        if (Math.abs(littleDemonPosX - housesPosX[j] + (houseNotScared.getWidth() / 2)) < 15) {
          SoundPlayer.getSoundPlayer().playScareHouse();
          // SoundPlayer.getSoundPlayer().playDemonSpeaking(); (at the same time?)
          housesScared[j] = true;
        }
        if (!housesScared[j]) {
          allScared = false;
        }
      }
      if (allScared) {
        // complete task when all the houses are scared
        setComplete(true);
        left = false;
        right = false;
      }
    }
  }
Esempio n. 3
0
 public void resetForNewDay() {
   hoursLeft = 12;
   paperworkLeft = PAPERWORK_PER_DAY_BASE_VALUE;
   nextTaskIndex = 0;
   tickProgress = 0;
   ticksPerHour = MILLIS_PER_HOUR_INITIAL;
   currImpAttackTime = 0; // reset imp spawn time;
   for (int i = 0; i < toDoList.size(); i++) {
     toDoList.get(i).resetForDay();
   }
   // remove all imp task blocks.
   for (int i = 0; i < impTaskObjects.size(); i++) {
     if (impTaskObjects.get(i).getAssociatedTask() == activeTask) {
       activeTask = null;
     }
     officeWorld.getEntities().remove(impTaskObjects.get(i));
     impTaskObjects.remove(i);
   }
   SoundPlayer.getSoundPlayer().setMusicTo(SoundPlayer.MAIN_SONG);
 }
Esempio n. 4
0
  @Override
  public void onEnter() {
    // currWorkerSleepTime = 0;
    officeWorld = new GameWorld<>(this);
    camera = new Camera();
    toDoList = new ArrayList<>();
    impTaskObjects = new ArrayList<>();
    ticksPerHour = MILLIS_PER_HOUR_INITIAL;
    impWaitTimeCurrent = IMP_WAIT_TIME_STAGE_1;
    // task and todo list init

    MakeCoffeeTask coffeeTask = new MakeCoffeeTask(this);
    MeetingTask meetingTask = new MeetingTask(this);
    TakeLunchTask lunchTask = new TakeLunchTask(this);
    EmailTask emailTask = new EmailTask(this);
    ScareHouseTask scareTask = new ScareHouseTask(this);
    FaxTask faxTask = new FaxTask(this);
    PaperworkTask paperworkTask = new PaperworkTask(this);
    toDoList.add(coffeeTask);
    toDoList.add(meetingTask);
    toDoList.add(lunchTask);
    toDoList.add(emailTask);
    toDoList.add(scareTask);
    toDoList.add(faxTask);

    workers = new Employee[6];
    BufferedImage workerWorkingImg = getAssetManager().getImage("worker");

    impAlertImage = getAssetManager().getImage("impAlert");
    completeDay = getAssetManager().getImage("dayComplete");

    int workerImageAdjust = 44;

    // add everything to the world
    // desk
    officeWorld.addEntity(
        new OfficeObject(officeWorld, 100, getAssetManager().getImage("workerDesk"), camera));
    workers[0] = new Employee(officeWorld, 100 + workerImageAdjust, workerWorkingImg, camera);
    officeWorld.addEntity(workers[0]);
    // meeting door
    officeWorld.addEntity(
        new OfficeTaskObject(
            officeWorld, 400, getAssetManager().getImage("meetingDoor"), camera, meetingTask));
    //  desk
    officeWorld.addEntity(
        new OfficeObject(officeWorld, 550, getAssetManager().getImage("workerDesk"), camera));
    workers[1] = new Employee(officeWorld, 550 + workerImageAdjust, workerWorkingImg, camera);
    officeWorld.addEntity(workers[1]);
    // coffee maker
    officeWorld.addEntity(
        new OfficeTaskObject(
            officeWorld, 850, getAssetManager().getImage("coffeemaker"), camera, coffeeTask));
    // fax machine
    officeWorld.addEntity(
        new OfficeTaskObject(
            officeWorld, 1000, getAssetManager().getImage("faxMachine"), camera, faxTask));
    //  desk
    officeWorld.addEntity(
        new OfficeObject(officeWorld, 1200, getAssetManager().getImage("workerDesk"), camera));
    workers[2] = new Employee(officeWorld, 1200 + workerImageAdjust, workerWorkingImg, camera);
    officeWorld.addEntity(workers[2]);
    //  desk
    officeWorld.addEntity(
        new OfficeObject(officeWorld, 1450, getAssetManager().getImage("workerDesk"), camera));
    workers[3] = new Employee(officeWorld, 1450 + workerImageAdjust, workerWorkingImg, camera);
    officeWorld.addEntity(workers[3]);
    // phone to order lunch
    officeWorld.addEntity(
        new OfficeTaskObject(
            officeWorld, 1650, getAssetManager().getImage("phoneOffice"), camera, lunchTask));
    // demon desk
    officeWorld.addEntity(
        new OfficeTaskObject(
            officeWorld, 1850, getAssetManager().getImage("paperdesk"), camera, paperworkTask));
    // computer to answer emails
    officeWorld.addEntity(
        new OfficeTaskObject(
            officeWorld, 2000, getAssetManager().getImage("computerdesk"), camera, emailTask));
    //  desk
    officeWorld.addEntity(
        new OfficeObject(officeWorld, 2250, getAssetManager().getImage("workerDesk"), camera));
    workers[4] = new Employee(officeWorld, 2250 + workerImageAdjust, workerWorkingImg, camera);
    officeWorld.addEntity(workers[4]);
    //  desk
    officeWorld.addEntity(
        new OfficeObject(officeWorld, 2500, getAssetManager().getImage("workerDesk"), camera));
    workers[5] = new Employee(officeWorld, 2500 + workerImageAdjust, workerWorkingImg, camera);
    officeWorld.addEntity(workers[5]);
    // portal to scare the family
    officeWorld.addEntity(
        new OfficeTaskObject(
            officeWorld, 2800, getAssetManager().getImage("portalOffice"), camera, scareTask));

    // init player last (so they're drawn on top)
    Track right =
        new Track(
            new BufferedImage[] {getImage("demon1"), getImage("demon2"), getImage("demon3")}, 200);
    getAssetManager().createHorizontialFlipCopy(getImage("demon1"), "demon1Left");
    getAssetManager().createHorizontialFlipCopy(getImage("demon2"), "demon2Left");
    getAssetManager().createHorizontialFlipCopy(getImage("demon3"), "demon3Left");
    Track left =
        new Track(
            new BufferedImage[] {
              getImage("demon1Left"), getImage("demon2Left"), getImage("demon3Left")
            },
            200);
    Animation rightAnim = new Animation();
    rightAnim.setTrack(rightAnim.addTrack(right));
    Animation leftAnim = new Animation();
    leftAnim.setTrack(leftAnim.addTrack(left));
    demonPlayer = new PlayerDemon(officeWorld, 0, leftAnim, rightAnim, camera);
    officeWorld.addEntity(demonPlayer);

    // init flip imp images
    getAssetManager()
        .createHorizontialFlipCopy(
            getAssetManager().getImage("troublemaker1"), "troublemaker1flip");
    getAssetManager()
        .createHorizontialFlipCopy(
            getAssetManager().getImage("troublemaker2"), "troublemaker2flip");

    impImage = getImage("troublemaker1flip");

    // employee heads init
    workerHeadsIcon =
        new BufferedImage[] {
          getAssetManager().getImage("workerHeadAwake"),
          // getAssetManager().getImage("workerHeadSleeping"),
          getAssetManager().getImage("workerHeadDead")
        };

    // Background init
    officeBackgroundRepeated = getAssetManager().getImage("foreground");
    coolParallaxScrolling = getAssetManager().getImage("background");
    border = getAssetManager().getImage("border");
    border2 = getAssetManager().getImage("border2");

    // other images init
    canNotDoYetPrompt = getAssetManager().getImage("canNotDoYet");

    /// Gui init
    gui = new Gui();
    GuiGroup main = new GuiGroup();

    main.addElement(new PaperStackGui(0, 300, 200, 300, this));
    main.addElement(clockGui = new ClockGui(600, 300, 200, 300, this));
    // draw last to put it on top
    main.addElement(todoListGuiElement = new ToDoListElement(200, 200, 600, 400, this));
    gui.addGroup("main", main);
    gui.setEnabled("main", true);
    todoListGuiElement.setEnabled(false);
    dayOn = 0;
    SoundPlayer.getSoundPlayer().setMusicTo(SoundPlayer.MAIN_SONG);
  }
Esempio n. 5
0
  @Override
  public void render(Object o) {
    Graphics2D g2 = (Graphics2D) o;
    // Clear the background
    g2.setColor(Color.BLACK);
    g2.fillRect(0, 0, 800, 600);
    // 1. clip office work to draw.
    // 800x300 Office world from (0, 0)
    //    draw background(s)
    //    draw all of the office furniture/people
    //    draw the demon
    //    If one is viewing the tasks window, render the tasks.
    Graphics2D officeRender = (Graphics2D) g2.create(0, 0, 800, 300); // reset the graphics

    // Draw the background
    officeRender.drawImage(coolParallaxScrolling, -parallaxOffset, 0, null);
    officeRender.drawImage(coolParallaxScrolling, 800 - parallaxOffset, 0, null);
    officeRender.drawImage(coolParallaxScrolling, -parallaxOffset, 100, null);
    officeRender.drawImage(coolParallaxScrolling, 800 - parallaxOffset, 100, null);

    int offset = ((int) camera.getXLocation()) % officeBackgroundRepeated.getWidth();
    for (int i = 0; i < ((officeBackgroundRepeated.getWidth() / 800) + 1); i++) {
      officeRender.drawImage(
          officeBackgroundRepeated,
          (int) (-offset + (i * officeBackgroundRepeated.getWidth())),
          100,
          null);
    }

    for (int i = 0; i < officeWorld.getEntities().size(); i++) {
      officeWorld.getEntities().get(i).render(officeRender);
    }
    officeRender.dispose();
    // 2. clip task world to draw.
    // 400x300 task world from (200, 300)
    //    If there is an active task, draw it
    //    Otherwise, draw a placeholder(?)
    Graphics2D taskRender = (Graphics2D) g2.create(200, 300, 400, 300);
    /// for (int j=0; j<toDoList.size(); j++) {
    ///     toDoList.get(j).render(g2); // pass the clipped graphics in
    /// }
    if (activeTask != null) {
      // find what task needs to be done next
      activeTask.render(taskRender);
      if (!isCompletedWithTasks()
          && activeTask != toDoList.get(nextTaskIndex)
          && !activeTask.isComplete()
          && !(activeTask instanceof HitImpTask)
          && !(activeTask instanceof InterviewTask)
          && !(activeTask instanceof PaperworkTask)) {
        // prompt that the task is visited too  early
        taskRender.drawImage(canNotDoYetPrompt, 0, 0, null);
      }
    } else {
      // Whatever is there with no task
    }
    taskRender.dispose();

    if (isFinishedWithDailyThings() && !viewingCompletedDay) {
      // SoundPlayer.getSoundPlayer().playVictoryMusic();
      SoundPlayer.getSoundPlayer().setMusicTo(SoundPlayer.NONE);
      SoundPlayer.getSoundPlayer().playVictoryMusic();
      viewingCompletedDay = true;
    }

    // draw the to-do list on top of everything
    if (viewingTasks) {
      // View all of the tasks.
    }
    gui.render(o);
    // Draw borders

    g2.drawImage(border, 0, 300, null);
    g2.drawImage(border2, 196, 306, null);
    g2.drawImage(border2, 598, 306, null);

    // render employee status gui according to what state they're in.
    for (int i = 0; i < workers.length; i++) {
      g2.drawImage(workerHeadsIcon[(workers[i].getState())], 495 + (50 * i), 10, null);
    }

    BufferedImage dayImg = getAssetManager().getImage("day" + (dayOn + 1));
    if (dayImg != null) {
      g2.drawImage(dayImg, 10, 10, null);
    }

    // draw the alert GUI warning about an imp attack
    for (int i = 0; i < impTaskObjects.size(); i++) {
      int yPos = 30 + (i * 25);
      int xPos = (int) (impTaskObjects.get(i).getX() - camera.getXLocation());
      // contain it to the screen so one can see what direction to go.
      if (xPos < 10) {
        xPos = 10;
      } else if (xPos > 730) {
        xPos = 770;
      }
      g2.drawImage(impAlertImage, xPos, yPos, null);
    }

    // Draw an imp that is flying across the screen
    if (showImp) {
      g2.drawImage(
          impImage,
          impXLoc - (impImage.getWidth() / 2),
          (int) ((((float) ((impXLoc - 400) * (impXLoc - 400))) / 1000) + 150)
              - (impImage.getHeight() / 2),
          null);
    }

    if (viewingCompletedDay) {
      // g2.drawImage(completeDay, 200, 150, null);
    }

    // draw the todolist last to go on top
    todoListGuiElement.render(o);

    /*
    Debugging things
    */
    /*
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, 150, 50);
    g2.setColor(Color.BLACK);
    g2.drawString("activeTask: " + activeTask, 10, 20);
    g2.drawString("paperworkLeft: " + paperworkLeft, 10, 30);
    */
  }
Esempio n. 6
0
  @Override
  public void update(int delta) {
    if (viewingCompletedDay) {
      viewingDayTime += delta;
      if (viewingDayTime >= 4000) {
        advanceDay();
      }
      return;
    }
    tickProgress += delta;
    if (tickProgress >= ticksPerHour) {
      advanceHour();
      tickProgress = 0;
    }
    // 1. update office world
    officeWorld.updateEntities(delta);
    // update paperwork
    paperworkLeft -= (getNumWorkerAlive() * EMPLOYEE_WORK_RATE);
    if (paperworkLeft < 0) {
      paperworkLeft = 0;
    }

    // imp spawning
    currImpAttackTime += delta;
    if (currImpAttackTime > impWaitTimeCurrent
        && getNumWorkerAlive() != 0) { // there must be workers alive to spawn an imp on one
      // make an imp randomly attack
      // make a random worker fall asleep
      if (Math.random() > 0.5) { // 50% chance to spawn at time limit
        // randomly chose a non-dead worker
        int whichOne = 0;
        int iterations = 0; // prevent infinite loop
        do {
          whichOne = (int) (Math.random() * workers.length);
          iterations++;
        } while (iterations >= 50
            && // safe lock to stop the loop after 100 times.
            workers[whichOne].getState() != Employee.WORKING
            && !workers[whichOne].isBeingAttackedByImp());
        if (!workers[whichOne].isBeingAttackedByImp()
            && workers[whichOne].getState() == Employee.WORKING
            && iterations < 50) { // only spawn an imp if iterations did not go out too far
          // define the task and add it to the list of tasks to be updated
          HitImpTask impTask = new HitImpTask(this, workers[whichOne]);
          ImpAttackTaskObject impTaskObject =
              new ImpAttackTaskObject(
                  officeWorld,
                  workers[whichOne].getX(),
                  getAssetManager().getImage("emptyImage"),
                  camera,
                  impTask);
          impTaskObjects.add(impTaskObject); // add to the list to keep track of it
          // spawn a "wake up" task object near them
          officeWorld.addEntity(impTaskObject);
          SoundPlayer.getSoundPlayer().playImpApproaching();
          // System.out.println("An imp started to attack an employee: whichOne: " + whichOne
          //     + ", worker being attacked already: " + workers[whichOne].isBeingAttackedByImp());
          workers[whichOne].setBeingAttackedByImp(true);
        }
      }
      currImpAttackTime = 0;
    }

    if (nextTaskIndex < toDoList.size() && toDoList.get(nextTaskIndex).isComplete()) {
      nextTaskIndex++;
    }
    for (int j = 0; j < toDoList.size(); j++) {
      toDoList.get(j).update(delta);
    }
    // 3. ?? update the input ??
    // Input does not need to be updated

    // Update the camera
    // The camera sets its position itself
    camera.setXLocation((int) (demonPlayer.getX() + (demonPlayer.getWidth() / 2) - 400));
    // Cool parallax scrolling
    parallaxOffset =
        (int)
            ((float)
                    (demonPlayer.getX()
                        / ((float) (Camera.getCameraMax() - demonPlayer.getWidth())
                            - Camera.getCameraMin()))
                * 800);

    // Update flying imp
    if (showImp) {
      impXLoc += 30;
      if (impXLoc > 850) {
        showImp = false;
      }
    }

    // startShowingImp();

    OfficeTaskObject intersects = null;
    for (int i = 0; i < officeWorld.getEntities().size(); i++) {
      OfficeObject obj = officeWorld.getEntities().get(i);
      if (obj instanceof OfficeTaskObject) {
        OfficeTaskObject task = (OfficeTaskObject) obj;
        if (task instanceof ChangeEmployeeStateTaskObject || task instanceof ImpAttackTaskObject) {
          // if a wake employee, interview, or kill imp task is completed, then its deleted on
          // completion.
          if (task.getAssociatedTask().isComplete()) {
            // remove object
            if (activeTask == task.getAssociatedTask()) {
              activeTask = null;
            }
            obj.setParent(null);
            officeWorld.getEntities().remove(obj);
            // remove the imp task from the list of imp tasks.
            if (task instanceof ImpAttackTaskObject) {
              ImpAttackTaskObject iat = (ImpAttackTaskObject) task;
              if (impTaskObjects.contains(iat)) {
                impTaskObjects.remove(iat);
              }
            }
            continue; // go to the next iteration.
          }
        }
        if (task.collidesWith(demonPlayer)) {
          intersects = task;
        }
      }
    }
    if (intersects != null) {
      activeTask = intersects.getAssociatedTask();
    } else {
      activeTask = null;
    }
    gui.update(-1, -1);
  }