Esempio n. 1
1
  @Override
  public void update(GameContainer container, int delta) throws SlickException {
    Projectile proj;
    playerNextPos = inputHandler.playerInput(player, container.getInput(), delta, sound);
    entity.update(delta, sound);
    if (!isBlocked(playerNextPos, player.getWidth(), player.getHeight())) {
      player.setCoord(playerNextPos);
    }

    player.logic();

    for (int i = 0; i < projectiles.size(); i++) {
      proj = projectiles.get(i);
      proj.update(delta);
      if (isBlocked(proj.pos, proj.getWidth(), proj.getHeight())) {
        projectiles.remove(i);
        sound.playSound(collisionSound);
      } else if (proj.collidesWith(entity) && proj.getOwner() == player) {
        proj.damage(entity);
        projectiles.remove(i);
      } else if (proj.collidesWith(player) && proj.getOwner() == entity) {
        proj.damage(player);
        projectiles.remove(i);
      }
    }
  }
Esempio n. 2
1
  public void render(GameContainer container, Graphics g) throws SlickException {
    int xOffset = -(int) player.getX() + WIDTH / 2;
    int yOffset = -(int) player.getY() + HEIGHT / 2;

    tileMap.render(xOffset, yOffset);
    player.draw(WIDTH, HEIGHT);
    entity.draw(xOffset, yOffset);
    for (int i = 0; i < projectiles.size(); i++) {
      projectiles.get(i).draw(xOffset, yOffset);
    }
    this.drawHealthBar(g, player, xOffset, yOffset);
    this.drawHealthBar(g, entity, xOffset, yOffset);
  }
Esempio n. 3
0
 public void scrollCoins() {
   for (Coin i : coinList) {
     i.setY(i.getY() + (int) (player1.getVelocity() * 0.3));
     i.setYPos(i.getYPos() + (int) (player1.getVelocity() * 0.3));
     i.setYMax(i.getYMax() + (int) (player1.getVelocity() * 0.3));
   }
 }
Esempio n. 4
0
 public void checkStarCollision() {
   for (Star s : starList) {
     if (s.getOnScreen()) { // if the star is on the screen we need to check if player collides
       if (s.checkCollision(
           s.getPics().get(s.getCounter()),
           player1)) { // if the player collides with the star we remove it then change the
         // velosity to the distance that the star provides
         sRemove.add(s); // remove star once you collide with it
         player1.setVelo(s.getDist()); // changes the velocity
         player1.setInvi(true); // sets the player invisble for a few seconds
         score += s.getPoints(); // points increase by the star type
         if (musicOn) {
           starSound.play(); // playthe star sound
         }
       }
     } else {
       sRemove.add(s); // remove the star if its not on the screen
     }
   }
   for (Star s : sRemove) {
     poofList.add(new Poof(s.getX(), s.getY(), s.getNum() + 3)); // make the poof effect
     starList.remove(s);
   }
   sRemove = new ArrayList<Star>();
 }
Esempio n. 5
0
 public void checkEnemyCollision() {
   for (Enemy e : enemyList) {
     if (e.getOnScreen()) { // can be removed later on
       // goes through all the enemies and checks if they collide
       if (e.checkCollision(e.getPics().get(e.getCounter()), player1)) {
         if (player1.getInvi() == false) {
           // If the player is not invisble then you get spiked.
           if (player1.getVelocity() > 0) { // if the player hits it from the bottom
             player1.setSpikeVelo();
             loseCoins();
           } else {
             player1.setVelo(
                 50); // if the player is on top instead the player bounces off the enemy
             if (musicOn) {
               bounce.play();
             }
           }
         }
         eRemove.add(e); // once we hit, we remove the enemy
       }
     } else {
       eRemove.add(e); // if the enemy goes of the screen, we remove
     }
   }
   for (Enemy e : eRemove) {
     poofList.add(new Poof(e.getX(), e.getY(), 1)); // removes all the enemies
     enemyList.remove(e);
   }
   eRemove = new ArrayList<Enemy>();
 }
