예제 #1
0
 @Override
 public Entity getEntityById(int id) {
   synchronized (entities) {
     for (Entity entity : entities) if (id == entity.getId()) return entity;
     return null;
   }
 }
예제 #2
0
  /**
   * 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);
          }
        }
      }
    }
  }
예제 #3
0
 public void keyReleased(KeyEvent e) {
   // #if (mov_0)
   int key = e.getKeyCode();
   if (key == KeyEvent.VK_LEFT) {
     current_Player.setLeft(false);
   }
   if (key == KeyEvent.VK_RIGHT) {
     current_Player.setRight(false);
   }
   if (key == KeyEvent.VK_DOWN) current_Player.setDown(false);
   if (key == KeyEvent.VK_UP) current_Player.setUp(false);
   if (key == KeyEvent.VK_SHIFT) current_Player.setSpeed(2);
   // #endif
   // #if (mov_1)
   // @            int key = e.getKeyCode();
   // @            if (key == KeyEvent.VK_SPACE && current_Player.getLoad()==1)
   // current_Player.setLoad(2);
   // @            if (key == KeyEvent.VK_LEFT) current_Player.setLeft(false);
   // @            if (key == KeyEvent.VK_RIGHT) current_Player.setRight(false);
   // @            if (key == KeyEvent.VK_DOWN) current_Player.setDown(false);
   // @            if (key == KeyEvent.VK_UP) current_Player.setUp(false);
   // @            if (key == KeyEvent.VK_SHIFT) current_Player.setSpeed(2);
   // #endif
   // #if (mov_2)
   // @            int key = e.getKeyCode();
   // @            if (key == KeyEvent.VK_LEFT) current_Player.setLeft(false);
   // @            if (key == KeyEvent.VK_RIGHT) current_Player.setRight(false);
   // @            if (key == KeyEvent.VK_DOWN) current_Player.setDown(false);
   // @            if (key == KeyEvent.VK_UP) current_Player.setUp(false);
   // @            if (key == KeyEvent.VK_SHIFT) current_Player.setSpeed(2);
   // #endif
   // #if (mov_3)
   // @            int key = e.getKeyCode();
   // @            if (key == KeyEvent.VK_SPACE &&
   // current_Player.getLoad()==1){current_Player.setLoad(2);}
   // @            if (key == KeyEvent.VK_LEFT) current_Player.setLeft(false);
   // @            if (key == KeyEvent.VK_RIGHT) current_Player.setRight(false);
   // @            if (key == KeyEvent.VK_DOWN) current_Player.setDown(false);
   // @            if (key == KeyEvent.VK_UP) current_Player.setUp(false);
   // @            if (key == KeyEvent.VK_SHIFT) current_Player.setSpeed(2);
   // #endif
   // #if (mov_4)
   // @            int key = e.getKeyCode();
   // @            if (key == KeyEvent.VK_SPACE && current_Player.getLoad()==1)
   // current_Player.setLoad(2);
   // @            if (key == KeyEvent.VK_LEFT) current_Player.setLeft(false);
   // @            if (key == KeyEvent.VK_RIGHT) current_Player.setRight(false);
   // @            if (key == KeyEvent.VK_DOWN) current_Player.setDown(false);
   // @            if (key == KeyEvent.VK_UP) current_Player.setUp(false);
   // @            if (key == KeyEvent.VK_SHIFT) current_Player.setSpeed(2);
   // #endif
 }
예제 #4
0
  public void init(Entity Owner, int Level) {

    owner = Owner;
    level = Level;

    if (Owner != null) {

      mn = owner.getName();
      Mn = owner.getPName();
      my = Utility.possessive(mn);
      My = Utility.possessive(Mn);
    }
  }
예제 #5
0
  public void skillOutput(boolean passive, boolean failed, boolean peaceful) {

    owner.getRoom().setSkillRedirect(true);

    if (passive) owner.passiveOutput(target, selfOut, targOut, grupOut, obsvOut);
    else owner.combatOutput(target, selfOut, targOut, grupOut, obsvOut);

    if (!failed) {
      if (peaceful) trainPeaceful();
      else train();
    }

    owner.getRoom().setSkillRedirect(false);
  }
예제 #6
0
 public void checkEnvCollisions() {
   for (int i = 0; i < amountEnv; i++) {
     // #if (Hinderniss_Set)
     // @                if (env[i].getBounds().intersects(current_Player.getBounds())){
     // @                    current_Player.setCollision(true);
     // @                    if (timecount == 0) timecount = 50;
     // @                }
     // @            //}
     // #else
     if (env[i].getBounds().intersects(current_Player.getBounds())) current_Player.setSpeed(1);
     // else  current_Player.setSpeed(2);
     // #endif
   }
 }
예제 #7
0
 public void update() {
   current_Player.move();
   // #if (tar)
   // @        	// bewegt den Rocket nach Q-Pressed
   // @        	if (current_Player.isRocket()){
   // @        		sch.move(current_Player.getDegree());
   // @        	}
   // #endif
 }
예제 #8
0
 // for the application
 @GET
 @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
 public TaskData getTaskData() {
   // same code as above method
   DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
   MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
   if (syncCache.get(keyname) != null) {
     TaskData ts = (TaskData) syncCache.get(keyname);
     return ts;
   }
   Key entKey = KeyFactory.createKey("TaskData", keyname);
   try {
     Entity ent = datastore.get(entKey);
     TaskData ts =
         new TaskData(keyname, (String) ent.getProperty("value"), (Date) ent.getProperty("date"));
     return ts;
   } catch (EntityNotFoundException e) {
     throw new RuntimeException("Get: TaskData with " + keyname + " not found");
   }
 }
예제 #9
0
 public void checkRocketCollision() {
   if (current_Player.isRocket()) {
     if (current_Player == player_1) {
       if (sch.getBounds().intersects(player_2.getBounds())) {
         player_2.setTp(player_2.getTp() - 25);
         current_Player.setRocket(false);
       }
     } else if (current_Player == player_2) {
       if (sch.getBounds().intersects(player_1.getBounds())) {
         player_1.setTp(player_1.getTp() - 25);
         current_Player.setRocket(false);
       }
     }
     if (sch.getBounds().intersects(0, h - 50, w, 25)
         || sch.getBounds().intersects(0, 0, w, 25)
         || sch.getBounds().intersects(0, 0, 25, h)
         || sch.getBounds().intersects(w - 35, 0, 30, h)) {
       current_Player.setRocket(false);
     }
   }
 }
예제 #10
0
 @PUT
 @Consumes(MediaType.APPLICATION_XML)
 public Response putTaskData(String value) {
   Response res = null;
   // add your code here
   // first check if the Entity exists in the datastore
   DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
   MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
   syncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));
   Key entKey = KeyFactory.createKey("TaskData", keyname);
   Date date = new Date();
   try {
     // if it is, signal that we updated the entity
     Entity ts = datastore.get(entKey);
     ts.setProperty("value", value);
     ts.setProperty("date", date);
     datastore.put(ts);
     res = Response.noContent().build();
   } catch (EntityNotFoundException e) {
     // if it is not, create it and
     // signal that we created the entity in the datastore
     Entity taskdata = new Entity("TaskData", keyname);
     taskdata.setProperty("value", value);
     taskdata.setProperty("date", date);
     datastore.put(taskdata);
     res = Response.created(uriInfo.getAbsolutePath()).build();
   }
   TaskData td = new TaskData(keyname, value, date);
   syncCache.put(keyname, td);
   return res;
 }
예제 #11
0
  public boolean tryDamageSkill(String rem, String cut, String output) {

    if (cut.length() > 0)
      if (rem.indexOf(cut) == 0) {
        rem = rem.substring(cut.length(), rem.length());
        rem = Utility.clearWhiteSpace(rem);
      }

    target = owner.getRoom().findEntity(owner, rem);

    if ((target == null) && (owner.getPlayerState() == Utility.PSTATE_FIGHTING))
      target = owner.getTarget();

    if (target == null) {
      owner.echo(output);
      return false;
    }

    if (!Combat.canAttack(owner, target, false, true)) return false;

    tn = target.getName();
    Tn = target.getPName();
    ty = Utility.possessive(tn);
    Ty = Utility.possessive(Tn);

    return true;
  }
예제 #12
0
 // for the browser
 @GET
 @Produces(MediaType.TEXT_XML)
 public TaskData getTaskDataHTML() {
   // add your code here (get Entity from datastore using this.keyname)
   // throw new RuntimeException("Get: TaskData with " + keyname +  " not found");
   // if not found
   DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
   MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
   if (syncCache.get(keyname) != null) {
     TaskData ts = (TaskData) syncCache.get(keyname);
     return ts;
   }
   Key entKey = KeyFactory.createKey("TaskData", keyname);
   try {
     Entity ent = datastore.get(entKey);
     TaskData ts =
         new TaskData(keyname, (String) ent.getProperty("value"), (Date) ent.getProperty("date"));
     return ts;
   } catch (EntityNotFoundException e) {
     throw new RuntimeException("Get: TaskData with " + keyname + " not found");
   }
 }
예제 #13
0
  public boolean trainPeaceful() {

    if (level >= 100) return false;

    int max = learnRate * ((level / 20) + 1);

    timesUsed++;

    if ((timesUsed % max) != 0) return false;

    level++;
    owner.echo(name + " has improved!");

    return true;
  }
예제 #14
0
 public void checkCollisions() {
   if (current_Player.getBounds().intersects(other_Player.getBounds())
       || current_Player.getBounds().intersects(0, h - 50, w, 25)
       || current_Player.getBounds().intersects(0, 0, w, 25)
       || current_Player.getBounds().intersects(0, 0, 25, h)
       || current_Player.getBounds().intersects(w - 35, 0, 30, h)) {
     current_Player.setCollision(true);
     if (timecount == 0) timecount = 50;
   } else current_Player.setCollision(false);
 }
예제 #15
0
  private void drawHealthBar(Graphics g, Entity entity, int xOffset, int yOffset) {
    int width = entity.getTexture().getWidth();
    float xPos = entity.getX() + xOffset;

    int height = entity.getTexture().getHeight();
    float yPos = entity.getY() + yOffset + height;

    g.setColor(new Color(200, 0, 0));
    g.fillRect(xPos, yPos, width, 3);
    g.setColor(new Color(0, 200, 0));
    g.fillRect(xPos, yPos, width * (entity.getHealth() / entity.getMaxHealth()), 3);
  }
예제 #16
0
  private String valueToHtml(final Entity entity, final Entity point, final Value value) {
    final StringBuilder sb = new StringBuilder(SIZE);
    if (!(Double.compare(value.getDoubleValue(), Const.CONST_IGNORED_NUMBER_VALUE) == 0)) {
      sb.append("<img style=\"float:left\" src=\"")
          .append(ServerInfoImpl.getFullServerURL(this.getThreadLocalRequest()));

      switch (value.getAlertState()) {
        case LowAlert:
          sb.append("/resources/images/point_low.png\">");
          break;
        case HighAlert:
          sb.append("/resources/images/point_high.png\">");
          break;
        case IdleAlert:
          sb.append("/resources/images/point_idle.png\">");
          break;
        case OK:
          sb.append("/resources/images/point_ok.png\">");
          break;
      }
    }

    if (entity != null && point != null) {

      sb.append("&nbsp;");

      if (!(Double.compare(value.getDoubleValue(), Const.CONST_IGNORED_NUMBER_VALUE) == 0)) {
        sb.append("Alert&nbsp;Status:").append(value.getAlertState().name());
        sb.append("<br>Value:").append(value.getDoubleValue());
      }

      if (!Utils.isEmptyString(value.getNote())) {
        sb.append("<br>Note:").append(value.getNote());
      }

      sb.append("<a href=\"#\" onclick=\"window.open('report.html?uuid=")
          .append(point.getKey())
          .append("', 'Report',")
          .append("'height=800,width=800,toolbar=0,status=0,location=0' );\" >")
          .append("&nbsp;[more]</a>");
    }

    return sb.toString();
  }
예제 #17
0
 public void checkPopupCollision() {
   for (int i = 0; i < 8; i++) {
     if (powerUps[i].isAktiv()
         && current_Player
             .getBounds()
             .intersects(powerUps[i].getX(), powerUps[i].getY(), 10, 10)) {
       powerUps[i].setAktiv(false);
       if (powerUps[i].getChange().equals("HP"))
         current_Player.setTp(current_Player.getTp() + powerUps[i].getChangeValue());
       if (powerUps[i].getChange().equals("SP"))
         current_Player.setSpeed(powerUps[i].getChangeValue());
       if (powerUps[i].getChange().equals("BP"))
         current_Player.setBp(current_Player.getBp() + powerUps[i].getChangeValue());
     }
   }
 }
예제 #18
0
파일: FileGen.java 프로젝트: asanian/GenNet
  public void treatmentDotAutomate() {
    try {
      PrintWriter file = new PrintWriter(new FileWriter(destination));

      file.println("digraph G {");
      for (int i = 0; i < auto.vTrans.size(); i++) {
        Trans trans = (Trans) auto.vTrans.get(i);

        for (int j = 0; j < auto.vEntity.size(); j++) {
          Entity etape = (Entity) auto.vEntity.get(j);
          if (etape.getNum() == trans.getNumInitialEnt()) {
            file.print(etape.getLabel());
          }
        }
        file.print("->");
        for (int j = 0; j < auto.vEntity.size(); j++) {
          Entity etape = (Entity) auto.vEntity.get(j);
          if (etape.getNum() == trans.getNumFinalEnt()) {
            file.print(etape.getLabel());
          }
        }
        file.print(" [label=\"");
        file.print(trans.getThreshold());

        // recuperation du signe
        if (trans.getSign() == 1) {
          file.print("+");
        } else {
          file.print("-");
        }
        file.println("\"];");
      }
      file.println("}");
      file.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #19
0
  /**
   * Output a specific entity to the specified stream.
   *
   * @param model The world model to export
   * @param entityID The entity to export
   * @param fw The stream to write to
   */
  public void export(WorldModel model, int entityID, Writer fw, String worldURL) {

    super.export(model, entityID, fw);

    Entity[] toolValues = ((BaseWorldModel) model).getModelData();

    Entity entity = toolValues[entityID];

    if (entity == null) {
      // errorReporter.messageReport("Cannot find model to export: " + entityID);
      return;
    }

    if (entity.isController()) {
      return;
    }

    try {
      fw.write(header);

      fw.write("<!-- Begin entity: " + entity.getEntityID() + "-->\n");

      // if the entity has a position then place it
      if (entity instanceof PositionableEntity) {

        double[] position = new double[3];
        float[] rotation = new float[4];
        float[] scale = new float[3];

        ((PositionableEntity) entity).getPosition(position);
        ((PositionableEntity) entity).getRotation(rotation);
        ((PositionableEntity) entity).getScale(scale);

        fw.write(
            "    <Transform "
                + "translation='"
                + position[0]
                + " "
                + position[1]
                + " "
                + position[2]
                + "' "
                + "rotation='"
                + rotation[0]
                + " "
                + rotation[1]
                + " "
                + rotation[2]
                + " "
                + rotation[3]
                + "' "
                + "scale='"
                + scale[0]
                + " "
                + scale[1]
                + " "
                + scale[2]
                + "' >\n");
      }

      // inline the model
      String url = entity.getModelURL();

      fw.write("        <Inline url='" + worldURL + url + "' />\n");

      // if the entity has a position then place it
      if (entity instanceof PositionableEntity) {
        fw.write("    </Transform>\n");
      }

      fw.write("<!-- End entity: " + entity.getEntityID() + "-->\n");

      fw.write("</Scene>\n");
      fw.write("</X3D>\n");

      fw.close();
    } catch (IOException ioe) {
      errorReporter.errorReport("IO Error.", ioe);
    }
  }
