/**
   * Base tick method for the level. Updates all entities, tiles, and player. Has slow repopulation
   * algorithm
   */
  public void tick() {
    player.tick();
    List<Entity> toTick = new ArrayList<Entity>();
    int lr = 7;
    for (int x = -lr; x < lr; x++) {
      for (int y = -lr; y < lr; y++) {
        Tile tile = getTile(player.x + x, player.z + y);
        tile.addToTick(toTick);
        tile.tick();
      }
    }

    for (int i = 0; i < toTick.size(); i++) {
      Entity e = toTick.get(i);
      e.tick(this);
    }
    tickcount++;
    if (tickcount % 1800 == 0) {
      System.out.println("Adding entity to world");
      if (r != null) {
        int rx = r.nextInt(w);
        int ry = r.nextInt(h);

        if (skillNoise.noise(rx / 80d, ry / 80d) > 0.0) {
          SmallMob mob = new SmallMob();
          if (!tiles[rx + ry * w].blocks(mob)) {
            tiles[rx + ry * w].addEntity(r.nextInt(4), mob);
          }
        }
      }
    }
  }
示例#2
0
 private void tick() {
   p.tick();
   c.tick();
   try {
     Thread.sleep(25); // delay :  1000 milliseconds is one second.
   } catch (InterruptedException ex) {
     Thread.currentThread().interrupt();
   }
 }
示例#3
0
  public void run() {
    int scale = DungeonServer.universe.getTimescale();

    while (running) {
      try {
        Thread.sleep(1000 / scale);
      } catch (InterruptedException e) {
        return;
      }

      /*
       * Skips all object updates if there are no players connected.
       */
      if (DungeonServer.universe.getNumberOfPlayers() == 0) continue;

      /*
       * Update all game objects, starting with the universe.
       */
      DungeonServer.universe.tick();

      /*
       * Update players.
       */
      Iterator<Player> players = DungeonServer.universe.getPlayers();
      while (players.hasNext()) {
        Player p = players.next();

        // update the player themselves
        p.tick();

        // update all items in player's inventory
        Iterator<Item> items = p.getInventoryIterator();
        while (items.hasNext()) {
          Item i = items.next();
          if (i instanceof Stateful) ((Stateful) i).tick();
        }
      }

      /*
       * Update items in all rooms.
       */
      Iterator<Room> rooms = DungeonServer.universe.getRooms();
      while (rooms.hasNext()) {
        Room r = rooms.next();

        Iterator<Item> items = r.getItems().iterator();
        while (items.hasNext()) {
          Item i = items.next();
          if (i instanceof Stateful) ((Stateful) i).tick();
        }
      }
    }
  }
示例#4
0
 // @Override
 public synchronized void tick() {
   ArrayList<Element> d = new ArrayList<>();
   for (Player l : jugadores) {
     l.tick();
   }
   for (Player z : jugadores) {
     for (Element x : restriccion) {
       // To avoid player go outside the arena.
       tickUp(z, x, d);
       tickDown(z, x, d);
       tickRight(z, x, d);
       tickLeft(z, x, d);
     }
   }
   restriccion.removeAll(d);
 }
 public void updateObjects() {
   player.tick();
 }
示例#6
0
 public void tick() {
   player.tick();
 }
示例#7
0
  /**
   * Go through each player and check what action they are doing. Also, go through each tile and
   * update it.
   */
  public void tick() {

    // System.out.println(game.getPlayer().getUsername() + "'s game");

    // for (Player p : players)
    // System.out.println(p.getUsername() + "is in: " +
    // p.getRoom().getName());
    // Go through players
    for (Player p : players) {
      if (!p.isAlive()) {
        game.r_removeModel(p.getUsername());
      }

      // Only render the player if they are alive
      if (readyToRender && p.isAlive()) {

        // If the player is in the same room as the player on this
        // computer, add them to the renderer
        if (p.getRoom().equals(game.getPlayer().getRoom())) {
          if (game.r_addModel(p.getModel())) {
            // System.out.println("Adding " + p.getUsername()
            //		+ "'s model in "
            //		+ game.getPlayer().getUsername() + "'s game");
          }
        }

        // If the player is not in the same room as the
        // player on this computer, remove them from the
        // renderer
        else if (!p.getRoom().equals(game.getPlayer().getRoom())) {
          game.r_removeModel(p.getUsername());
        }

        // Update the room
        if (!p.isRoomLoaded() && p.equals(game.getPlayer())) {

          if (p.getOldRoom() != null) p.getOldRoom().removeTiles(game.getRenderer());

          p.getRoom().initTiles(game.getRenderer());
          p.setRoomLoaded(true);
        }

        // Update player
        p.tick();

        // Packet to be sent to the server
        Packet packet = null;

        // Player shooting
        if (p.isShooting()) {
          packet = new Packet03Engage(p.getUsername());
          // packet.writeData(game.getClient());
        }

        // Player interacting
        // Check if player is interacting with a tile
        if (p.isInteracting()
            && p.getRoom() != null
            && p.equals(game.getPlayer())
            && p.getRoom().validPosition(p, p.getX(), p.getY())) {
          Tile tile = p.getRoom().getTile(p, p.getX(), p.getY());
          // isInteracting = false;
          // tile.onInteract(p);

          // Find the type of interaction
          switch (p.getInteraction()) {
            case CHEST:
            case DOOR:
            case TERMINAL:
              packet = new Packet06Interact(p.getUsername(), tile.getID());
              break;

            case NONE:
            default:
              break;
          }

          // Interact with the tile
          tile.onInteract(p);

          // Reset the interaction back to NONE
          p.resetInteraction();

          p.setInteracting(false);

          if (packet != null) packet.writeData(game.getClient());
        }

        // Check health
        if (!p.getUsername().equals(game.getPlayer().getUsername())) {
          Player pl = getPlayer(game.getPlayer().getUsername());

          if (pl.getRoom().equals(p.getRoom())
              && pl.getSide() == Team.GUARD
              && p.getSide() == Team.SPY
              && pl.inRange(p.getX(), p.getY())) {
            // getPlayer(game.getPlayer().getUsername())
            // .takeDamage(0.1);
            packet = new Packet04Damage(p.getUsername(), p.getUsername(), 0.5);
            packet.writeData(game.getClient());
          }
        }

        // Player moving
        if (p.isMoving()) {
          packet =
              new Packet02Move(
                  p.getUsername(),
                  ((PlayerMP) p).getID(),
                  p.getX(),
                  p.getY(),
                  p.getZ(),
                  true,
                  p.getRotation());
          packet.writeData(game.getClient());
        }

        // Player picking up item
        if (p.itemPickedUp()) {
          Tile tile = p.getRoom().getTile(p, p.getX(), p.getY());
          Item last = p.getLastItem();
          p.setItemPickedUp(false);
          packet = new Packet10Pickup(p.getUsername(), tile.getID(), last.getID());
          packet.writeData(game.getClient());
        }

        // Finally tick through the room that the player is in
        p.getRoom().tick(game.getRenderer(), game.getPlayer());
      }
    }
  }