Esempio n. 6
0
  public static void loadPlayer(Registry registry) {
    Player p = (Player) getPlayers().get(player);
    if (p != null) {
      p.setTransient(registry);
    }

    GameController gc = registry.getGameController();
    registry.getPlayerManager().clearPlayers();
    registry.getPlayerManager().registerPlayer(p);
    BlockManager bm = (BlockManager) blockManagers.get(player);
    bm.name = "Saved";
    bm = (BlockManager) bm.clone();
    bm.name = "Clone";
    bm.setTransient(registry);
    gc.setBlockManager(bm);
    PlaceableManager pm = (PlaceableManager) placeableManagers.get(player).clone();
    gc.setPlaceableManager(pm);
    MonsterManager mm = (MonsterManager) monsterManagers.get(player).clone();
    mm.setTransient(registry);
    gc.setMonsterManager(mm);

    if (p != null) {
      p.resetPlayer();
    }

    // unloadUnused();
  }
Esempio n. 7
0
 public void scrollEnemies() {
   for (Enemy i : enemyList) {
     i.setY(i.getY() + (int) (player1.getVelocity() * 0.3));
     i.setYPos(i.getYPos() + (int) (player1.getVelocity() * 0.3));
     i.setYMax(i.getYMax() + (int) (player1.getVelocity() * 0.3));
   }
 }
Esempio n. 8
0
  public void load() throws IOException {
    File file = getFile();
    if (file.exists()) {
      JsonObject rootObject = JSON_PARSER.parse(new FileReader(file)).getAsJsonObject();

      for (JsonElement element : rootObject.getAsJsonArray("players")) {
        Player player = new Player(element.getAsJsonObject());
        playerDB.put(player.getName(), player);
      }

      for (JsonElement element : rootObject.getAsJsonArray("groups")) {
        Group group = new Group(element.getAsJsonObject());
        groupDB.put(group.getName(), group);
      }
    } else {
      //noinspection ResultOfMethodCallIgnored
      file.createNewFile();
      JsonObject rootObject = new JsonObject();
      rootObject.add("players", new JsonArray());
      rootObject.add("groups", new JsonArray());
      BufferedWriter bw = new BufferedWriter(new FileWriter(file));
      bw.write(GSON.toJson(rootObject));
      bw.close();
    }
  }