예제 #20
0
  @EventHandler
  public void onPacketProcess(PacketProcessEvent event) {
    Packet packet = event.getPacket();
    if (packet instanceof Packet5PlayerInventory) {
      Packet5PlayerInventory inventoryPacket = (Packet5PlayerInventory) packet;
      Entity entity = getEntityById(inventoryPacket.entityID);
      if (entity == null || !(entity instanceof LivingEntity)) return;
      LivingEntity livingEntity = (LivingEntity) entity;
      livingEntity.setWornItemAt(inventoryPacket.slot, inventoryPacket.item);
    } else if (packet instanceof Packet8UpdateHealth) {
      Packet8UpdateHealth updateHealthPacket = (Packet8UpdateHealth) packet;
      MainPlayerEntity player = bot.getPlayer();
      player.setHealth(updateHealthPacket.healthMP);
      player.setHunger(updateHealthPacket.food);
    } else if (packet instanceof Packet9Respawn) {
      synchronized (chunks) {
        chunks.clear();
      }
    } else if (packet instanceof Packet20NamedEntitySpawn) {
      Packet20NamedEntitySpawn spawnPacket = (Packet20NamedEntitySpawn) packet;
      PlayerEntity entity = new PlayerEntity(this, spawnPacket.entityId, spawnPacket.name);
      entity.setX(spawnPacket.xPosition / 32D);
      entity.setY(spawnPacket.yPosition / 32D);
      entity.setZ(spawnPacket.zPosition / 32D);
      entity.setYaw(spawnPacket.rotation);
      entity.setPitch(spawnPacket.pitch);
      entity.setWornItemAt(0, new BasicItemStack(spawnPacket.currentItem, 1, 0));
      spawnEntity(entity);
    } else if (packet instanceof Packet21PickupSpawn) {
      Packet21PickupSpawn spawnPacket = (Packet21PickupSpawn) packet;
      ItemEntity entity = new ItemEntity(this, spawnPacket.entityId, spawnPacket.item);
      entity.setX(spawnPacket.xPosition / 32D);
      entity.setY(spawnPacket.yPosition / 32D);
      entity.setZ(spawnPacket.zPosition / 32D);
      spawnEntity(entity);
    } else if (packet instanceof Packet22Collect) {
      Entity entity = getEntityById(((Packet22Collect) packet).collectedEntityId);
      if (entity != null) despawnEntity(entity);
    } else if (packet instanceof Packet23VehicleSpawn) {
      Packet23VehicleSpawn spawnPacket = (Packet23VehicleSpawn) packet;
      Entity entity = null;
      Class<? extends Entity> entityClass = EntityList.getObjectEntityClass(spawnPacket.type);
      if (entityClass == null) return;
      try {
        Constructor<? extends Entity> constructor =
            entityClass.getConstructor(World.class, Integer.TYPE);
        entity = constructor.newInstance(this, spawnPacket.entityId);
      } catch (Exception exception) {
        exception.printStackTrace();
        return;
      }
      entity.setX(spawnPacket.xPosition / 32D);
      entity.setY(spawnPacket.yPosition / 32D);
      entity.setZ(spawnPacket.zPosition / 32D);
      entity.setYaw(0);
      entity.setPitch(0);
      spawnEntity(entity);
    } else if (packet instanceof Packet24MobSpawn) {
      Packet24MobSpawn mobSpawnPacket = (Packet24MobSpawn) packet;
      LivingEntity entity = null;
      Class<? extends LivingEntity> entityClass =
          EntityList.getLivingEntityClass(mobSpawnPacket.type);
      if (entityClass == null) return;
      try {
        Constructor<? extends LivingEntity> constructor =
            entityClass.getConstructor(World.class, Integer.TYPE);
        entity = constructor.newInstance(this, mobSpawnPacket.entityId);
      } catch (Exception exception) {
        exception.printStackTrace();
        return;
      }
      entity.setX(mobSpawnPacket.xPosition / 32D);
      entity.setY(mobSpawnPacket.yPosition / 32D);
      entity.setZ(mobSpawnPacket.zPosition / 32D);
      entity.setYaw((mobSpawnPacket.yaw * 360) / 256F);
      entity.setPitch((mobSpawnPacket.pitch * 360) / 256F);
      entity.setHeadYaw((mobSpawnPacket.headYaw * 360) / 256F);

      if (mobSpawnPacket.getMetadata() != null) entity.updateMetadata(mobSpawnPacket.getMetadata());
      spawnEntity(entity);
    } else if (packet instanceof Packet25EntityPainting) {
      Packet25EntityPainting paintingPacket = (Packet25EntityPainting) packet;
      PaintingEntity entity =
          new PaintingEntity(
              this, paintingPacket.entityId, ArtType.getArtTypeByName(paintingPacket.title));
      entity.setX(paintingPacket.xPosition);
      entity.setY(paintingPacket.yPosition);
      entity.setZ(paintingPacket.zPosition);
      entity.setDirection(paintingPacket.direction);
      spawnEntity(entity);
    } else if (packet instanceof Packet26EntityExpOrb) {

    } else if (packet instanceof Packet29DestroyEntity) {
      Packet29DestroyEntity destroyEntityPacket = (Packet29DestroyEntity) packet;
      for (int id : destroyEntityPacket.entityIds) {
        Entity entity = getEntityById(id);
        if (entity != null) {
          despawnEntity(entity);
          entity.setDead(true);
        }
      }
    } else if (packet instanceof Packet30Entity) {
      Packet30Entity entityPacket = (Packet30Entity) packet;
      Entity entity = getEntityById(entityPacket.entityId);
      if (entity == null) return;
      entity.setX(entity.getX() + (entityPacket.xPosition / 32D));
      entity.setY(entity.getY() + (entityPacket.yPosition / 32D));
      entity.setZ(entity.getZ() + (entityPacket.zPosition / 32D));
      if (packet instanceof Packet31RelEntityMove || packet instanceof Packet33RelEntityMoveLook) {
        entity.setYaw((entityPacket.yaw * 360) / 256F);
        entity.setPitch((entityPacket.pitch * 360) / 256F);
      }
    } else if (packet instanceof Packet34EntityTeleport) {
      Packet34EntityTeleport teleportPacket = (Packet34EntityTeleport) packet;
      Entity entity = getEntityById(teleportPacket.entityId);
      if (entity == null) return;
      entity.setX(teleportPacket.xPosition / 32D);
      entity.setY(teleportPacket.yPosition / 32D);
      entity.setZ(teleportPacket.zPosition / 32D);
      entity.setYaw((teleportPacket.yaw * 360) / 256F);
      entity.setPitch((teleportPacket.pitch * 360) / 256F);
    } else if (packet instanceof Packet35EntityHeadRotation) {
      Packet35EntityHeadRotation headRotatePacket = (Packet35EntityHeadRotation) packet;
      Entity entity = getEntityById(headRotatePacket.entityId);
      if (entity == null || !(entity instanceof LivingEntity)) return;
      ((LivingEntity) entity).setHeadYaw((headRotatePacket.headRotationYaw * 360) / 256F);
    } else if (packet instanceof Packet39AttachEntity) {
      Packet39AttachEntity attachEntityPacket = (Packet39AttachEntity) packet;
      Entity rider = getEntityById(attachEntityPacket.entityId);
      if (rider == null) return;
      Entity riding = null;
      if (attachEntityPacket.vehicleEntityId == -1) {
        if (rider.getRiding() != null) {
          rider.getRiding().setRider(null);
          rider.setRiding(null);
        }
      } else {
        riding = getEntityById(attachEntityPacket.vehicleEntityId);
        if (riding == null) return;
        rider.setRiding(riding);
        riding.setRider(rider);
      }
    } else if (packet instanceof Packet40EntityMetadata) {
      Packet40EntityMetadata metadataPacket = (Packet40EntityMetadata) packet;
      Entity entity = getEntityById(metadataPacket.entityId);
      if (entity == null) return;
      entity.updateMetadata(metadataPacket.getMetadata());
    } else if (packet instanceof Packet43Experience) {
      Packet43Experience experiencePacket = (Packet43Experience) packet;
      MainPlayerEntity player = bot.getPlayer();
      player.setExperienceLevel(experiencePacket.experienceLevel);
      player.setExperienceTotal(experiencePacket.experienceTotal);
    } else if (packet instanceof Packet51MapChunk) {
      if (bot.isMovementDisabled()) return;
      Packet51MapChunk mapChunkPacket = (Packet51MapChunk) packet;
      processChunk(
          mapChunkPacket.x,
          mapChunkPacket.z,
          mapChunkPacket.chunkData,
          mapChunkPacket.bitmask,
          mapChunkPacket.additionalBitmask,
          true,
          mapChunkPacket.biomes);
    } else if (packet instanceof Packet52MultiBlockChange) {
      Packet52MultiBlockChange multiBlockChangePacket = (Packet52MultiBlockChange) packet;
      if (multiBlockChangePacket.metadataArray == null) return;
      DataInputStream datainputstream =
          new DataInputStream(new ByteArrayInputStream(multiBlockChangePacket.metadataArray));
      try {
        for (int i = 0; i < multiBlockChangePacket.size; i++) {
          short word0 = datainputstream.readShort();
          short word1 = datainputstream.readShort();
          int id = (word1 & 0xfff) >> 4;
          int metadata = word1 & 0xf;
          int x = word0 >> 12 & 0xf;
          int z = word0 >> 8 & 0xf;
          int y = word0 & 0xff;
          setBlockIdAt(
              id,
              (multiBlockChangePacket.xPosition * 16) + x,
              y,
              (multiBlockChangePacket.zPosition * 16) + z);
          setBlockMetadataAt(
              metadata,
              (multiBlockChangePacket.xPosition * 16) + x,
              y,
              (multiBlockChangePacket.zPosition * 16) + z);
        }
      } catch (IOException exception) {
        exception.printStackTrace();
      }
    } else if (packet instanceof Packet53BlockChange) {
      Packet53BlockChange blockChangePacket = (Packet53BlockChange) packet;
      setBlockIdAt(
          blockChangePacket.type,
          blockChangePacket.xPosition,
          blockChangePacket.yPosition,
          blockChangePacket.zPosition);
      setBlockMetadataAt(
          blockChangePacket.metadata,
          blockChangePacket.xPosition,
          blockChangePacket.yPosition,
          blockChangePacket.zPosition);
    } else if (packet instanceof Packet56MapChunks) {
      if (bot.isMovementDisabled()) return;
      Packet56MapChunks chunkPacket = (Packet56MapChunks) packet;
      for (int i = 0; i < chunkPacket.primaryBitmap.length; i++)
        processChunk(
            chunkPacket.chunkX[i],
            chunkPacket.chunkZ[i],
            chunkPacket.chunkData[i],
            chunkPacket.primaryBitmap[i],
            chunkPacket.secondaryBitmap[i],
            chunkPacket.skylight,
            true);
    }
  }
