Package com.pointcliki.dizgruntled

Examples of com.pointcliki.dizgruntled.LogicFactory


    } catch (JSONException e) {
      System.err.println("Problem placing logic");
      System.err.println(e.getMessage());
    }
    // Create a logic factory to handle the creation of in-game logics
    LogicFactory factory = new LogicFactory();
    scene(EditorScene.class).map().placeLogic(factory.createFromJSON(j));
  }
View Full Code Here


     
      // Store the logics
      ArrayList<Logic> logics = new ArrayList<Logic>();
     
      // Create a logic factory to handle the creation of in-game logics
      LogicFactory factory = new LogicFactory();
     
      int l = s.length;
      // Skip to the start of the logics
      n += 7;
      // If we have a scrolling background we need to skip some more
      if (MonolithResource.readInteger(s, n) == 1313818964) n += 5;
           
      // Read logics
      try {
        while (n + 284 < l) {
          // Data of the logic
          int dataOffset = n;
          // String lengths
          int nameLength = MonolithResource.readInteger(s, n + 4);
          int logicLength = MonolithResource.readInteger(s, n + 8);
          int graphicLength = MonolithResource.readInteger(s, n + 12);
          int aniLength = MonolithResource.readInteger(s, n + 16);
         
          if (logicLength == 0) break;
         
          // Skip to name / image / animation of the logic
          n += 284;
         
          // Get the logic, graphic file and animation/sound file if there is one
          n += nameLength;
          String logicRef = new String(Arrays.copyOfRange(s, n, n + logicLength));
          n += logicLength;
          String graphicRef = new String(Arrays.copyOfRange(s, n, n + graphicLength)).replace('_', '/');
          n += graphicLength;
          String aniRef = new String(Arrays.copyOfRange(s, n, n + aniLength)).replace('_', '/');
          n += aniLength;
         
          if (!logicRef.matches("[A-Za-z]+")) break;
         
          // Map to correct world if a level reference
          if (graphicRef.startsWith("LEVEL")) graphicRef = "AREA" + fWorld + "/IMAGEZ" + graphicRef.substring(5);
          else if (graphicRef.length() > 0) graphicRef = "GAME/IMAGEZ" + graphicRef.substring(4);
         
          if (aniRef.startsWith("LEVEL")) aniRef = "AREA" + fWorld + "/ANIZ" + aniRef.substring(5);
          else if (aniRef.length() > 0) aniRef = "GAME/ANIZ" + aniRef.substring(4);
         
          // For some reason, ambient files are sometimes incorrectly called "AREAXLOOP" rather than "AMBIENTXLOOP"
          if (GruntzGame.resourceManager().rez().file(aniRef, "ani") == null) aniRef = aniRef.replace("AREA", "AMBIENT");
         
          // Check that the string exists
          Logic log = factory.createFromWWD(logicRef, graphicRef, aniRef, Arrays.copyOfRange(s, dataOffset, dataOffset + 284));
          if (log != null) logics.add(log);
          else if (!logicRef.equals("GiantRock")) System.err.println("Failed to find controller for logic " + logicRef);
        }
      } catch (Exception e) {
        // Finish parsing errors if an exception occurs
View Full Code Here

   
    JSONArray tilesets = map.optJSONArray("tilesets");
    fTilesets = new TileSet[tilesets.length()];
    for (int i = 0; i < tilesets.length(); i++) fTilesets[i] =  GruntzGame.resourceManager().tileset(tilesets.optString(i));
   
    LogicFactory f = new LogicFactory();
    fLogics = new EntityQuery<Logic>();
    if (valid) {
      JSONArray logics = map.optJSONArray("logics");
      for (int i = 0; i < logics.length(); i++) fLogics.add(f.createFromJSON(logics.optJSONObject(i)));
    }
       
    fTiles = new byte[tilesets.length()][area];
    if (valid) {
      for (int j = 0; j < fTilesets.length; j++) {
View Full Code Here

  public void dropGrunt(GridCoordinate xy) {
    if (fGruntMoulds > 0) {
      fGruntMoulds--;
      // Spawn grunt
      try {
        LogicFactory f = new LogicFactory();
        JSONObject obj = new JSONObject();
        obj.put("logic", "Grunt");
        obj.put("xy", xy.x() * 32 + " " + xy.y() * 32);
        obj.put("tool", "NORMAL");
        obj.put("toy", "NONE");
        // TODO: Fix to be correct for player
        obj.put("color", "ORANGE");
        obj.put("ai", "NO AI");
        obj.put("player", 0);
        Grunt g = (Grunt) f.createFromJSON(obj);
        levelScene().mapManager().map().placeLogic(g);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
View Full Code Here

TOP

Related Classes of com.pointcliki.dizgruntled.LogicFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.