Esempio n. 9
0
  public void run() {
    while (controller.okToRun) {
      try {
        recordControl.setRecordStream(bos);
        capturePlayer.start();
        recordControl.startRecord();
        Thread.sleep(recordingTime);
        recordControl.stopRecord();
        recordControl.commit();
        bos.flush();

        // Insert the recorded data into the shared buffer.
        buffer.insert(bos.toByteArray());

        // Reset the ByteArrayOutputStream for reuse.
        bos.reset();
      } catch (InterruptedException e) {

        // If Thread was interrupted, we just want to terminate.
        // Close any open Players
        // Do we need to do this if we set the threads to null
        // from TunerMIDlet?
        if (capturePlayer != null) {
          capturePlayer.close();
        }
      } catch (Exception e) {
        controller.showError(e.getMessage(), new FatalForm(controller));
      }
    }
  }
  private void showCamera() {

    try {

      releaseResources();
      player = Manager.createPlayer("capture://video");
      player.addPlayerListener(this);
      player.realize();

      videoControl = (VideoControl) player.getControl("VideoControl");
      aVideoCanvas = new VideoCanvas();
      aVideoCanvas.initControls(videoControl, player);

      aVideoCanvas.addCommand(CMD_RECORD);
      aVideoCanvas.addCommand(CMD_EXIT);
      aVideoCanvas.setCommandListener(this);
      parentMidlet.getDisplay().setCurrent(aVideoCanvas);

      player.start();
      contentType = player.getContentType();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 // paints the player, items, and rooms
 public void paintComponent(Graphics g) {
   super.paintComponent(g);
   Environment Layout = new Environment();
   Layout.drawRoom(mapX, mapY, g);
   Player PlayerSprite = new Player();
   PlayerSprite.drawPlayer(x, y, g);
   Layout.items(x, y, g, getItem);
 }
Esempio n. 12
0
 public boolean spawnBossOrc(Player player) {
   if (getSpawnCount("BossOrc") < 1) {
     registry.showMessage("Success", "Beware, Melvin lurks nearby...");
     spawn("BossOrc", "Roaming", player.getMapX(), player.getMapY());
     return true;
   }
   return false;
 }
Esempio n. 13
0
 private void assignCards() {
   player.clearCards();
   dealer.clearCards();
   for (int i = 0; i < 3; ++i) {
     player.assignCard(genNewCard());
     dealer.assignCard(genNewCard());
   }
 }
Esempio n. 14
0
 public boolean spawnSnailRider(Player player) {
   if (getSpawnCount("SnailRider") < 1) {
     registry.showMessage("Success", "Suddenly, a wild Snail Rider appears!");
     spawn("SnailRider", "Roaming", player.getMapX(), player.getMapY());
     return true;
   }
   return false;
 }
Esempio n. 15
0
 public void keyReleased(KeyEvent evt) {
   keys[evt.getKeyCode()] = false;
   // reset the counters for for the sprite s
   player1.resetCounter();
   if (!player1.getPower().equals("Balloon")) {
     player1.resetPicCounter();
   }
 }
 private void releaseResources() {
   if (player != null) {
     try {
       player.stop();
       player.close();
     } catch (Exception e) {
     }
   }
 }
Esempio n. 17
0
 public boolean check(String entityName, Node node) {
   if (!playerDB.containsKey(entityName)) return false;
   Player player = playerDB.get(entityName);
   if (player.hasSpecificPermissionFor(node)) return true;
   for (String groupName : player.getGroups()) {
     if (checkGroup(groupName, node)) return true;
   }
   return false;
 }
  /**
   * update is an overwritten method of Observer, used in reaction to a change happening in an
   * observed class. In this case it updates the instance variable HashMap itemMap, removing
   * references to the Item at the old location, and adding it's reference to the new location. It
   * also updates the locations that the Player has visited, adding the most recent Location first
   * in the linked list. Note: more objects than Items and Player could be added later
   *
   * @param o : an Observable object (which should be an GameObject object of some sort)
   * @param arg : an Object (which should be a Location object)
   */
  public void update(Observable o, Object arg) {
    /** Item update code* */
    if (o instanceof Item && arg instanceof Integer) {
      Item item = (Item) o;
      int oldLocation = (Integer) arg;
      int newLocation = item.getObjectLocation();

      // remove old item from array list
      ArrayList<Item> newList = itemMap.get((Integer) oldLocation);

      if (newList != null) {
        // For loop while there is another element
        for (Iterator<Item> it = newList.iterator(); it.hasNext(); ) {
          if (item.getObjectID() == it.next().getObjectID()) {
            it.remove();
          }
          // End if matching id
        }
        // End for loop

        // Update the item map with the new status with the item removed
        itemMap.put((Integer) oldLocation, newList);
      }
      // if list not null

      // If not 'destroyed', which is sent to location 9999
      if (!(newLocation == 9999)) {
        // add the item to the new location's array list
        if (!(itemMap.containsKey((Integer) newLocation))) {
          newList = new ArrayList<Item>();
          newList.add(item);
          itemMap.put((Integer) newLocation, newList);
        } else {
          newList = itemMap.get((Integer) newLocation);
          // not checking for duplicates yet, add the item to the list
          newList.add(item);
          // Update the item map with the new status
          itemMap.put((Integer) newLocation, newList);
        }
        // End contains key
      }
      // End if not destroyed
    }
    // End if valid instances of Item and Integer

    /** Player update code* */
    if (o instanceof Player && arg instanceof Integer) {
      Player player = (Player) o;
      int location = player.getObjectLocation();

      // Add new locations the player visits Last in the linked list,
      // which makes last element always the current
      playerList.addLast(location);
    }
    // End if valid instances of Player and Integer
  }
Esempio n. 19
0
 /**
  * Update changing components.
  *
  * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
  */
 @Override
 public void paintComponent(Graphics g) {
   money.setText(String.valueOf(player.getMoney()));
   record.setText(String.valueOf(bestScore));
   dealerPanel.removeAll();
   playerPanel.removeAll();
   for (Card dealerCard : dealer.getCards()) dealerPanel.add(dealerCard);
   for (Card playerCard : player.getCards()) playerPanel.add(playerCard);
   revalidate();
 }
Esempio n. 20
0
 private void playFile(File file) throws Exception {
   player = playerList.getPlayer(playListManager.getTrackDatabase().getPlayer());
   try {
     player.play(file);
   } catch (PlayerException e) {
     e.printStackTrace();
   } finally {
     // Without this, RoboJock can't talk because it fights with the
     // Java player over the sound device.
     player.close();
   }
 }
Esempio n. 21
0
  //    public static void unloadUnused() {
  //        if (player > -1) {
  //            for (int i = 0; i < NUMBER_OF_PLAYER_SLOTS; i++) {
  //                if (i != player) {
  //                    players.set(i, null);
  //                    blockManagers.set(i, null);
  //                    placeableManagers.set(i, null);
  //                    monsterManagers.set(i, null);
  //                }
  //            }
  //        }
  //    }
  public static ArrayList getPlayerList() {
    ArrayList names = new ArrayList();

    for (int i = 0; i < players.size(); i++) {
      Player p = players.get(i);
      if (p != null) {
        names.add(p.getName());
      } else {
        names.add("");
      }
    }
    return names;
  }
Esempio n. 22
0
 private void movePlayers() {
   onePlayerAlive = false;
   Iterator i = players.iterator();
   while (i.hasNext()) {
     Player p = (Player) i.next();
     if (p.getLives() == 0) {
       p.setActive(false);
     }
     if (p.isActive()) {
       onePlayerAlive = true;
       p.move();
     }
   }
 }
Esempio n. 23
0
 public void loseCoins() {
   int x = player1.getX();
   int y = player1.getY();
   double losePercentage = 0.1;
   for (int i = 0;
       i < (int) coins * losePercentage;
       i++) { // makes the user lose 10 percent of the coin and draws them in a circle
     // System.out.println(i);
     int xPos = x + (int) (100 * Math.cos(Math.toRadians((360 / (coins * losePercentage)) * i)));
     int yPos = y - (int) (100 * Math.sin(Math.toRadians((360 / (coins * losePercentage)) * i)));
     coinList.add(new Coin(xPos, yPos, 3));
   }
   coins -= (int) (coins * losePercentage);
 }
Esempio n. 24
0
  private void setup() {
    playerSetup();

    deathLocation = new int[4];
    Arrays.fill(deathLocation, -1);

    menu.setVisible(false);
    this.revalidate();

    audioSetup();

    Iterator i = players.iterator();
    Player p;
    while (i.hasNext()) {
      p = (Player) i.next();
      p.resetLives(3);
      p.setActive(true);
    }

    BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
    Cursor blank =
        Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0), "BLANK");
    this.setCursor(blank);

    reset();

    ballN = 1;
    level = 1;
    timeLast = 0;
    score = 0;
    counterN = 10;
    timeCircle = 0;
    timeCircleSwitch = 0;
    programLoopCounter = 1;
    programSpeedAdjust = 1;

    onePlayerAlive = true;
    countdownF = true;
    circular = true;
    spawnIncrease = true;
    spawnCircleB = false;
    spawnMonsterB = false;
    spawnRandomersB = false;

    levelSetup();
    countdown();
    animate();
  }