예제 #21
0
  public void trainPassive(Skill Sk) {

    owner.getRoom().setSkillRedirect(true);
    Sk.train();
    owner.getRoom().setSkillRedirect(false);
  }
예제 #22
0
  public void drawBuffer() {
    Graphics2D b = buffer.createGraphics(); // DrawPanel
    Graphics2D pl_b = buffer.createGraphics();
    Graphics2D pl_c = buffer.createGraphics();
    rkt = buffer.createGraphics();
    AffineTransform rkt_aff = new AffineTransform();
    Graphics2D envi[] = new Graphics2D[amountEnv];
    AffineTransform enviTrans[] = new AffineTransform[amountEnv];

    b.setColor(Color.BLACK);
    b.fillRect(0, 0, w, h);

    // #if (Default)
    // @
    // #elif (Blue_White)
    // @        	ii_bg = new ImageIcon("imgs/Hintergrund/HgBlauWeiss1.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Blue_White_Green)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/HgBlauWeissGruen.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Purple_White)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/HgLilaWeiss.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Glass)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundglass05.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Lava)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundlava01.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Limba)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundlimba.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Old)
    ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundoldpnt01.gif");
    img_bg = ii_bg.getImage();
    b.drawImage(img_bg, w, w, this);
    // #elif (Ov_Paper)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundov_paper.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Paper)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundpaper05.gif");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Univ)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrunduniv01.jpg");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Water)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundwater01.jpg");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #elif (Water_2)
    // @            ii_bg = new ImageIcon("imgs/Hintergrund/Hintergrundwater05.jpg");
    // @            img_bg = ii_bg.getImage();
    // @            b.drawImage(img_bg, w, w, this);
    // #endif

    b.setColor(Color.gray);
    b.fillRect(0, 0, w, 25); // oben
    b.fillRect(0, h - 50, w, 25); // unten
    b.fillRect(0, 0, 25, h); // links
    b.fillRect(w - 35, 0, 30, h); // rechts
    b.setColor(Color.WHITE);

    // rocket
    // #if (tar)
    // #if (Rectangle)
    // @               if (current_Player.isRocket()){
    // @                   rkt_aff.rotate(current_Player.getDegree(), sch.getX(), sch.getY());
    // @                   rkt.setTransform(rkt_aff);
    // @                   System.out.println("Rok X:"+sch.getX()+" Rok Y:"+sch.getY());
    // @                   rkt.drawRect(sch.getX()+ current_Player.getWidth()/2, sch.getY() +
    // current_Player.getHeight()/2, kaliber, kaliber);} // Rocket 4Eck
    // #endif
    // #if (Oval)
    // @               if (current_Player.isRocket()){
    // @                   b.drawOval(sch.getX()+ current_Player.getWidth()/2, sch.getY() +
    // current_Player.getHeight()/2, kaliber, kaliber);} // Rocket Oval
    // #endif
    // #if (aa31)
    // @                 if (current_Player.isRocket()){
    // @                     try {
    // @                        rocketFire = ImageIO.read(new File("imgs/aa31.gif"));
    // @                        rkt_aff.rotate(current_Player.getDegree(), sch.getX(), sch.getY());
    // @                        rkt.setTransform(rkt_aff);
    // @                        rkt.drawImage(rocketFire, null, (int)sch.getX(), (int)sch.getY());
    // @                        //rkt.drawImage(rocketFire, null, (int)current_Player.getX(),
    // (int)current_Player.getY());
    // @                    } catch (IOException e) {
    // @                    }
    // @                 }
    // #endif
    // #if (Portal)
    // @                 if (current_Player.isRocket()){
    // @                     try {
    // @                        rocketFire = ImageIO.read(new File("imgs/portal.gif"));
    // @                        rkt_aff.rotate(current_Player.getDegree(), sch.getX(), sch.getY());
    // @                        rkt.setTransform(rkt_aff);
    // @                        rkt.drawImage(rocketFire, null,
    // sch.getX()+current_Player.getWidth()/2, sch.getY()+current_Player.getHeight()/2);
    // @                     } catch (IOException e) {
    // @                     }
    // @                 }
    // #endif
    // #if (Nino)
    // @                 if (current_Player.isRocket()){
    // @                     try {
    // @                        rocketFire = ImageIO.read(new File("imgs/nino.gif"));
    // @                        rkt_aff.rotate(current_Player.getDegree(), sch.getX(), sch.getY());
    // @                        rkt.setTransform(rkt_aff);
    // @                        rkt.drawImage(rocketFire, null,
    // sch.getX()+current_Player.getWidth()/2, sch.getY()+current_Player.getHeight()/2);
    // @                     } catch (IOException e) {
    // @                     }
    // @                 }
    // #endif
    // #endif

    for (int i = 0; i <= amountEnv - 1; i++) {
      envi[i] = buffer.createGraphics();
      enviTrans[i] = new AffineTransform();
      envi[i].setTransform(enviTrans[i]);
      envi[i].drawImage(env[i].getImg(), env[i].getX(), env[i].getY(), this);
    }

    for (int i = 0; i < 8; i++) {
      if (powerUps[i].isAktiv()) {
        b.setColor(powerUps[i].getCol());
        b.drawImage(powerUps[i].getImg(), powerUps[i].getX(), powerUps[i].getY(), this);
      }
    }

    b.setColor(Color.WHITE);
    b.drawString("BP: " + current_Player.getBp(), 10, 20);
    b.drawString("TP P1/P2: " + player_1.getTp() + " / " + player_2.getTp(), 100, 20);

    if (current_Player.getSch().getEnd_X() != 0 && current_Player.getSch().getEnd_Y() != 0) {
      b.setColor(Color.YELLOW);
      b.drawLine(
          (int) current_Player.getSch().getStart_X(),
          (int) current_Player.getSch().getStart_Y(),
          (int) current_Player.getSch().getEnd_X(),
          (int) current_Player.getSch().getEnd_Y());
      b.setColor(Color.WHITE);
      for (int i = 0; i < current_Player.getSch().getArImg().length; i++) {
        if (current_Player.getSch().getArImg()[i] != null && current_Player.getSch().isIsActive()) {
          b.drawImage(
              current_Player.getSch().getArImg()[i],
              (int) current_Player.getSch().getEnd_X()
                  - current_Player.getSch().getArImg()[i].getWidth(this) / 2,
              (int) current_Player.getSch().getEnd_Y()
                  - current_Player.getSch().getArImg()[i].getHeight(this) / 2,
              (int)
                  (current_Player.getSch().getArImg()[i].getWidth(this)
                      * (current_Player.getSch().getSpeed() / 150)),
              (int)
                  (current_Player.getSch().getArImg()[i].getHeight(this)
                      * (current_Player.getSch().getSpeed() / 150)),
              this);
          if (timeCounter == 75) {
            System.out.println("----------------------><---------------------");
            if (player_1
                .getBounds()
                .intersects(
                    (int) current_Player.getSch().getEnd_X()
                        - current_Player.getSch().getArImg()[i].getWidth(this) / 2,
                    (int) current_Player.getSch().getEnd_Y()
                        - current_Player.getSch().getArImg()[i].getHeight(this) / 2,
                    (int)
                        (current_Player.getSch().getArImg()[i].getWidth(this)
                            * (current_Player.getSch().getSpeed() / 150)),
                    (int)
                        (current_Player.getSch().getArImg()[i].getHeight(this)
                            * (current_Player.getSch().getSpeed() / 150)))) {
              player_1.setTp(player_1.getTp() - (int) current_Player.getSch().getSpeed() / 4);
              System.out.println("----------------------> P1 <---------------------");
            }
            if (player_2
                .getBounds()
                .intersects(
                    (int) current_Player.getSch().getEnd_X()
                        - current_Player.getSch().getArImg()[i].getWidth(this) / 2,
                    (int) current_Player.getSch().getEnd_Y()
                        - current_Player.getSch().getArImg()[i].getHeight(this) / 2,
                    (int)
                        (current_Player.getSch().getArImg()[i].getWidth(this)
                            * (current_Player.getSch().getSpeed() / 150)),
                    (int)
                        (current_Player.getSch().getArImg()[i].getHeight(this)
                            * (current_Player.getSch().getSpeed() / 150)))) {
              player_2.setTp(player_2.getTp() - (int) current_Player.getSch().getSpeed() / 4);
              System.out.println("----------------------> P2 <---------------------");
            }
          }
        }
        if (timeCounter >= 150) {
          timeCounter = 0;
          current_Player.getSch().setIsActive(false);
          current_Player.getSch().setEnd_X(0);
          current_Player.getSch().setEnd_Y(0);
        }
        if (current_Player.getSch().isIsActive()) timeCounter += 1;
        System.out.println("timecounter: " + timeCounter);
      }
    }

    if (player_1.getTp() <= 0) b.drawString("SPIELER 2 HAT GEWONNEN !", w / 2, h / 2);
    if (player_2.getTp() <= 0) b.drawString("SPIELER 1 HAT GEWONNEN !", w / 2, h / 2);

    current_Player.setStop(false);
    b.setColor(Color.red);

    AffineTransform a = new AffineTransform();
    a.rotate(
        current_Player.getDegree(),
        current_Player.getX() + current_Player.getWidth() / 2,
        current_Player.getY() + current_Player.getHeight() / 2);
    ((Graphics2D) pl_b).setTransform(a);
    pl_b.drawImage(
        current_Player.getImg(), (int) current_Player.getX(), (int) current_Player.getY(), this);
    System.out.println(
        "P1 X:" + (int) current_Player.getX() + " P1 Y:" + (int) current_Player.getY());
    System.out.println("P1 W:" + current_Player.getWidth() + " P1 H:" + current_Player.getHeight());
    AffineTransform a2 = new AffineTransform();
    a2.rotate(
        other_Player.getDegree(),
        other_Player.getX() + other_Player.getWidth() / 2,
        other_Player.getY() + other_Player.getHeight() / 2);
    ((Graphics2D) pl_c).setTransform(a2);
    pl_c.drawImage(
        other_Player.getImg(), (int) other_Player.getX(), (int) other_Player.getY(), this);

    if (current_Player.isCollision() == true) {
      current_Player.setStop(true);
      if (timecount > 10) {
        b.setColor(Color.WHITE);
        b.drawString("C O L L I S I O N !", (int) w / 2 - 50, (int) h / 2);
        timecount--;
      } else {
        timecount = 0;
        current_Player.setBp(0);
        current_Player.setX(300);
        current_Player.setY(100);
        current_Player.getSch().setEnd_X(1);
        current_Player.getSch().setEnd_Y(1);
        current_Player.getSch().setStart_X(1);
        current_Player.getSch().setStart_Y(1);
      }
      b.dispose();
    }
  }
  @Override
  public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    resp.setContentType("text/html");
    resp.getWriter().println("<html><body>");

    String keyname = req.getParameter("keyname");
    String value = req.getParameter("value");

    DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
    // Using the synchronous cache.
    MemcacheService syncCache = MemcacheServiceFactory.getMemcacheService();
    syncCache.setErrorHandler(ErrorHandlers.getConsistentLogAndContinue(Level.INFO));

    // display every element of kind TaskData for /datastore
    if (req.getParameterMap().isEmpty()) {
      // querying from datastore
      resp.getWriter().println("<h3>Datastore results:</h3>");
      List<String> listOfKeys = new ArrayList<String>();
      Query q = new Query("TaskData");
      PreparedQuery pq = datastore.prepare(q);
      for (Entity result : pq.asIterable()) {
        String datastore_key = result.getKey().getName();
        String taskData_value = (String) result.getProperty("value");
        Date taskData_date = (Date) result.getProperty("date");
        resp.getWriter()
            .println(
                "<p>keyname = "
                    + datastore_key
                    + "  value = "
                    + taskData_value
                    + " date = "
                    + taskData_date.toString()
                    + "</p>");
        listOfKeys.add(datastore_key);
      }
      // check which of the keys exist in memcache
      String memcache_value;
      resp.getWriter().println("<h3>Memcache results:</h3>");
      for (String datastore_key : listOfKeys) {
        memcache_value = (String) syncCache.get(datastore_key);
        if (memcache_value != null) {
          // String decoded = new String(memcache_value, "UTF-8");
          resp.getWriter()
              .println("<p>keyname = " + datastore_key + " value = " + memcache_value + "</p>");
        }
      }
    }

    // display element of kind TaskData with key=keyname
    else if (keyname != null && value == null) {

      // first check in the cache
      String memcache_value = (String) syncCache.get(keyname); // Read from cache.
      // Get value from datastore
      Key task_key = KeyFactory.createKey("TaskData", keyname);
      try {
        Entity tne = datastore.get(task_key);
        if (memcache_value == null) {
          resp.getWriter().println("<h2>Datastore</h2>");
        } else {
          resp.getWriter().println("<h2>Both</h2>");
        }

      } catch (EntityNotFoundException e) {
        resp.getWriter().println("<h2>Neither</h2>");
      }
    }

    // store element of kind TaskData with key=keyname and value=value
    else if (keyname != null && value != null) {
      Entity tne = new Entity("TaskData", keyname);
      tne.setProperty("value", value);
      tne.setProperty("date", new Date());
      datastore.put(tne);
      syncCache.put(keyname, value); // Populate cache.
      resp.getWriter()
          .println("<h2>Stored " + keyname + " and " + value + " in Datastore and Memcache</h2>");
    } else {

      resp.getWriter().println("<h2>You entered wrong query parameters</h2>");
    }

    /*
       Entity tne = new Entity("TaskData", "Person");
    alice.setProperty("gender", "female");
    alice.setProperty("age", 20);
    */

    resp.getWriter().println("</body></html>");
  }
