Esempio n. 1
0
 public void render(Graphics g, Point offset, Point render) {
   if (loaded) {
     g.drawImage(levelImage, offset.x - (render.x * 32), offset.y - (render.y * 32), null);
     for (LItemDrop item : items) {
       item.render(g, offset, render);
     }
     for (LMob mob : mobs) {
       mob.render(g, offset, render);
     }
   } else {
     Log.warn("level is not loaded! broken?");
   }
 }
Esempio n. 2
0
 @SuppressWarnings("unchecked")
 public void save() {
   JSONObject entities = new JSONObject();
   JSONArray mobs = new JSONArray();
   for (LMob mob : this.mobs) {
     if (mob.getID() != 0) {
       JSONObject obj = new JSONObject();
       obj.put("id", mob.getID());
       obj.put("x", mob.getPosition().getX());
       obj.put("y", mob.getPosition().getY());
       obj.put("dir", mob.getDir());
       obj.put("roam", mob.canRoam());
       obj.put("loot", mob.getLootInJSON());
       mobs.add(obj);
     } else {
       // TODO do correct player save
     }
   }
   entities.put("mobs", mobs);
   JSONArray items = new JSONArray();
   for (LItemDrop item : this.items) {
     JSONObject obj = new JSONObject();
     obj.put("id", item.getId());
     obj.put("x", item.getCords().getX());
     obj.put("y", item.getCords().getY());
     obj.put("q", item.getQuantity());
     items.add(obj);
   }
   entities.put("items", items);
   try {
     FileWriter file = new FileWriter(entitiesFile);
     file.write(entities.toJSONString());
     file.flush();
     file.close();
   } catch (IOException e) {
     Log.severe("Failed to save file");
     Log.stackTrace(e);
   }
 }
Esempio n. 3
0
 public LMob getPlayer() {
   for (LMob mob : mobs) {
     if (mob.getID() == 0) return mob;
   }
   return null;
 }