Esempio n. 25
0
 // -------------------------------------------------------------------------------------------------------------------------------------------------------
 public String getPowerUp() {
   if (!player1.getPower().equals("")) {
     return ("P1");
   } else {
     return "none";
   }
 }
Esempio n. 26
0
 static int isEnd(Player player) {
   int i;
   for (i = 1; i <= 5; i++) {
     if (player.haveHide("End" + i)) return i;
   }
   return 0;
 }
  public void captureImage() {
    String savepath =
        this.saveDirectory + "\\cam" + this.getDateFormatNow("yyyyMMdd_HHmmss-S") + ".jpg";
    System.out.println("Capturing current image to " + savepath);

    // Grab a frame
    FrameGrabbingControl fgc =
        (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");
    buf = fgc.grabFrame();

    // Convert it to an image
    btoi = new BufferToImage((VideoFormat) buf.getFormat());
    img = btoi.createImage(buf);

    // save image
    saveJPG(img, savepath);

    // show the image
    // imgpanel.setImage(img);

    // images.add(img);
    images.add(savepath);

    if (images_lastadded.size() >= lastadded_max) {
      // Remove last
      images_lastadded.remove(images_lastadded.size() - 1);
    }

    images_lastadded.add(0, images.size() - 1);
    images_nevershown.add(0, images.size() - 1);

    forceNewImage();
  }
Esempio n. 28
0
  public void run() {
    try {
      Telnet.writeLine(cs, "<fggreen> >>> Welcome to AdaMUD <<< <reset>");
      Telnet.flushInput(cs);

      while ((player = s.getPlayerDB().login(cs, s)) == null) ;
      player.look();

      while (true) {
        System.out.println("Waiting for message");
        String message = Telnet.readLine(cs).trim();

        if (message == null) {
          // Disconnected
          break;
        }

        if (message.equals("bye")) {
          Telnet.writeLine(cs, "Goodbye!");
          break;
        }

        parseCommand(message);
      }

      cs.close();
    } catch (IOException e) {
      System.out.println("Client error: " + e);
    } finally {
      s.getPlayerDB().remove(player);
      s.remove(cs);
    }
  }
Esempio n. 29
0
  /** main loop - periodically copy location data into Lua and evaluate zone positions */
  private void mainloop() {
    try {
      while (!end) {
        try {
          if (gps.getLatitude() != player.position.latitude
              || gps.getLongitude() != player.position.longitude
              || gps.getAltitude() != player.position.altitude) {
            player.refreshLocation();
          }
          cartridge.tick();
        } catch (Exception e) {
          stacktrace(e);
        }

        try {
          Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
      }
      if (log != null) log.close();
    } catch (Throwable t) {
      ui.end();
      stacktrace(t);
    } finally {
      instance = null;
      state = null;
      if (eventRunner != null) eventRunner.kill();
      eventRunner = null;
    }
  }
Esempio n. 30
0
  /** thread's run() method that does all the work in the right order */
  public void run() {
    try {
      if (log != null)
        log.println(
            "-------------------\ncartridge "
                + gwcfile.name
                + " started (openWIG r"
                + VERSION
                + ")\n-------------------");
      prepareState();

      if (doRestore) restoreGame();
      else newGame();

      loglevel = LOG_PROP;

      ui.debugMsg("Starting game...\n");
      ui.start();

      player.refreshLocation();
      cartridge.callEvent(doRestore ? "OnRestore" : "OnStart", null);
      ui.refresh();
      eventRunner.unpause();

      mainloop();
    } catch (IOException e) {
      ui.showError("Could not load cartridge: " + e.getMessage());
    } catch (Throwable t) {
      stacktrace(t);
    } finally {
      ui.end();
    }
  }