예제 #24
0
 // Bewegung - Normal
 private void changepl() {
   // #if (mov_0)
   current_Player.setBp(250);
   current_Player.getSch().setStart_X(0);
   current_Player.getSch().setStart_Y(0);
   current_Player.getSch().setEnd_X(0);
   current_Player.getSch().setEnd_Y(0);
   current_Player.getSch().setterStart_time(0);
   current_Player.getSch().setterEnd_time(0);
   if (current_Player == player_1) {
     current_Player = player_2;
     other_Player = player_1;
   } else {
     current_Player = player_1;
     other_Player = player_2;
   }
   // #endif
   // #if (mov_1)
   // @           current_Player.setBp(0);
   // @           current_Player.getSch().setStart_X(0);
   // @           current_Player.getSch().setStart_Y(0);
   // @           current_Player.getSch().setEnd_X(0);
   // @           current_Player.getSch().setEnd_Y(0);
   // @           current_Player.getSch().setterStart_time(0);
   // @           current_Player.getSch().setterEnd_time(0);
   // @           current_Player.setLoad(0);
   // @           if (current_Player == player_1){
   // @               current_Player = player_2;
   // @               other_Player = player_1;
   // @           }
   // @           else{
   // @               current_Player = player_1;
   // @               other_Player = player_2;
   // @           }
   // #endif
   // #if (mov_2)
   // @           current_Player.setBp(250);
   // @           current_Player.getSch().setStart_X(0);
   // @           current_Player.getSch().setStart_Y(0);
   // @           current_Player.getSch().setEnd_X(0);
   // @           current_Player.getSch().setEnd_Y(0);
   // @           current_Player.getSch().setterStart_time(0);
   // @           current_Player.getSch().setterEnd_time(0);
   // @           if (current_Player == player_1){
   // @               current_Player = player_2;
   // @               other_Player = player_1;
   // @           }
   // @           else{
   // @               current_Player = player_1;
   // @               other_Player = player_2;
   // @           }
   // #elif (mov_3)
   // @           current_Player.setBp(0);
   // @           current_Player.getSch().setStart_X(0);
   // @           current_Player.getSch().setStart_Y(0);
   // @           current_Player.getSch().setEnd_X(0);
   // @           current_Player.getSch().setEnd_Y(0);
   // @           current_Player.getSch().setterStart_time(0);
   // @           current_Player.getSch().setterEnd_time(0);
   // @           current_Player.setLoad(0);
   // @           if (current_Player == player_1){
   // @               current_Player = player_2;
   // @               other_Player = player_1;
   // @           }
   // @           else{
   // @               current_Player = player_1;
   // @               other_Player = player_2;
   // @           }
   // #elif (mov_4)
   // @           current_Player.setBp(0);
   // @           current_Player.getSch().setStart_X(0);
   // @           current_Player.getSch().setStart_Y(0);
   // @           current_Player.getSch().setEnd_X(0);
   // @           current_Player.getSch().setEnd_Y(0);
   // @           current_Player.getSch().setterStart_time(0);
   // @           current_Player.getSch().setterEnd_time(0);
   // @           current_Player.setLoad(0);
   // @           if (current_Player == player_1){
   // @               current_Player = player_2;
   // @               other_Player = player_1;
   // @           }
   // @           else{
   // @               current_Player = player_1;
   // @               other_Player = player_2;
   // @           }
   // #endif
 }
예제 #25
0
  public void keyPressed(KeyEvent e) {
    // #if (mov_0)
    int key = e.getKeyCode();
    if (key == KeyEvent.VK_LEFT) {
      current_Player.setLeft(true);
    }
    if (key == KeyEvent.VK_RIGHT) {
      current_Player.setRight(true);
    }
    if (key == KeyEvent.VK_DOWN) current_Player.setDown(true);
    if (key == KeyEvent.VK_UP) current_Player.setUp(true);
    if (key == KeyEvent.VK_SHIFT) current_Player.setSpeed(3);
    if (key == KeyEvent.VK_ENTER) if (current_Player.getSch().isIsActive() == false) changepl();
    if (key == KeyEvent.VK_F1) ls.createNewPlayer();
    // #if(tar)
    // @            if (key == KeyEvent.VK_Q){
    // @               // current_Player.setRocket(true);
    // @               // sch = new Schuss((int)current_Player.getX(),(int)current_Player.getY());
    // @               // current_Player.setBp(0);
    // @            }
    // #endif
    // #elif (mov_1)
    // @            int key = e.getKeyCode();
    // @            if (key == KeyEvent.VK_LEFT){
    // @                current_Player.setLeft(true);
    // @            }
    // @            if (key == KeyEvent.VK_RIGHT){
    // @                current_Player.setRight(true);
    // @            }
    // @            if (key == KeyEvent.VK_SPACE && current_Player.getLoad() < 2){
    // @                current_Player.setBp(current_Player.getBp()+5);
    // @                current_Player.setLoad(1);
    // @            }
    // @            if (key == KeyEvent.VK_DOWN) current_Player.setDown(true);
    // @            if (key == KeyEvent.VK_UP) current_Player.setUp(true);
    // @            if (key == KeyEvent.VK_SHIFT) current_Player.setSpeed(3);
    // @            if (key == KeyEvent.VK_ENTER) if (current_Player.getSch().isIsActive()==false)
    // changepl();
    // @            if (key == KeyEvent.VK_F1) ls.createNewPlayer();
    // #elif (mov_2)
    // @            int key = e.getKeyCode();
    // @            if (key == KeyEvent.VK_LEFT) current_Player.setLeft(true);
    // @            if (key == KeyEvent.VK_RIGHT) current_Player.setRight(true);
    // @            if (key == KeyEvent.VK_DOWN) current_Player.setDown(true);
    // @            if (key == KeyEvent.VK_UP) current_Player.setUp(true);
    // @            if (key == KeyEvent.VK_SHIFT) current_Player.setSpeed(3);
    // @            if (key == KeyEvent.VK_ENTER) if (current_Player.getSch().isIsActive()==false)
    // changepl();
    // @            if (key == KeyEvent.VK_F1) ls.createNewPlayer();
    // #elif (mov_3)
    // @            int key = e.getKeyCode();
    // @            if (key == KeyEvent.VK_LEFT){
    // @                current_Player.setLeft(true);
    // @            }
    // @            if (key == KeyEvent.VK_RIGHT){
    // @                current_Player.setRight(true);
    // @            }
    // @            if (key == KeyEvent.VK_SPACE){
    // @            	current_Player.setBp(current_Player.getBp()+5);
    // @            	current_Player.setLoad(1);
    // @                //current_Player.setSpeed(5);
    // @            }
    // @            if (key == KeyEvent.VK_DOWN) current_Player.setDown(true);
    // @            if (key == KeyEvent.VK_UP) current_Player.setUp(true);
    // @            if (key == KeyEvent.VK_SHIFT) current_Player.setSpeed(3);
    // @            if (key == KeyEvent.VK_ENTER) if (current_Player.getSch().isIsActive()==false)
    // changepl();
    // @            if (key == KeyEvent.VK_F1) ls.createNewPlayer();
    // #elif (mov_4)
    // @            int key = e.getKeyCode();
    // @            if (key == KeyEvent.VK_LEFT){
    // @                current_Player.setLeft(true);
    // @            }
    // @            if (key == KeyEvent.VK_RIGHT){
    // @                current_Player.setRight(true);
    // @            }
    // @            if (key == KeyEvent.VK_SPACE && current_Player.getLoad() < 2){
    // @                current_Player.setBp(current_Player.getBp()+5);
    // @                current_Player.setLoad(1);
    // @            }
    // @            if (key == KeyEvent.VK_DOWN) current_Player.setDown(true);
    // @            if (key == KeyEvent.VK_UP) current_Player.setUp(true);
    // @            if (key == KeyEvent.VK_SHIFT) current_Player.setSpeed(3);
    // @            if (key == KeyEvent.VK_ENTER) if (current_Player.getSch().isIsActive()==false)
    // changepl();
    // @            if (key == KeyEvent.VK_F1) ls.createNewPlayer();
    // #endif

    // neu beginn
    if (key == KeyEvent.VK_Q) {
      // #if (tar)
      // @            	current_Player.setRocket(true);
      // @            	sch = new Schuss((int)current_Player.getX(),(int)current_Player.getY());
      // @            	current_Player.setBp(0);
      // #endif
    }
    // neu ende
  }
예제 #26
0
  /**
   * Output the World Model to the specified stream.
   *
   * @param model The world model to export
   * @param fw The stream to write to
   */
  public void export(WorldModel model, Writer fw) {

    super.export(model, fw);

    Entity[] entities = ((BaseWorldModel) model).getModelData();

    int len = entities.length;

    try {

      fw.write(header);

      for (int i = 0; i < len; i++) {
        Entity entity = entities[i];

        if (entity == null) {
          // Its expected we will have gaps
          continue;
        }

        if (entity.isController()) {
          continue;
        }

        fw.write("<!-- Begin entity: " + entity.getEntityID() + "-->\n");

        // if the entity has a position then place it
        if (entity instanceof PositionableEntity) {

          double[] position = new double[3];
          float[] rotation = new float[4];
          float[] scale = new float[3];

          ((PositionableEntity) entity).getPosition(position);
          ((PositionableEntity) entity).getRotation(rotation);
          ((PositionableEntity) entity).getScale(scale);

          fw.write(
              "    <Transform "
                  + "translation='"
                  + position[0]
                  + " "
                  + position[1]
                  + " "
                  + position[2]
                  + "' "
                  + "rotation='"
                  + rotation[0]
                  + " "
                  + rotation[1]
                  + " "
                  + rotation[2]
                  + " "
                  + rotation[3]
                  + "' "
                  + "scale='"
                  + scale[0]
                  + " "
                  + scale[1]
                  + " "
                  + scale[2]
                  + "' >\n");
        }

        // inline the model
        String url = entity.getModelURL();
        fw.write("        <Inline url='" + url + "' />\n");

        // if the entity has a position then place it
        if (entity instanceof PositionableEntity) {
          fw.write("    </Transform>\n");
        }

        fw.write("<!-- End entity: " + entity.getEntityID() + "-->\n");
      }

      fw.write("</Scene>\n");
      fw.write("</X3D>\n");
      fw.close();

    } catch (IOException ioe) {
      errorReporter.errorReport("IO Error.", ioe);
    }
  }
예제 #27
0
  /**
   * Output a specific entity to the specified stream.
   *
   * @param model The world model to export
   * @param entityID The entity to export
   * @param mainScene The X3D scene to write to
   */
  public X3DNode export(WorldModel model, int entityID, X3DScene mainScene, String worldURL) {

    // get the entity
    Entity entity = model.getEntity(entityID);

    if (entity == null) {
      errorReporter.messageReport("Cannot find model to export: " + entityID);
      return null;
    }

    if (entity.isController()) {
      return null;
    }

    try {

      X3DNode group;

      // if the entity has a position then place it
      if (entity instanceof PositionableEntity) {

        double[] position = new double[3];
        float[] rotation = new float[4];
        float[] scale = new float[3];

        ((PositionableEntity) entity).getPosition(position);
        ((PositionableEntity) entity).getRotation(rotation);
        ((PositionableEntity) entity).getScale(scale);

        float[] pos = new float[] {(float) position[0], (float) position[1], (float) position[2]};

        // create the transform group node
        group = mainScene.createNode("Transform");
        SFVec3f translationField = (SFVec3f) (group.getField("translation"));
        translationField.setValue(pos);
        SFRotation rotationField = (SFRotation) (group.getField("rotation"));
        rotationField.setValue(rotation);
        SFVec3f scaleField = (SFVec3f) (group.getField("scale"));
        scaleField.setValue(scale);

      } else {

        // create the transform group node
        group = mainScene.createNode("Group");
      }

      // create the inline node
      String url = worldURL + entity.getModelURL();

      X3DNode inline = mainScene.createNode("Inline");
      MFString urlField = (MFString) (inline.getField("url"));
      urlField.setValue(1, new String[] {url});

      // grab the child node to append to
      MFNode childrenField = (MFNode) (group.getField("children"));

      // add inline to the group/transform
      childrenField.append(inline);

      return group;

    } catch (Exception ex) {
      errorReporter.errorReport("Error.", ex);
    }

    return null;
  }
예제 #28
0
  public void checkGameInput() {

    if (drawMode.isPressed()) {
      octree.setRenderMode(!octree.isRenderMode());
      octree.setObjectColliding(false);
      if (octree.isRenderMode()) {
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // Render the triangles in fill mode
      } else {
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // Render the triangles in wire frame mode
      }
      octree.createDisplayList(octree, g_World, octree.getDisplayListID());
    }

    if (fullScreen.isPressed()) {
      setFullScreen(!isFullScreen());
    }

    if (enter.isPressed()) {
      Octree.octreeCollisionDetection = !Octree.octreeCollisionDetection;
    }

    if (left.isPressed()) {
      camera.strafe(-SPEED / 10 * elapsedTime);
    }

    if (right.isPressed()) {

      camera.strafe(SPEED / 10 * elapsedTime);
    }

    if (zoomIn.isPressed()) {
      camera.move(+SPEED / 10 * elapsedTime);
    }
    if (zoomOut.isPressed()) {

      camera.move(-SPEED / 10 * elapsedTime);
    }

    if (moveLeft.isPressed()) {
      g_BallEntity.fAngle += (float) AR_DegToRad(g_BallEntity.fTurnRate) * elapsedTime;
    }

    if (moveRight.isPressed()) {

      // Rotate the Ball Angle Counter Clockwise.
      g_BallEntity.fAngle -= (float) AR_DegToRad(g_BallEntity.fTurnRate) * elapsedTime;
    }

    // Clamp values above 2 * PI or 360 Deg's.
    if (g_BallEntity.fAngle >= AR_2PI) g_BallEntity.fAngle = g_BallEntity.fAngle - AR_2PI;

    // Clamp values below 0.
    if (g_BallEntity.fAngle < 0.0f) g_BallEntity.fAngle = AR_2PI + g_BallEntity.fAngle;

    if (debug.isPressed()) {
      g_bDisplayNodes = !g_bDisplayNodes;
    }

    if (moveUp.isPressed()) {
      if (g_BallEntity.fVelX + (g_BallEntity.fAccel * elapsedTime) < g_BallEntity.fMaxVel) {
        g_BallEntity.fVelX += g_BallEntity.fAccel * elapsedTime;
        g_BallEntity.fVelZ += g_BallEntity.fAccel * elapsedTime;
      }
    }
    if (moveDown.isPressed()) {

      // Move the Ball Backwards.
      if (g_BallEntity.fVelX - (g_BallEntity.fAccel * elapsedTime) > g_BallEntity.fMinVel) {
        g_BallEntity.fVelX -= g_BallEntity.fAccel * elapsedTime;
        g_BallEntity.fVelZ -= g_BallEntity.fAccel * elapsedTime;
      }
    }

    // Apply Gravity to this Entity (using time based motion) if he's not colliding with anything.
    if (!octree.isObjectColliding()) g_BallEntity.fVelY += (GRAVITY * elapsedTime);

    // Apply (spherical based) motion.

    g_BallEntity.x +=
        (g_fSinTable[(int) AR_RadToDeg(g_BallEntity.fAngle)] * g_BallEntity.fVelX) * elapsedTime;
    g_BallEntity.y += g_BallEntity.fVelY * elapsedTime;
    g_BallEntity.z +=
        (g_fCosTable[(int) AR_RadToDeg(g_BallEntity.fAngle)] * g_BallEntity.fVelZ) * elapsedTime;

    // Adjust the Forward I-Sectors Endpoint.
    g_vForwardISector[1].x =
        g_fSinTable[(int) AR_RadToDeg(g_BallEntity.fAngle)] * g_BallEntity.fRadius * 0.2f;
    g_vForwardISector[1].y = 0.0f;
    g_vForwardISector[1].z =
        g_fCosTable[(int) AR_RadToDeg(g_BallEntity.fAngle)] * g_BallEntity.fRadius * 0.2f;

    // Slow this guy down (friction).
    if (g_BallEntity.fVelX > g_fFriction * elapsedTime) {
      g_BallEntity.fVelX -= g_fFriction * elapsedTime;
    }

    if (g_BallEntity.fVelZ > g_fFriction * elapsedTime) {
      g_BallEntity.fVelZ -= g_fFriction * elapsedTime;
    }

    if (g_BallEntity.fVelX < g_fFriction * elapsedTime) {
      g_BallEntity.fVelX += g_fFriction * elapsedTime;
    }

    if (g_BallEntity.fVelZ < g_fFriction * elapsedTime) {
      g_BallEntity.fVelZ += g_fFriction * elapsedTime;
    }

    // If this Ball falls outside the world, drop back from the top.
    if (g_BallEntity.y < -30) {
      g_BallEntity.x = g_BallEntity.z = 0.0f;
      g_BallEntity.y = 5.0f;
      g_BallEntity.fVelX = g_BallEntity.fVelY = g_BallEntity.fVelZ = 0.0f;
    }

    Vector3f[] vGroundLine = {new Vector3f(), new Vector3f()};
    Vector3f[] vForwardLine = {new Vector3f(), new Vector3f()};

    // Prepare a Temporary line transformed to the Balls exact world position.
    vGroundLine[0].x = g_BallEntity.x + g_vGroundISector[0].x;
    vGroundLine[0].y = g_BallEntity.y + g_vGroundISector[0].y;
    vGroundLine[0].z = g_BallEntity.z + g_vGroundISector[0].z;

    vGroundLine[1].x = g_BallEntity.x + g_vGroundISector[1].x;
    vGroundLine[1].y = g_BallEntity.y + g_vGroundISector[1].y;
    vGroundLine[1].z = g_BallEntity.z + g_vGroundISector[1].z;

    // Prepare a Temporary line transformed to the Balls exact world position.
    vForwardLine[0].x = g_BallEntity.x + g_vForwardISector[0].x;
    vForwardLine[0].y = g_BallEntity.y + g_vForwardISector[0].y;
    vForwardLine[0].z = g_BallEntity.z + g_vForwardISector[0].z;

    vForwardLine[1].x = g_BallEntity.x + g_vForwardISector[1].x;
    vForwardLine[1].y = g_BallEntity.y + g_vForwardISector[1].y;
    vForwardLine[1].z = g_BallEntity.z + g_vForwardISector[1].z;

    // A temporary Vector holding the Intersection Point of our Intersection Check.
    vIntersectionPt = new Vector3f();

    // Reset the Status of the Object (wheter it is colliding or not).
    octree.setObjectColliding(false);

    // Reset the Nodes collided to zero so we can start with a fresh count.
    Octree.numNodesCollided = 0;

    // Test the line for an intersection with the Octree Geometry.
    if (octree.intersectLineWithOctree(octree, g_World, vGroundLine, vIntersectionPt)) {
      // Move the Ball up from the point at which it collided with the ground. This is what
      // ground clamping is!
      g_BallEntity.x = vIntersectionPt.x;
      // NOTE: Make sure it is above the surface, AND half it's height (so it isn't half
      // underground).
      // This would only apply if you placed entity's by their exact center.
      g_BallEntity.y = vIntersectionPt.y + g_BallEntity.fRadius;
      g_BallEntity.z = vIntersectionPt.z;

      // Stop your up-down velocity.
      g_BallEntity.fVelY = 0.0f;
    }

    // Test the line for an intersection with the Octree Geometry.
    if (octree.intersectLineWithOctree(octree, g_World, vForwardLine, vIntersectionPt)) {
      // Move the Ball up from the point at which it collided with the ground. This is what
      // ground clamping is!
      g_BallEntity.x = vIntersectionPt.x;
      // NOTE: Make sure it is above the surface, AND half it's height (so it isn't half
      // underground).
      // This would only apply if you placed entity's by their exact center.
      g_BallEntity.y = vIntersectionPt.y + g_BallEntity.fRadius;
      g_BallEntity.z = vIntersectionPt.z;

      // Stop your up-down velocity.
      g_BallEntity.fVelY = 0.0f;
    }
  }